update init script
This commit is contained in:
parent
fd0311a55f
commit
fcb7386735
|
|
@ -1,34 +1,49 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Start/stop shadowsocks.
|
|
||||||
#
|
|
||||||
#====================================================================
|
|
||||||
# Run level information:
|
|
||||||
# chkconfig: 2345 99 99
|
|
||||||
# Description: lightweight secured socks5 proxy
|
|
||||||
# processname: shadowsocks-server
|
|
||||||
# Run "/sbin/chkconfig --add shadowsocks" to add the Run levels.
|
|
||||||
#====================================================================
|
|
||||||
|
|
||||||
# Note: this script requires sudo in order to run shadowsocks as the specified
|
### BEGIN INIT INFO
|
||||||
# user.
|
# chkconfig: 2345 90 10
|
||||||
|
# Provides: Shadowsocks-go
|
||||||
|
# Required-Start: $network $syslog
|
||||||
|
# Required-Stop: $network
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Fast tunnel proxy that helps you bypass firewalls
|
||||||
|
# Description: A secure socks5 proxy, designed to protect your Internet traffic.
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
# Author: Teddysun <i@teddysun.com>
|
||||||
|
|
||||||
# Source function library
|
# Source function library
|
||||||
. /etc/rc.d/init.d/functions
|
. /etc/rc.d/init.d/functions
|
||||||
|
|
||||||
# Check that networking is up.
|
# Check that networking is up.
|
||||||
[ ${NETWORKING} ="yes" ] || exit 0
|
[ "${NETWORKING}" == "yes" ] || exit 0
|
||||||
|
|
||||||
|
NAME=Shadowsocks-go
|
||||||
BIN=/usr/bin/shadowsocks-server
|
BIN=/usr/bin/shadowsocks-server
|
||||||
CONFIG_FILE=/etc/shadowsocks/config.json
|
CONF=/etc/shadowsocks/config.json
|
||||||
PID_DIR=/var/run
|
PID_DIR=/var/run
|
||||||
PID_FILE=$PID_DIR/shadowsocks.pid
|
PID_FILE=$PID_DIR/shadowsocks-go.pid
|
||||||
RET_VAL=0
|
RET_VAL=0
|
||||||
|
|
||||||
[ -x $BIN ] || exit 0
|
[ -x $BIN ] || exit 0
|
||||||
|
|
||||||
|
if [[ ! -d $PID_DIR ]]; then
|
||||||
|
mkdir -p $PID_DIR
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Creating PID directory $PID_DIR failed"
|
||||||
|
RET_VAL=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f $CONF ]; then
|
||||||
|
echo "$NAME config file $CONF not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
check_running() {
|
check_running() {
|
||||||
if [[ -r $PID_FILE ]]; then
|
if [[ -r $PID_FILE ]]; then
|
||||||
read PID <$PID_FILE
|
read PID < $PID_FILE
|
||||||
if [[ -d "/proc/$PID" ]]; then
|
if [[ -d "/proc/$PID" ]]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
|
@ -44,51 +59,40 @@ do_status() {
|
||||||
check_running
|
check_running
|
||||||
case $? in
|
case $? in
|
||||||
0)
|
0)
|
||||||
echo "shadowsocks-go running with PID $PID"
|
echo "$NAME is running with PID $PID"
|
||||||
;;
|
;;
|
||||||
1)
|
1|2)
|
||||||
echo "shadowsocks-go not running, remove PID file $PID_FILE"
|
echo "$NAME is not running"
|
||||||
;;
|
RET_VAL=1
|
||||||
2)
|
|
||||||
echo "Could not find PID file $PID_FILE, shadowsocks-go does not appear to be running"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_start() {
|
do_start() {
|
||||||
if [[ ! -d $PID_DIR ]]; then
|
|
||||||
mkdir $PID_DIR || echo "failed creating PID directory $PID_DIR"; exit 1
|
|
||||||
fi
|
|
||||||
if check_running; then
|
if check_running; then
|
||||||
echo "shadowsocks-go already running with PID $PID"
|
echo "$NAME is already running with PID $PID"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
if [[ ! -r $CONFIG_FILE ]]; then
|
$BIN -c $CONF 2>&1 > /dev/null &
|
||||||
echo "config file $CONFIG_FILE not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
echo "starting shadowsocks-go"
|
|
||||||
# sudo will set the group to the primary group of $USER
|
|
||||||
$BIN -c $CONFIG_FILE > /dev/null &
|
|
||||||
PID=$!
|
PID=$!
|
||||||
echo $PID > $PID_FILE
|
echo $PID > $PID_FILE
|
||||||
sleep 0.3
|
sleep 0.3
|
||||||
if ! check_running; then
|
if check_running; then
|
||||||
echo "start failed"
|
echo "$NAME start success"
|
||||||
return 1
|
else
|
||||||
|
echo "$NAME start failed"
|
||||||
|
RET_VAL=1
|
||||||
fi
|
fi
|
||||||
echo "shadowsocks-go running with PID $PID"
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_stop() {
|
do_stop() {
|
||||||
if check_running; then
|
if check_running; then
|
||||||
echo "stopping shadowsocks-go with PID $PID"
|
kill -9 $PID
|
||||||
kill $PID
|
|
||||||
rm -f $PID_FILE
|
rm -f $PID_FILE
|
||||||
|
echo "$NAME stop success"
|
||||||
else
|
else
|
||||||
echo "Could not find PID file $PID_FILE"
|
echo "$NAME is not running"
|
||||||
|
RET_VAL=1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +106,7 @@ case "$1" in
|
||||||
do_$1
|
do_$1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: shadowsocks {start|stop|restart|status}"
|
echo "Usage: $0 { start | stop | restart | status }"
|
||||||
RET_VAL=1
|
RET_VAL=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user