Stop a service.

Do nothing if the service is null or not in a state in which it can be/needs to be stopped.

The service state is checked <i>before</i> the operation begins.
This process is <i>not</i> thread safe.
@param service a service or null
427587
public static void stop(Service service) {
    if (service != null) {
      Service.STATE state = service.getServiceState();
      if (state == Service.STATE.STARTED) {
        service.stop();
      }
    }
  }
912388
public void stop() throws IOException, InterruptedException {
    for (int i = services.size() - 1; i >= 0; i--) {
      Service service = services.get(i);
      logger.info("Stopping Minicluster Service: "
          + service.getClass().getName());
      service.stop();
    }
    logger.info("All Minicluster Services stopped.");
  }
902805
def stop(self):
        
        try:
            sh.systemctl.stop(self.name)
        except sh.ErrorReturnCode_5:
            self.logger.debug('Service not running.')
1220805
@Override
    public synchronized void stop() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(tc, "Stopping the basic FFDC service");
        }
        logSummary(true);
    }
622402
def stopService(self):
        
        self._service.factory.stopTrying()
        yield self._service.factory.stopFactory()
        yield service.MultiService.stopService(self)
380064
public final void stop() {
        if (this.thread != null) {
            try {
                if (this.thread != null) {
                    this.thread.interrupt();
                    synchronized (this.thread) {
                        this.thread.notifyAll();
                    }
                }
            } finally {
                this.thread = null;
            }
        }
    }
911317
def StopService(service_name, service_binary_name=None):
  
  # QueryServiceStatus returns: scvType, svcState, svcControls, err,
  # svcErr, svcCP, svcWH
  try:
    status = win32serviceutil.QueryServiceStatus(service_name)[1]
  except pywintypes.error as e:
    if getattr(e, "winerror", None) == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
      logging.debug("Tried to stop '%s', but the service is not installed.",
                    service_name)
    else:
      logging.exception("Unable to query status of service '%s':", service_name)
    return

  for _ in range(20):
    if status == win32service.SERVICE_STOPPED:
      break
    elif status != win32service.SERVICE_STOP_PENDING:
      try:
        win32serviceutil.StopService(service_name)
      except pywintypes.error:
        logging.exception("Unable to stop service '%s':", service_name)
    time.sleep(1)
    status = win32serviceutil.QueryServiceStatus(service_name)[1]

  if status == win32service.SERVICE_STOPPED:
    logging.info("Service '%s' stopped.", service_name)
    return
  elif not service_binary_name:
    return

  # Taskkill will fail on systems predating Windows XP, this is a best
  # effort fallback solution.
  output = subprocess.check_output(
      ["taskkill", "/im", "%s*" % service_binary_name, "/f"],
      shell=True,
      stdin=subprocess.PIPE,
      stderr=subprocess.PIPE)

  logging.debug("%s", output)

  # Sleep a bit to ensure that process really quits.
  time.sleep(2)
1313996
public synchronized void shutdown() {
        if (mState == STATE_STOPPED) {
            return;
        }
        if (mState == STATE_NOT_STARTED) {
            mState = STATE_STOPPED;
            return;
        }
        mState = STATE_SHOULD_STOP;
        // Inject stop task into the queue so it knows to stop, in case we're blocked.
        mQueue.offer(STOP_TASK);
    }
69994
def stop_service
      DRb.remove_server(self)
      if  Thread.current['DRb'] && Thread.current['DRb']['server'] == self
        Thread.current['DRb']['stop_service'] = true
      else
        @thread.kill
      end
    end
846721
public static void stop(ServiceController<?> controller) {
        try {
            transition(controller, State.DOWN);
        } catch (StartException e) {
            // This can't happen
            throw new IllegalStateException(e);
        }
    }
221847
def start(self, service):
        
        try:
            map(self.start_class, service.depends)
            if service.is_running():
                return
            if service in self.failed:
                log.warning("%s previously failed to start", service)
                return
            service.start()
        except Exception:
            log.exception("Unable to start service %s", service)
            self.failed.add(service)
472235
def shutdown(self, service_thread_map):
    """"""
    with self._services.lifecycle_lock:
      for service, service_thread in service_thread_map.items():
        self._logger.info('terminating pantsd service: {}'.format(service))
        service.terminate()
        service_thread.join(self.JOIN_TIMEOUT_SECONDS)
      self._logger.info('terminating pantsd')
      self._kill_switch.set()
269246
public static void stop(String args[]) {
        log.debug("windowsStop called");
        boot.stop();

        synchronized (SERVICE) {
            // notify the thread synchronized on SERVER in start()
            SERVICE.notify();
        }
    }
833477
@Override
    public void stop() {
        if (!HAConfiguration.isHAEnabled(configuration)) {
            LOG.info("HA is not enabled, no need to stop leader election service");
            return;
        }
        try {
            leaderLatch.close();
            curatorFactory.close();
        } catch (IOException e) {
            LOG.error("Error closing leader latch", e);
        }
    }
737582
@Override
    public void stop(){
        if(isStarted){
            synchronized (this) {
                if (isStarted) {
                    if (getLookupService() instanceof Closable) {
                        ((Closable) getLookupService()).stop();
                    }
                    isStarted = false;
                }
            }
        }
    }
947894
function stopService() {
  return server.stop(this, function(err) {
    if (err) {
      return out.error("service did not respond well: %j", err);
    }
    return out.success("service stopped");
  });
}
1072992
@Override
    public void stop() {
        if(isStarted.compareAndSet(true,false)){
            ScheduledExecutorService healthCheck = healthCheckService.getAndSet(newHealthCheckService());
            healthCheck.shutdown();
            LOGGER.info("the SD API RegistryHealth Check Task has stopped.");
            ScheduledExecutorService heartbeat = heartbeatService.getAndSet(newHeartbeatService());
            heartbeat.shutdown();
            LOGGER.info("the SD API Heartbeat Task has stopped.");
        }
    }