Skip to content

Commit

Permalink
update for 4in1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
teddysun committed Dec 5, 2016
1 parent 0fee300 commit dab26bb
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions shadowsocks-crond.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dab26bb

Please sign in to comment.