linux 判断某个进程是否存在,存在则重启,不存在则启动。

++++++++++++++++++++++++++++++++++++ 

PIDS=`ps -ef|grep "app.js"|grep -v grep`

if [ "$PIDS" != "" ]; then
pm2 restart app
echo "app restart!"
else
pm2 start app.js
echo "app started"
fi

 

+++++++++++++++++++++++++++++++++++

 

 ## 下面是node环境   webhook脚本配置 

#!/bin/bash

 

export NODE_HOME=/usr/bin/node
export PATH=$NODE_HOME/bin:$PATH
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
cd /www/wwwroot/api/nodeApi/
git reset --hard origin/master
git clean -f
git pull
PIDS=`ps -ef|grep "app.js"|grep -v grep`
if [ "$PIDS" != "" ]; then
pm2 restart app
echo "app restart!"
else
pm2 start app.js
echo "app started"
fi
pm2 show 0
echo "----------------------------------------------------------------------------"
posted @ 2017-12-29 11:26  Demoworld  阅读(6852)  评论(0编辑  收藏  举报