进程守护脚本
- 新建脚本
touch server_agent.ssh
- 编辑脚本
vim server_agent.ssh
#!/bin/bash
echo "start server"
while true
do
# 获取 8080 端口的进程号
pid=$(lsof -i:8079|awk '{print $2}')
echo ${pid}
# 如果进程号为空,重启服务
if [ "${pid}" == "" ]
then
echo "restart..."
cd /root/go/src/github.com/service/
setsid ./service
pid=$(lsof -i:8079|awk '{print $2}')
echo ${pid}
fi
sleep 5
done
- 添加可执行权限
chmod 777 server_agent.ssh
- 启动脚本
nohup ./server_agent.ssh &
网友评论