linux 进程重启脚本,Linux进程拉起和重启脚本

服务器宕机等场景下拉起或者定期重启进程等,可用本文的脚本处理。

其中start.sh为拉起脚本,restart.sh为重启脚本。

1.[代码]start.ini

process_name=jboss

bin_path=/ICA20/jboss-4.3.1.GA-9000/bin

2.[代码]start.sh

#!/bin/bash

date

. /etc/profile

. ~/.bash_profile

path=$(cd `dirname $0`; pwd)

source $path/start.ini

#check whether the process is exist

is_alive=0

echo "Check process [$process_name]..."

cmd=`ps -ef | grep java | grep -c $process_name`

if test $cmd -ge 1; then

echo "Process [$process_name] exist..."

is_alive=1

else

echo "Process [$process_name] not exist..."

is_alive=0

fi

if [[ "$is_alive" -eq 0 ]];then

echo "Start [$process_name]..."

echo "cd $bin_path..."

cd $bin_path

nohup sh run.sh &

fi

echo "Check finished."

3.[代码]restart.ini

process_name=TTSserver

bin_path=/ICA20/ttsClient

4.[代码]restart.sh

#!/bin/bash

date

. /etc/profile

. ~/.bash_profile

path=$(cd `dirname $0`; pwd)

source $path/restart.ini

#check whether the process is exist

is_alive=0

echo "Check process [$process_name]..."

cmd=`ps -ef | grep 20 | grep -c $process_name`

if test $cmd -ge 1; then

echo "Process [$process_name] exist..."

is_alive=1

else

echo "Process [$process_name] not exist..."

is_alive=0

fi

if [[ "$is_alive" -eq 1 ]];then

echo "Kill [$process_name]..."

kill -9 $(ps -ef|grep $process_name|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')

sleep 60s

fi

echo "cd $bin_path..."

echo "Start [$process_name]..."

cd $bin_path

nohup ./$process_name -n 20 &

echo "Check finished."

5.[图片] QQ截图20150924180846.png

24181058_oapW.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值