-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |