Sleds/buildvm/scat/mongo_stop.py

46 lines
1.0 KiB
Python

#!/bin/python3
'''
Created on Mar 30, 2014
author: tpweis
file name: mongo_stop.py
'''
import os
import subprocess
import sys
sys.path.insert(0,'/sl/lib')
from sleds_utilities import *
def main():
"function main"
slsetvars()
process_name = "mongod"
p1 = subprocess.Popen(["sudo", "systemctl", "stop", process_name], stdout=subprocess.PIPE)
# the kill might take a while. Try for up to N seconds, then fail.
rc = "FAIL to stop mongod"
for n in range(20):
time.sleep(1)
p2 = subprocess.Popen(["ps", "-C", process_name], stdout=subprocess.PIPE)
data=p2.communicate()[0]
data=data.decode()
data=data.rstrip()
slscatlog('D',"mongo_stop returned: " + data)
if process_name in data:
# The process is still alive. If still in range, try again
continue
# Not found. Good result
rc = "mongod stopped"
break
print(rc)
exit ()
if __name__ == '__main__':
# execute only if run as a script
main()