Created
July 22, 2013 15:57
-
-
Save charlestang/6055008 to your computer and use it in GitHub Desktop.
这个脚本是服务器上shadowsocks的服务器的守护进程,脚本放在config.json相同的目录中,然后配置一个每分钟运行的crontab,该脚本会保证自己只有一个实例在运行,脚本的功能是每秒扫瞄一次,看ssserver进程是否还在运行中,如果找不到ssserver,就重新启动一个ssserver。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
base_path=$(cd `dirname $0`;pwd) | |
daemon_pid=$base_path/daemon.pid | |
if [ -e $daemon_pid ]; then | |
pid=`cat $daemon_pid` | |
exist=`ps aux | grep $pid | grep -v grep` | |
if [ ${#exist} -gt 0 ]; then | |
exit 0 | |
else | |
echo -n '' > $daemon_pid | |
fi | |
fi | |
echo -n $$ > $daemon_pid | |
while "true" | |
do | |
ps_sserver=`ps aux | grep ssserver | grep -v grep` | |
if [ ${#ps_sserver} -gt 0 ]; then | |
sleep 1 | |
else | |
cd $base_path; ssserver >> $base_path/log 2>&1 & | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这样不好吧?