Skip to content

Instantly share code, notes, and snippets.

@charlestang
Created July 22, 2013 15:57
Show Gist options
  • Save charlestang/6055008 to your computer and use it in GitHub Desktop.
Save charlestang/6055008 to your computer and use it in GitHub Desktop.
这个脚本是服务器上shadowsocks的服务器的守护进程,脚本放在config.json相同的目录中,然后配置一个每分钟运行的crontab,该脚本会保证自己只有一个实例在运行,脚本的功能是每秒扫瞄一次,看ssserver进程是否还在运行中,如果找不到ssserver,就重新启动一个ssserver。
#!/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
@shinux
Copy link

shinux commented Feb 14, 2016

这样不好吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment