Skip to content

Instantly share code, notes, and snippets.

@implicit-invocation
Created December 19, 2019 14:08
Show Gist options
  • Save implicit-invocation/44a23a7777af0bfe81fac146abf9c4b3 to your computer and use it in GitHub Desktop.
Save implicit-invocation/44a23a7777af0bfe81fac146abf9c4b3 to your computer and use it in GitHub Desktop.
#!/bin/sh
# chkconfig: 2345 90 10
# description: Start or stop the Shadowsocks R server
#
### BEGIN INIT INFO
# Provides: Shadowsocks-R
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start or stop the Shadowsocks R server
### END INIT INFO
# Author: Yvonne Lu(Min) <[email protected]>
name=shadowsocks
PY=/usr/bin/python
SS=/usr/local/shadowsocksr/server.py
start(){
/usr/local/shadowsocksr/logrun.sh
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name start success"
else
echo "$name start failed"
fi
}
stop(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${SSPY}" | awk '{print $2}'`
if [ ! -z "$pid" ]; then
/usr/local/shadowsocksr/stop.sh
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name stop success"
else
echo "$name stop failed"
fi
else
echo "$name is not running"
RETVAL=1
fi
}
status(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${SSPY}" | awk '{print $2}'`
if [ -z "$pid" ]; then
echo "$name is not running"
RETVAL=1
else
echo "$name is running with PID $pid"
RETVAL=0
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
start
RETVAL=$?
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment