forked from huihuijordan/teddysunss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadowsocks-libev
98 lines (83 loc) · 1.95 KB
/
shadowsocks-libev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# chkconfig: 2345 90 10
# description: A secure socks5 proxy, designed to protect your Internet traffic.
### BEGIN INIT INFO
# Provides: Shadowsocks-libev
# 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: Start or stop the Shadowsocks-libev server
### END INIT INFO
# Author: Teddysun <i@teddysun.com>
# Source function library
. /etc/rc.d/init.d/functions
# Check that networking is up.
[ ${NETWORKING} ="yes" ] || exit 0
if [ -f /usr/local/bin/ss-server ]; then
DAEMON=/usr/local/bin/ss-server
elif [ -f /usr/bin/ss-server ]; then
DAEMON=/usr/bin/ss-server
fi
NAME=Shadowsocks-libev
CONF=/etc/shadowsocks-libev/config.json
PID_DIR=/var/run
PID_FILE=$PID_DIR/shadowsocks-libev.pid
RET_VAL=0
[ -x $DAEMON ] || exit 0
if [ ! -d $PID_DIR ]; then
mkdir -p $PID_DIR
if [ $? -ne 0 ]; then
echo "Creating PID directory $PID_DIR failed"
exit 1
fi
fi
if [ ! -f $CONF ]; then
echo "$NAME config file $CONF not found"
exit 1
fi
do_start() {
if [ -f $PID_FILE ]; then
read PID < $PID_FILE
echo "$NAME (pid $PID) is already running..."
exit 0
else
echo -n $"Starting ${NAME}: "
daemon $DAEMON -u -c $CONF -f $PID_FILE
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && success
echo
}
do_stop() {
echo -n $"Stopping ${NAME}: "
killproc -p $PID_FILE
RETVAL=$?
[ $RETVAL -eq 0 ]
rm -f $PID_FILE
echo
}
do_status() {
if [ -f $PID_FILE ]; then
read PID < $PID_FILE
echo "$NAME (pid $PID) is running..."
else
echo "$NAME is stopped"
RETVAL=1
fi
}
do_restart() {
do_stop
do_start
}
case "$1" in
start|stop|restart|status)
do_$1
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RET_VAL=1
;;
esac
exit $RETVAL