Fix start script

This commit is contained in:
Teddysun 2015-01-08 13:49:15 +08:00
parent 4e1c8cab01
commit b4f7aec281

View File

@ -1,26 +1,28 @@
#!/bin/bash #!/bin/bash
# Start/stop shadowsocks. # Start/stop shadowsocks.
# #
### BEGIN INIT INFO #====================================================================
# Provides: shadowsocks # Run level information:
# Required-Start: # chkconfig: 2345 99 99
# Required-Stop: # Description: lightweight secured scoks5 proxy
# Should-Start: # processname: shadowsocks-server
# Should-Stop: # Run "/sbin/chkconfig --add shadowsocks" to add the Run levels.
# Default-Start: 2 3 4 5 #====================================================================
# Default-Stop: 0 1 6
# Short-Description: shadowsocks is a lightweight tunneling proxy
# Description: Modified from Linode's nginx fastcgi startup script
### END INIT INFO
# Note: this script requires sudo in order to run shadowsocks as the specified # Note: this script requires sudo in order to run shadowsocks as the specified
# user. # user.
# Source function library
. /etc/rc.d/init.d/functions
# Check that networking is up.
[ ${NETWORKING} ="yes" ] || exit 0
BIN=/usr/bin/shadowsocks-server BIN=/usr/bin/shadowsocks-server
CONFIG_FILE=/etc/shadowsocks/config.json CONFIG_FILE=/etc/shadowsocks/config.json
#LOG_FILE=/var/log/shadowsocks #LOG_FILE=/var/log/shadowsocks
USER=nobody #USER=nobody
GROUP=nobody #GROUP=nobody
PID_DIR=/var/run PID_DIR=/var/run
PID_FILE=$PID_DIR/shadowsocks.pid PID_FILE=$PID_DIR/shadowsocks.pid
RET_VAL=0 RET_VAL=0
@ -60,8 +62,6 @@ do_status() {
do_start() { do_start() {
if [[ ! -d $PID_DIR ]]; then if [[ ! -d $PID_DIR ]]; then
mkdir $PID_DIR || echo "failed creating PID directory $PID_DIR"; exit 1 mkdir $PID_DIR || echo "failed creating PID directory $PID_DIR"; exit 1
chown $USER:$GROUP $PID_DIR || echo "failed creating PID directory $PID_DIR"; exit 1
chmod 0770 $PID_DIR
fi fi
if check_running; then if check_running; then
echo "shadowsocks-go already running with PID $PID" echo "shadowsocks-go already running with PID $PID"
@ -73,7 +73,7 @@ do_start() {
fi fi
echo "starting shadowsocks-go" echo "starting shadowsocks-go"
# sudo will set the group to the primary group of $USER # sudo will set the group to the primary group of $USER
sudo -u $USER $BIN -c $CONFIG_FILE & $BIN -c $CONFIG_FILE &
PID=$! PID=$!
echo $PID > $PID_FILE echo $PID > $PID_FILE
sleep 0.3 sleep 0.3