51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
#!/bin/python3
|
|
'''
|
|
Created on Mar 30, 2014
|
|
author: tpweis
|
|
file name: k2_stop.py
|
|
'''
|
|
import os
|
|
import time
|
|
import subprocess
|
|
import sys
|
|
sys.path.insert(0,'/sl/lib')
|
|
|
|
from sleds_utilities import *
|
|
|
|
# This function returns SUCESS or FAILURE. It K2Daemon is not running, that counts
|
|
# as success also. IE, running this twice does not generate an failure return.
|
|
|
|
def main():
|
|
"function main"
|
|
|
|
slsetvars()
|
|
process_name = "K2Daemon"
|
|
|
|
cmd = "pkill"
|
|
p1 = subprocess.Popen([cmd, "-f", process_name], stdout=subprocess.PIPE)
|
|
# the kill might take a while. Try for up to N seconds, then fail.
|
|
rc = "FAILURE"
|
|
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 still alive. If still in range, try again
|
|
continue
|
|
# Not found. Good result
|
|
rc = "SUCCESS"
|
|
break
|
|
|
|
print(rc)
|
|
slscatlog('D',"k2_stop: " + cmd)
|
|
|
|
exit()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# execute only if run as a script
|
|
main()
|
|
|