-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprocess.py
33 lines (28 loc) · 974 Bytes
/
sprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import subprocess
import sys
import logging
import os
import platform
#os.chdir('/Users/indiana/python-test')
pcwd = os.getcwd()+os.sep+'mylog.txt'
oper_system = platform.system()
logging.basicConfig(filename=pcwd,format='%(asctime)s - %(levelname)s - %(message)s',datefmt='%a, %d %b %Y %H:%M:%S',level=logging.DEBUG)
logging.info('The operating system is: '+oper_system)
logging.info(pcwd)
logging.info('The directory has changed.')
arg_sum = len(sys.argv)
try:
farg = str(sys.arg[1])
except:
logging.info("Argument is missing.")
exit(1)
logging.info('Checking if process' + farg + ' is running.')
is_running = subprocess.call(['ps','-C',farg])
if is_running == 1:
logging.warning = "System '+farg+' is not running."
logging.info = "Start the +farg+' immediately."
restart_farg = subprocess.call(['sudo','ps','-ef'])
if restart_farg == 1:
logging.error("Unable to start %s please check the logs." %farg)
else:
logging.info("%s succesfully started." %farg)