-
Notifications
You must be signed in to change notification settings - Fork 7.7k
/
xx_net.sh
executable file
·96 lines (81 loc) · 1.93 KB
/
xx_net.sh
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
#!/bin/bash
#
# xx_net init script
#
### BEGIN INIT INFO
# Provides: xx_net
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Monitor for xx_net activity
### END INIT INFO
# **NOTE** bash will exit immediately if any command exits with non-zero.
set -e
PACKAGE_NAME=xx_net
PACKAGE_DESC="XX-Net proxy server"
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
if [ -L $0 ];then
PACKAGE_PATH="$(dirname $(readlink -n $0))/"
else
PACKAGE_PATH=`dirname $0`
fi
cd $PACKAGE_PATH
PACKAGE_PATH="`pwd `/"
PACKAGE_START="${PACKAGE_PATH}start"
start() {
echo -n "Starting ${PACKAGE_DESC}: "
nohup ${PACKAGE_START} >/dev/null 2>&1 &
echo "${PACKAGE_NAME}."
}
stop() {
echo -n "Stopping ${PACKAGE_DESC}: "
kill -9 `ps aux | grep "${PACKAGE_START}" | grep -v grep | awk '{print $2}'` || true
kill -9 `ps aux | grep "launcher/start.py" | grep -v grep | awk '{print $2}'` || true
echo "${PACKAGE_NAME}."
}
status() {
pid="PID`ps aux | grep "${PACKAGE_START}" | grep -v grep | awk '{print $2}'`"
if [[ "$pid" == "PID" ]];then
echo "xx-net stopped"
else
echo "xx-net running,pid: ${pid##"PID"}"
fi
}
restart() {
stop
sleep 1
start
}
usage() {
N=$(basename "$0")
echo "Usage: [sudo] $N {start|stop|restart|status}" >&2
exit 1
}
if [ "$(id -u)" != "0" ]; then
echo "please use sudo to run ${PACKAGE_NAME}"
exit 0
fi
case "$1" in
# If no arg is given, start the goagent.
# If arg `start` is given, also start goagent.
'' | start)
start
;;
stop)
stop
;;
#reload)
restart | force-reload)
restart
;;
status)
status
;;
*)
usage
;;
esac
exit 0