X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=334f33f297e3017a7e764f4600f802a68ca9c18c;hb=refs%2Fheads%2Fpackaging;hp=dbfa55f5fe1da2a5dc67311be25e2c336313f075;hpb=66db0978b275eec1dbffc862e68715a1b63dd31d;p=nodemanager.git diff --git a/tools.py b/tools.py index dbfa55f..334f33f 100644 --- a/tools.py +++ b/tools.py @@ -9,6 +9,7 @@ import threading import subprocess import shutil import sys +import signal import logger @@ -309,6 +310,14 @@ def get_node_virt (): f.write(virt) return virt +### this return True or False to indicate that systemctl is present on that box +# cache result in memory as _has_systemctl +_has_systemctl=None +def has_systemctl (): + if _has_systemctl is None: + _has_systemctl = (subprocess.call([ 'systemctl', '--help' ]) == 0) + return _has_systemctl + # how to run a command in a slice # now this is a painful matter # the problem is with capsh that forces a bash command to be injected in its exec'ed command @@ -328,3 +337,12 @@ def command_in_slice (slicename, argv): logger.log("command_in_slice: WARNING: could not find a valid virt") return argv +#################### +def init_signals (): + def handler (signum, frame): + logger.log("Received signal %d - exiting"%signum) + os._exit(1) + signal.signal(signal.SIGHUP,handler) + signal.signal(signal.SIGQUIT,handler) + signal.signal(signal.SIGINT,handler) + signal.signal(signal.SIGTERM,handler)