forked from teddysun/shadowsocks_install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadowsocksR-debian
90 lines (80 loc) · 1.79 KB
/
shadowsocksR-debian
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
#!/bin/bash
### BEGIN INIT INFO
# Provides: ShadowsocksR
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# 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 ShadowsocksR server
### END INIT INFO
# Author: Teddysun <i@teddysun.com>
NAME=ShadowsocksR
BIN=/usr/local/shadowsocks/server.py
if [ -f /etc/shadowsocks-r/config.json ]; then
CONF=/etc/shadowsocks-r/config.json
elif [ -f /etc/shadowsocks.json ]; then
CONF=/etc/shadowsocks.json
fi
RETVAL=0
check_running(){
PID=`ps -ef | grep -v grep | grep -i "${BIN}" | awk '{print $2}'`
if [ ! -z $PID ]; then
return 0
else
return 1
fi
}
do_start(){
check_running
if [ $? -eq 0 ]; then
echo "$NAME (pid $PID) is already running..."
exit 0
else
$BIN -c $CONF -d start
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "Starting $NAME success"
else
echo "Starting $NAME failed"
fi
fi
}
do_stop(){
check_running
if [ $? -eq 0 ]; then
$BIN -c $CONF -d stop
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "Stopping $NAME success"
else
echo "Stopping $NAME failed"
fi
else
echo "$NAME is stopped"
RETVAL=1
fi
}
do_status(){
check_running
if [ $? -eq 0 ]; then
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 }"
RETVAL=1
;;
esac
exit $RETVAL