def _attach_and_stream(container): """ Attach to a container and stream its stdout and stderr output to this process's stdout, until the container stops. If the user presses Ctrl-C or the process is killed, also stop the Docker container. Used to run the calico-node as a foreground attached service. :param container: Docker container to attach to. :return: None. """ # Register a SIGTERM handler, so we shut down the container if this # process is kill'd. def handle_sigterm(sig, frame): print "Got SIGTERM" docker_client.stop(container) sys.exit(0) signal.signal(signal.SIGTERM, handle_sigterm) output = docker_client.attach(container, stream=True) try: for raw_data in output: sys.stdout.write(raw_data) except KeyboardInterrupt: # mainline. someone press Ctrl-C. print "Stopping Calico node..." finally: # Could either be this process is being killed, or output generator # raises an exception. docker_client.stop(container)
def node_stop(force): if force or len(client.get_endpoints(hostname=hostname, orchestrator_id=ORCHESTRATOR_ID)) == 0: client.remove_host(hostname) try: docker_client.stop("calico-node") except docker.errors.APIError as err: if err.response.status_code != 404: raise print "Node stopped and all configuration removed" else: print "Current host has active endpoints so can't be stopped." + \ " Force with --force"
def node_stop(force): if force or len( client.get_endpoints(hostname=hostname, orchestrator_id=ORCHESTRATOR_ID)) == 0: client.remove_host(hostname) try: docker_client.stop("calico-node") except docker.errors.APIError as err: if err.response.status_code != 404: raise print "Node stopped and all configuration removed" else: print "Current host has active endpoints so can't be stopped." + \ " Force with --force"
def handle_sigterm(sig, frame): print "Got SIGTERM" docker_client.stop(container) sys.exit(0)