From dab26bb991e4c2050f1162defe8758f122e18468 Mon Sep 17 00:00:00 2001 From: Teddysun Date: Mon, 5 Dec 2016 21:34:24 +0900 Subject: [PATCH] update for 4in1 version --- shadowsocks-crond.sh | 69 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/shadowsocks-crond.sh b/shadowsocks-crond.sh index 0ed8218..f881393 100644 --- a/shadowsocks-crond.sh +++ b/shadowsocks-crond.sh @@ -6,51 +6,50 @@ # Visit: https://shadowsocks.be/6.html # #=================================================================# -# name -name=Shadowsocks -# log path +name=(Shadowsocks Shadowsocks-Python ShadowsocksR Shadowsocks-Go Shadowsocks-libev) path=/var/log -# check log path [[ ! -d ${path} ]] && mkdir -p ${path} -# log file log=${path}/shadowsocks-crond.log -# shadowsocks-python path(centos) + shadowsocks[0]=/usr/bin/ssserver -# shadowsocks-python path(debian) shadowsocks[1]=/usr/local/bin/ssserver -# shadowsocks-go path shadowsocks[2]=/usr/bin/shadowsocks-server -# shadowsocks-libev path shadowsocks[3]=/usr/local/bin/ss-server -# shadowsocksR path shadowsocks[4]=/usr/local/shadowsocks/server.py -# default pid value -pid="" -[ ! -f /etc/init.d/shadowsocks ] && echo "`date +"%Y-%m-%d %H:%M:%S"` /etc/init.d/shadowsocks is not existed" >> ${log} && exit +shadowsocks_init[0]=/etc/init.d/shadowsocks +shadowsocks_init[1]=/etc/init.d/shadowsocks-python +shadowsocks_init[2]=/etc/init.d/shadowsocks-r +shadowsocks_init[3]=/etc/init.d/shadowsocks-go +shadowsocks_init[4]=/etc/init.d/shadowsocks-libev -# check Shadowsocks status -/etc/init.d/shadowsocks status &>/dev/null -if [ $? -eq 0 ]; then - for bin in ${shadowsocks[*]} - do - pid=`ps -ef | grep -v grep | grep -i "${bin}" | awk '{print $2}'` - if [ ! -z ${pid} ]; then - break +i=0 +for init in ${shadowsocks_init[@]}; do + pid="" + if [ -f ${init} ]; then + ${init} status &>/dev/null + if [ $? -eq 0 ]; then + for bin in ${shadowsocks[@]}; do + pid=`ps -ef | grep -v grep | grep -i "${bin}" | awk '{print $2}'` + if [ ! -z ${pid} ]; then + break + fi + done fi - done -fi -# check status & auto start -if [ -z ${pid} ]; then - echo "`date +"%Y-%m-%d %H:%M:%S"` $name is not running" >> ${log} - echo "`date +"%Y-%m-%d %H:%M:%S"` Starting $name" >> ${log} - /etc/init.d/shadowsocks start &>/dev/null - if [ $? -eq 0 ]; then - echo "`date +"%Y-%m-%d %H:%M:%S"` $name start success" >> ${log} - else - echo "`date +"%Y-%m-%d %H:%M:%S"` $name start failed" >> ${log} + if [ -z ${pid} ]; then + echo "`date +"%Y-%m-%d %H:%M:%S"` ${name[$i]} is not running" >> ${log} + echo "`date +"%Y-%m-%d %H:%M:%S"` Starting ${name[$i]}" >> ${log} + ${init} start &>/dev/null + if [ $? -eq 0 ]; then + echo "`date +"%Y-%m-%d %H:%M:%S"` ${name[$i]} start success" >> ${log} + else + echo "`date +"%Y-%m-%d %H:%M:%S"` ${name[$i]} start failed" >> ${log} + fi + else + echo "`date +"%Y-%m-%d %H:%M:%S"` ${name[$i]} is running with pid $pid" >> ${log} + fi + fi -else - echo "`date +"%Y-%m-%d %H:%M:%S"` $name is running with pid $pid" >> ${log} -fi + ((i++)) +done