shutdown instance if it fails health check can gracefully stop.
493957
@Override
    protected void deregister(ServiceInstance instance) {

        if (instance.getInstanceId().isPresent()) {
            DeregisterInstanceRequest deregisterInstanceRequest = new DeregisterInstanceRequest().withServiceId(route53AutoRegistrationConfiguration.getAwsServiceId())
                    .withInstanceId(instance.getInstanceId().get());
            getDiscoveryClient().deregisterInstance(deregisterInstanceRequest);
        }
    }
941585
public function handleShutdown()
    {
        // If we reached this step, we are in shutdown handler.
        // An exception thrown in a shutdown handler will not be propagated
        // to the exception handler. Pass that information along.
        $this->canThrowExceptions = false;

        $error = error_get_last();
        if ($error && Misc::isLevelFatal($error['type'])) {
            // If there was a fatal error,
            // it was not handled in handleError yet.
            $this->handleError(
                $error['type'],
                $error['message'],
                $error['file'],
                $error['line']
            );
        }
    }
791622
def _shutdown(self):
        """"""
        if self._channel:
            _log.info("Halting %r consumer sessions", self._channel.consumer_tags)
        self._running = False
        if self._connection and self._connection.is_open:
            self._connection.close()
        # Reset the signal handler
        for signum in (signal.SIGTERM, signal.SIGINT):
            signal.signal(signum, signal.SIG_DFL)
945821
public function shutdown()
    {
        // check if there was a fatal error caused shutdown
        if ($lastError = error_get_last()) {
            // initialize type + message
            $type = 0;
            $message = '';
            // extract the last error values
            extract($lastError);
            // query whether we've a fatal/user error
            if ($type === E_ERROR || $type === E_USER_ERROR) {
                error_log($message);
            }
        }
    }
1373389
@Override
    public void shutdown() {
        try {
            verifyMaintainability();
        } catch (VerificationFailedException ex) {
            throw new RuntimeException("Can not shutdown " + this + "!", ex);
        }

        this.shutdownInitiated = true;
        try {
            dataObservable.shutdown();
        } finally {
            try {
                deactivate();
            } catch (CouldNotPerformException | InterruptedException ex) {
                ExceptionPrinter.printHistory("Could not shutdown " + this + "!", ex, logger);
            }
        }
    }
91048
def shutdown(name, wait=False, reboot=False):
    '''
    
    '''
    if not exists(name):
        raise ContainerNotExists("The container (%s) does not exist!" % name)
    cmd = ['lxc-shutdown', '-n', name]
    if wait:
        cmd += ['-w']
    if reboot:
        cmd += ['-r']
        
    subprocess.check_call(cmd)
626219
function gracefulShutdown(){
  console.log('About to exit, closing servers.');

  servers.forEach(function(server, index){
    server.close();
  });

  process.exit();
}
257589
public void shutdown() {
		if (executor != null) {
			executor.shutdown();
			executor = null;
		}

		if (timer != null) {
			timer.cancel();
			timer = null;
		}

		instance = null;
	}
425193
def __stop(self):  # pragma: no cover
        """"""

        if not self.dispatcher_thread:
            return

        logger.info('Stopping dispatcher')
        self.running = False  # graceful shutdown
        self.dispatcher_thread.join()
        self.dispatcher_thread = None
1342549
def shutdown(self):
        
        if self.cycle is None or self.cycle.response_complete:
            event = h11.ConnectionClosed()
            self.conn.send(event)
            self.transport.close()
        else:
            self.cycle.keep_alive = False
1247729
def stop(self, wait=False):
        
        if self.instance_id is not None:
            log.info("Shutting down node `%s` (VM instance `%s`) ...",
                     self.name, self.instance_id)

            self._cloud_provider.stop_instance(self.instance_id)
            if wait:
                while self.is_alive():
                    time.sleep(1)
            # When an instance is terminated, the EC2 cloud provider will
            # basically return it as "running" state. Setting the
            # `instance_id` attribute to None will force `is_alive()`
            # method not to check with the cloud provider, and forever
            # forgetting about the instance id.
            self.instance_id = None
714040
public synchronized void stop() {
        if (isRunning()) {
            try {
                setSendingStatus(false);
            } catch (Throwable t) {
                logger.error("Problem stopping sending status during shutdown", t);
            }
            DeviceFinder.getInstance().removeIgnoredAddress(socket.get().getLocalAddress());
            socket.get().close();
            socket.set(null);
            broadcastAddress.set(null);
            updates.clear();
            setTempoMaster(null);
            setDeviceNumber((byte)0);  // Set up for self-assignment if restarted.
            deliverLifecycleAnnouncement(logger, false);
        }
    }
960919
def graceful_stop(self, signal_number=None, stack_frame=None):
        
        stop_msg = "Hard" if self.shutdown else "Graceful"
        if signal_number is None:
            self.log.info("%s stop called manually. "
                          "Shutting down.", stop_msg)
        else:
            self.log.info("%s stop called by signal #%s. Shutting down."
                          "Stack Frame: %s",
                          stop_msg, signal_number, stack_frame)
        self.shutdown = True
        self.crawler_list.stop()
        self.daemon_list.stop()
        self.thread_event.set()
        return True
1298381
public void stop()
			throws MojoExecutionException, IOException, InstanceNotFoundException {
		try {
			this.connection.invoke(this.objectName, "shutdown", null, null);
		}
		catch (ReflectionException ex) {
			throw new MojoExecutionException("Shutdown failed", ex.getCause());
		}
		catch (MBeanException ex) {
			throw new MojoExecutionException("Could not invoke shutdown operation", ex);
		}
	}
683615
protected function breakMainLoopCheck()
    {
        $time = microtime(true);

        if ($this->terminated || $this->breakMainLoop) {
            EventLoop::$instance->stop();
            return;
        }

        if ($this->shutdown) {
            EventLoop::$instance->stop();
            return;
        }

        if ($this->reload) {
            return;
        }

        if (Daemon::$config->maxmemoryusage->value > 0
            && (memory_get_usage(true) > Daemon::$config->maxmemoryusage->value)
        ) {
            $this->log('\'maxmemory\' exceed. Graceful shutdown.');

            $this->gracefulRestart();
        }

        if (Daemon::$config->maxrequests->value > 0
            && ($this->reqCounter >= Daemon::$config->maxrequests->value)
        ) {
            $this->log('\'max-requests\' exceed. Graceful shutdown.');

            $this->gracefulRestart();
        }

        if (Daemon::$config->maxidle->value
            && $this->timeLastActivity && ($time - $this->timeLastActivity > Daemon::$config->maxidle->value)
        ) {
            $this->log('\'maxworkeridle\' exceed. Graceful shutdown.');

            $this->gracefulRestart();
        }

        if ($this->update === true) {
            $this->update = false;
            $this->update();
        }
    }
679218
@SneakyThrows
	public void gracefullyShutdown(Duration timeout) {
		logger.info("Shutting down...");

		if(!shuttingDown) {
			synchronized (this) {
				shuttingDown = true;
				threadPoolExecutor.shutdown();
			}

			// stops jobs that have not yet started to be executed
			for(Job job : jobStatus()) {
				Runnable runningJob = job.runningJob();
				if(runningJob != null) {
					threadPoolExecutor.remove(runningJob);
				}
				job.status(JobStatus.DONE);
			}
			synchronized (launcherNotifier) {
				launcherNotifier.set(false);
				launcherNotifier.notify();
			}
		}

		threadPoolExecutor.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS);
	}
902805
def stop(self):
        
        try:
            sh.systemctl.stop(self.name)
        except sh.ErrorReturnCode_5:
            self.logger.debug('Service not running.')