Skip to content

Commit dac514b

Browse files
authored
Added shutdown os command calls for different OS
1 parent 9cfd271 commit dac514b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

docker/scripts/nbl/ci/dev/lib/kazoo.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def appendKazooAtomic(self, zNodePath, data):
6262
pass
6363

6464

65+
def shutdownOs():
66+
if os.name == 'nt' or os.name == 'java': # For windows and java (in the rare case of running jython)
67+
return os.system('shutdown /s /f 0')
68+
elif os.name == 'posix': # For Unix, Linux, Mac
69+
return os.system('sudo shutdown -h now')
70+
else:
71+
print('Unknown operating system') # Docs for os.name listed only the above three cases
72+
return 1
73+
74+
6575
def healthyCheck(host):
6676
try:
6777
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
@@ -82,10 +92,8 @@ def healthyCheck(host):
8292
if shutdown:
8393
print("Requested shutdown...")
8494

85-
try:
86-
subprocess.run(f"shutdown /s /f", check=True)
87-
except subprocess.CalledProcessError as e:
88-
print(f"Could not shutdown container because of: {e.stderr}")
95+
if shutdownOs() != 0:
96+
print(f"Could not shutdown container")
8997

9098
return True
9199
except (socket.error, socket.timeout):

0 commit comments

Comments
 (0)