Skip to content

Commit 9859460

Browse files
authored
Merge pull request #61 from liyancn/master
add example for restart local sbd
2 parents bb0a010 + c33408f commit 9859460

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/restartSBD.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pythonlsf import lsf
2+
import sys
3+
4+
5+
def restartSBD(opCode, message, hosts) :
6+
if lsf.lsb_init("test") > 0:
7+
print("failed to initialize")
8+
return
9+
req = lsf.hostCtrlReq()
10+
req.opCode = opCode
11+
req.message = message
12+
if len(hosts) > 0 :
13+
for h in hosts:
14+
print("restarting sbatchd daemon on host <{}> ...".format(h))
15+
req.host = h
16+
cc = lsf.lsb_hostcontrol(req)
17+
if cc == 0 :
18+
print("sbatchd daemon restarted successfully.")
19+
elif cc == -1 :
20+
print("ERROR: sbatchd daemon failed to restart.")
21+
else :
22+
print("ERROR: return {} while trying to restart sbatchd.".format(cc))
23+
else :
24+
print("restarting sbatchd daemon on local host ...")
25+
cc = lsf.lsb_hostcontrol(req)
26+
if cc == 0 :
27+
print("sbatchd daemon restarted successfully.")
28+
elif cc == -1 :
29+
print("ERROR: sbatchd daemon failed to restart.")
30+
else :
31+
print("ERROR: return {} while trying to restart sbatchd.".format(cc))
32+
33+
34+
if __name__ == "__main__":
35+
opCode = lsf.HOST_REBOOT
36+
message = "reboot according to python-api"
37+
if len(sys.argv) > 1 :
38+
hosts = sys.argv[1:]
39+
else :
40+
hosts = []
41+
restartSBD(opCode, message, hosts)
42+

0 commit comments

Comments
 (0)