Skip to content

Commit

Permalink
update init script
Browse files Browse the repository at this point in the history
  • Loading branch information
teddysun committed Sep 16, 2016
1 parent 9693b8f commit fd0311a
Showing 1 changed file with 51 additions and 38 deletions.
89 changes: 51 additions & 38 deletions shadowsocksR-debian
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: ShadowsocksR
# Required-Start: $network $local_fs $remote_fs
Expand All @@ -11,65 +12,77 @@

# Author: Teddysun <[email protected]>

name=ShadowsocksR
NAME=ShadowsocksR
BIN=/usr/local/shadowsocks/server.py
conf=/etc/shadowsocks.json
CONF=/etc/shadowsocks.json

check_running(){
PID=`ps -ef | grep -v grep | grep -i "${BIN}" | awk '{print $2}'`
if [ ! -z $PID ]; then
return 0
else
return 1
fi
}

start(){
$BIN -c $conf -d start
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name start success"
do_start(){
check_running
if [ $? -eq 0 ]; then
echo "$NAME is already running with PID $PID"
RETVAL=1
else
echo "$name start failed"
$BIN -c $CONF -d start
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "$NAME start success"
else
echo "$NAME start failed"
RETVAL=1
fi
fi
}

stop(){
pid=`ps -ef | grep -v grep | grep -i "${BIN}" | awk '{print $2}'`
if [[ ! -z $pid ]]; then
$BIN -c $conf -d stop
do_stop(){
check_running
if [ $? -eq 0 ]; then
$BIN -c $CONF -d stop
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name stop success"
if [ $RETVAL -eq 0 ]; then
echo "$NAME stop success"
else
echo "$name stop failed"
echo "$NAME stop failed"
RETVAL=1
fi
else
echo "$name is not running"
echo "$NAME is not running"
RETVAL=1
fi
}

status(){
pid=`ps -ef | grep -v grep | grep -i "${BIN}" | awk '{print $2}'`
if [[ -z $pid ]]; then
echo "$name is not running"
RETVAL=1
else
echo "$name is running with PID $pid"
do_status(){
check_running
if [ $? -eq 0 ]; then
echo "$NAME is running with PID $PID"
RETVAL=0
else
echo "$NAME is not running"
RETVAL=1
fi
}

do_restart(){
do_stop
do_start
}

case "$1" in
'start')
start
start|stop|restart|status)
do_$1
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
start
RETVAL=$?
;;
*)
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL

exit $RETVAL

0 comments on commit fd0311a

Please sign in to comment.