Sleds/buildvm/scat/mongo_start.py

43 lines
907 B
Python

#!/bin/python3
'''
Created on Mar 30, 2014
author: tpweis
file name: mongo_start.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", "start", process_name], stdout=subprocess.PIPE)
# the start might take a while. Try for up to N seconds, then fail.
rc = "FAIL to start mongod"
for n in range(5):
time.sleep(1)
p2 = subprocess.Popen(["ps", "-C", process_name], stdout=subprocess.PIPE)
data=p2.communicate()[0]
data=data.decode()
data=data.rstrip()
if process_name in data:
# The process is alive.
rc = "mongod started"
break
print(rc)
exit()
if __name__ == '__main__':
# execute only if run as a script
main()