49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
#!/bin/python3
|
|
'''
|
|
Created on Mar 30, 2014
|
|
author: tpweis
|
|
file name: tomcat_status.py
|
|
'''
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
sys.path.insert(0,'/sl/lib')
|
|
|
|
from sleds_utilities import *
|
|
|
|
def main():
|
|
"function main"
|
|
|
|
slsetvars()
|
|
# now fetch the contents of the tomcat.pid file, and check it against the ps data.
|
|
pid_name = slrunget() + "tomcat.pid"
|
|
|
|
try:
|
|
pidfile = open(pid_name, 'r')
|
|
# file is open. Check the tomcat.pid value
|
|
pid = pidfile.read()
|
|
pid = pid.rstrip('\n')
|
|
pidfile.close()
|
|
|
|
# Now fetch the process status string for the pid we fetched
|
|
|
|
process_string="tomcat"
|
|
p1 = subprocess.Popen(["ps", "-q", pid, "-f"], stdout=subprocess.PIPE)
|
|
data = p1.communicate()[0]
|
|
data=data.decode()
|
|
|
|
if process_string in data:
|
|
print("ON")
|
|
else:
|
|
slscatlog('E',"Bad value in tomcat.pid: " + pid)
|
|
print("OFF")
|
|
except OSError:
|
|
print("OFF")
|
|
|
|
return
|
|
|
|
if __name__ == '__main__':
|
|
# execute only if run as a script
|
|
main()
|
|
|