进程守护脚本

2019-01-02  本文已影响14人  袁俊亮技术博客

进程守护脚本

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 &
上一篇 下一篇

猜你喜欢

热点阅读