首页 技术 正文
技术 2022年11月9日
0 收藏 319 点赞 2,854 浏览 1199 个字

Shell实现判断进程是否存在并重新启动脚本 – superbfly的专栏 – CSDN博客 https://blog.csdn.net/superbfly/article/details/52513765

#! /bin/bash
# author caoxin
# time 2012-10-10
# program : 判断进行是否存在,并重新启动

function check(){
count=`ps -ef |grep $1 |grep -v “grep” |wc -l`
#echo $count
if [ 0 == $count ];then
nohup python /runscript/working/$1 &
fi
}

check behaviors.py

#!/bin/bash
#

#调用关闭jboss进程脚本
stopMethodServer.sh

#打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v “grep” 去掉grep进程
jmsThread=`ps -ef | grep gdms | grep jboss | grep -v “grep”`
echo $jmsThread

#查询jboss进程个数:wc -l 返回行数
count=`ps -ef | grep gdms | grep jboss | grep -v “grep” | wc -l`
echo $count

sec=7
#开始一个循环,以判断进程是否关闭

for var in 1 2
do
if [ $count -gt 0 ]; then
#若进程还未关闭,则脚本sleep几秒
echo sleep $sec second the $var time, the JMS thread is still alive
sleep $sec
else
#若进程已经关闭,则跳出循环
echo “break”
break
fi
done

#if [ $count -eq 0 ]; then
# echo “nohup startMethodServer.sh &”
# nohup startMethodServer.sh &
#else
# echo “It’s better to check the thread!!!”
#fi

#调用启动脚本
nohup startMethodServer.sh &

#!/bin/bash
while [ 1 ]
do
#打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v “grep” 去掉grep进程
jmsThread=`ps -ef | grep testServer | grep -v “grep”`
# echo $jmsThread
#查询jboss进程个数:wc -l 返回行数
count=`ps -ef | grep testServer | grep -v “grep” | wc -l`
# echo $count
if [ $count -eq 0 ]; then
s=”cd /root/testServer/bin;nohup python testServer.py start”
eval $s
# echo “bad!”
# else
# echo “ok”
fi
done

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291