From c33408fb1e78e162253fc0d56cef44866f6106ee Mon Sep 17 00:00:00 2001 From: Yan Li Date: Thu, 17 Aug 2023 11:14:05 +0800 Subject: [PATCH] add example for restart local sbd --- examples/restartSBD.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 examples/restartSBD.py diff --git a/examples/restartSBD.py b/examples/restartSBD.py new file mode 100755 index 0000000..d1a6462 --- /dev/null +++ b/examples/restartSBD.py @@ -0,0 +1,42 @@ +from pythonlsf import lsf +import sys + + +def restartSBD(opCode, message, hosts) : + if lsf.lsb_init("test") > 0: + print("failed to initialize") + return + req = lsf.hostCtrlReq() + req.opCode = opCode + req.message = message + if len(hosts) > 0 : + for h in hosts: + print("restarting sbatchd daemon on host <{}> ...".format(h)) + req.host = h + cc = lsf.lsb_hostcontrol(req) + if cc == 0 : + print("sbatchd daemon restarted successfully.") + elif cc == -1 : + print("ERROR: sbatchd daemon failed to restart.") + else : + print("ERROR: return {} while trying to restart sbatchd.".format(cc)) + else : + print("restarting sbatchd daemon on local host ...") + cc = lsf.lsb_hostcontrol(req) + if cc == 0 : + print("sbatchd daemon restarted successfully.") + elif cc == -1 : + print("ERROR: sbatchd daemon failed to restart.") + else : + print("ERROR: return {} while trying to restart sbatchd.".format(cc)) + + +if __name__ == "__main__": + opCode = lsf.HOST_REBOOT + message = "reboot according to python-api" + if len(sys.argv) > 1 : + hosts = sys.argv[1:] + else : + hosts = [] + restartSBD(opCode, message, hosts) +