#!/usr/bin/python
import subprocess
import datetime
res = subprocess.Popen("ps -ef |egrep -v grep | grep deployer",stdout=subprocess.PIPE,shell=True)
tomcats=res.stdout.readlines()
counts=len(tomcats)
if counts>1:
dt=datetime.datetime.now()
fp=open(‘/root/deployer.txt’,'a’)
fp.write(‘deployer stop at %s\n’ % dt.strftime(‘%Y-%m-%d %H:%M:%S’))
fp.close()
#!/usr/bin/python
import subprocess
import datetime
import os
shell = ['adapter']
for i in shell:
com="ps -ef |egrep -v grep| grep %s" % i
print(com)
res = subprocess.Popen(com,stdout=subprocess.PIPE,shell=True)
print(res)
tomcats=res.stdout.readlines()
#print(tomcats)
counts=len(tomcats)
print(counts)
if counts<1:
dt=datetime.datetime.now()
fp=open('/data/shell/deployer.txt','a')
fp.write('test stop at %s\n' % dt.strftime('%Y-%m-%d %H:%M:%S'))
fp.close()
#subprocess.Popen("/bin/bash /opt/canal/adapter/bin/stop.sh",shell=True)
#subprocess.Popen("/bin/bash /opt/canal/adapter/bin/startup.sh",shell=True)
os.system("/bin/bash /opt/canal/deployer/bin/stop.sh")
os.system("/bin/bash /opt/canal/deployer/bin/startup.sh")
os.system("/bin/bash /opt/canal/adapter/bin/stop.sh")
os.system("/bin/bash /opt/canal/adapter/bin/startup.sh")
#subprocess.Popen("rm -rf /opt/canal/adapter/bin/adapter.pid && /bin/bash /opt/canal/adapter/bin/startup.sh",shell=True)
#soft = ['adapter', 'deployer']
#bash =['stop.sh', 'startup.sh']
#for i in bash:
# for j in soft:
# commond="/bin/bash /opt/canal/{}/bin/{} ".format(j, i)
# print(commond)
# re1 = subprocess.Popen(commond,shell=True)
# print(re1)
#!/usr/bin/python
import subprocess
import datetime
import os
shell = ['deployer']
for i in shell:
com="ps -ef |egrep -v grep| grep %s" % i
print(com)
res = subprocess.Popen(com,stdout=subprocess.PIPE,shell=True)
print(res)
tomcats=res.stdout.readlines()
#print(tomcats)
counts=len(tomcats)
print(counts)
if counts<1:
dt=datetime.datetime.now()
fp=open('/data/shell/deployer.txt','a')
fp.write('test stop at %s\n' % dt.strftime('%Y-%m-%d %H:%M:%S'))
fp.close()
#subprocess.Popen("/bin/bash /opt/canal/adapter/bin/stop.sh",shell=True)
#subprocess.Popen("/bin/bash /opt/canal/adapter/bin/startup.sh",shell=True)
os.system("/bin/bash /opt/canal/deployer/bin/stop.sh")
os.system("/bin/bash /opt/canal/deployer/bin/startup.sh")
os.system("/bin/bash /opt/canal/adapter/bin/stop.sh")
os.system("/bin/bash /opt/canal/adapter/bin/startup.sh")
#subprocess.Popen("rm -rf /opt/canal/adapter/bin/adapter.pid && /bin/bash /opt/canal/adapter/bin/startup.sh",shell=True)
#soft = ['adapter', 'deployer']
#bash =['stop.sh', 'startup.sh']
#for i in bash:
# for j in soft:
# commond="/bin/bash /opt/canal/{}/bin/{} ".format(j, i)
# print(commond)
# re1 = subprocess.Popen(commond,shell=True)
# print(re1)
*/1 * * * * /usr/bin/python3 /data/shell/canal_monitor_a.py >null 2>&1
python编写自动启动tomcat脚本
最新推荐文章于 2023-02-10 15:48:49 发布