直接编辑 ~/.bashrc,加入以下代码:

1
2
3
4
5
6
7
8
9
10
SERVICE=’nginx’

if pgrep $SERVICE > /dev/null
then
echo “$SERVICE service running, everything is fine”
else
echo “$SERVICE is not running, starting”
nginx
echo “$SERVICE started”
fi