1. #!/bin/bash
    2. source /etc/profile
    3. #检查是否是root用户
    4. if [ $(id -u) != "0" ]
    5. then
    6. echo "Not the root user! Try using sudo command!"
    7. exit 1
    8. fi
    9. #监控服务是是否存活,这里是通过监控端口来监控服务,这里也可以替换为其他服务
    10. netstat -anop | grep 0.0.0.0.0:27017
    11. if [ $? -ne 1 ]
    12. then
    13. exit
    14. fi
    15. echo $(date +%T%n%F)" Restart mongodb Services " >> mongodb.log
    16. #重启服务
    17. nohup mongod --dbpath /opt/mongodb/data &
    18. /opt/node-v8.16.2/bin/pm2 restart yapi