一个短小精悍的监控/守护进程
- Author: 柳大·Poechant(钟超)
- Email: zhongchao.ustc#gmail.com
- Blog:Blog.CSDN.net/Poechant
- Date: May 28th, 2012
#!/bin/bash
YOUR_TARGET = your_target
while:
do
echo "Current DIR is " $PWD
stillRunning = $(ps -ef | grep "$PWD/$YOUR_TARGET" | grep -v "grep")
if [ "$stillRunning" ]; then
echo "You target service was already started by another way"
echo "Kill it and then startup by this shell, otherwise this shell will loop out this message annoyingly"
kill -9 $pidof $PWD/$YOUR_TARGET
else
echo "Your target service was not started"
echo "Starting service …"
$PWD/$YOUR_TARGET &
echo "Your target service was exited!"
fi
sleep 10
done
-
grep -v: –invert-match. Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
-
转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant
-
本文介绍了一个使用bash编写的简易服务监控脚本。该脚本能够周期性地检查指定服务是否正在运行,若未运行则自动启动服务,并在服务退出后重启。通过此脚本可以轻松实现对目标服务的持续监控。

3313

被折叠的 条评论
为什么被折叠?



