#!/bin/bashsource /etc/profile#检查是否是root用户if [ $(id -u) != "0" ]thenecho "Not the root user! Try using sudo command!"exit 1fi#监控服务是是否存活,这里是通过监控端口来监控服务,这里也可以替换为其他服务netstat -anop | grep 0.0.0.0.0:27017if [ $? -ne 1 ]thenexitfiecho $(date +%T%n%F)" Restart mongodb Services " >> mongodb.log#重启服务nohup mongod --dbpath /opt/mongodb/data &/opt/node-v8.16.2/bin/pm2 restart yapi
