Commit 5b550e0b authored by Valentin Reis's avatar Valentin Reis

Small work session with Swann:

- added correct SIGINT/process ending handling to cmd
- fixed  kill/list containers
- added ZMQ_LINGER 0 to the socket options.
parent 81ac4947
Pipeline #4603 passed with stages
in 54 seconds
......@@ -7,9 +7,12 @@ import signal
import os
import nrm.messaging
import uuid
import sys
import collections
RPC_MSG = nrm.messaging.MSGTYPES['up_rpc_req']
logger = logging.getLogger('nrm')
KillArgs = collections.namedtuple("Kill", ["uuid"])
class CommandLineInterface(object):
......@@ -19,8 +22,14 @@ class CommandLineInterface(object):
def __init__(self):
pass
def do_signal(self, signum, stackframe):
logger.info("received signal %d, exiting", signum)
def do_signal(self, uuid, signum, stackframe):
if uuid:
logger.info("received signal %d, killing the application..",
signum)
self.do_kill(KillArgs(uuid))
logger.info("killed the application.", signum)
else:
logger.info("received signal %d, exiting", signum)
exit(1)
def setup(self):
......@@ -30,7 +39,9 @@ class CommandLineInterface(object):
self.client = nrm.messaging.UpstreamRPCClient(upstream_client_param)
# take care of signals
signal.signal(signal.SIGINT, self.do_signal)
def handler(signum, frame):
self.do_signal(None, signum, frame)
signal.signal(signal.SIGINT, handler)
self.client.wait_connected()
......@@ -81,6 +92,11 @@ class CommandLineInterface(object):
msg = self.client.recvmsg()
assert msg.api == 'up_rpc_rep'
assert msg.type == 'process_start'
def handler(signum, frame):
self.do_signal(msg.container_uuid, signum, frame)
signal.signal(signal.SIGINT, handler)
state = 'started'
while(True):
msg = self.client.recvmsg()
......@@ -104,6 +120,7 @@ class CommandLineInterface(object):
if outeof and erreof and state == 'exiting':
state = 'exit'
logger.info("command ended: %r", exitmsg)
sys.exit(int(exitmsg.status))
break
def do_list(self, argv):
......
......@@ -162,12 +162,13 @@ class ContainerManager(object):
if uuid in self.containers:
c = self.containers[uuid]
logger.debug("killing %r:", c)
try:
c.process.proc.terminate()
except OSError:
pass
for p in c.processes.values():
try:
p.terminate()
except OSError:
logging.error("OS error: could not terminate process.")
def list(self):
"""List the containers in the system."""
return [{'uuid': c.uuid, 'pid': c.process.pid} for c in
self.containers.values()]
return [{'uuid': c.uuid, 'pid': c.processes.keys()}
for c in self.containers.values()]
......@@ -171,6 +171,7 @@ class UpstreamPubServer(object):
self.address = address
self.zmq_context = zmq.Context()
self.socket = self.zmq_context.socket(zmq.PUB)
self.socket.setsockopt(zmq.LINGER, 0)
self.socket.bind(address)
def sendmsg(self, msg):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment