Skip to content

Commit

Permalink
Add debian startup script.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Jan 21, 2013
1 parent 8ef8ed6 commit 794472b
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions sample-config/shadowsocks
@@ -0,0 +1,84 @@
#!/bin/bash
# Start/stop shadowsocks.
#
### BEGIN INIT INFO
# Provides: shadowsocks
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# 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
# user.

BIN=/usr/local/bin/shadowsocks
CONFIG_FILE=/etc/shadowsocks/config.json
LOG_FILE=/var/log/shadowsocks
USER=nobody
GROUP=nobody
PID_DIR=/var/run/
PID_FILE=$PID_DIR/shadowsocks.pid
RET_VAL=0

case "$1" in
start)
if [[ ! -d $PID_DIR ]]
then
mkdir $PID_DIR
chown $USER:$GROUP $PID_DIR
chmod 0770 $PID_DIR
fi
if [[ -r $PID_FILE ]]
then
echo "shadowsocks already running with PID `cat $PID_FILE`"
RET_VAL=1
else
# sudo will set the group to the primary group of $USER
sudo -u $USER $BIN -c $CONFIG_FILE >$LOG_FILE &
echo $! > $PID_FILE
RET_VAL=$?
fi
;;
stop)
if [[ -r $PID_FILE ]]
then
kill `cat $PID_FILE`
rm $PID_FILE
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE"
RET_VAL=1
fi
;;
restart)
if [[ -r $PID_FILE ]]
then
kill `cat $PID_FILE`
rm $PID_FILE
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE"
fi
start
RET_VAL=$?
;;
status)
if [[ -r $PID_FILE ]]
then
echo "shadowsocks running with PID `cat $PID_FILE`"
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE, shadowsocks does not appear to be running"
fi
;;
*)
echo "Usage: shadowsocks {start|stop|restart|status}"
RET_VAL=1
;;
esac
exit $RET_VAL

0 comments on commit 794472b

Please sign in to comment.