Linux 进程守护脚本

一、进程守护脚本:

while true;
do
        server=`ps aux | grep stat-agent-1.0.0-SNAPSHOT.jar | grep -v grep`
        if [ ! "$server" ]; then
           systemctl start statagent.service
        fi
        sleep 20
done

二、开机启动进程守护:

1.创建文件
cd /etc/init.d
vim daemon-stat-agent

2.文件内容
#!/bin/sh
#chkconfig: 2345 10 20
#description: daemon-stat-agent

cd /usr/local/stathub
nohup ./daemon-stat-agent.sh &

3.设置执行权限
chmod +x daemon-stat-agent

4.添加开机启动任务
chkconfig --add daemon-stat-agent

5.查看开机启动任务
chkconfig --list

 

posted @ 2021-02-06 10:30  0611163  阅读(612)  评论(0编辑  收藏  举报