forked from peter123456789/SS-SSR-TG-iptables-bt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpserver_centos
115 lines (111 loc) · 3.02 KB
/
pserver_centos
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# chkconfig: 2345 90 10
# description: Peerflix Server: a self-hosted remote torrent client
### BEGIN INIT INFO
# Provides: Peerflix Server
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Peerflix Server: a self-hosted remote torrent client
# Description: Start or stop the Peerflix Server
### END INIT INFO
NAME="Peerflix Server"
NAME_BIN="peerflix-server"
FILE="/etc/node/lib/node_modules/peerflix-server"
CONF="/etc/peerflix-server/peerflix-server.conf"
LOG="/tmp/peerflix-server.log"
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
RETVAL=0
check_running(){
PID=`ps -ef |grep "${NAME_BIN}" |grep -v "grep" |grep -v "init.d" |grep -v "service" |awk '{print $2}'`
if [[ ! -z ${PID} ]]; then
return 0
else
return 1
fi
}
read_config(){
[[ ! -e ${CONF} ]] && echo -e "${Error} ${NAME} 配置文件不存在 !" && exit 1
host=`cat ${CONF}|grep "host = "|awk -F "host = " '{print $NF}'`
port=`cat ${CONF}|grep "port = "|awk -F "port = " '{print $NF}'`
user=`cat ${CONF}|grep "user = "|awk -F "user = " '{print $NF}'`
passwd=`cat ${CONF}|grep "passwd = "|awk -F "passwd = " '{print $NF}'`
}
View_User(){
ip=$(wget -qO- -t1 -T2 ipinfo.io/ip)
if [[ -z "${ip}" ]]; then
ip=$(wget -qO- -t1 -T2 api.ip.sb/ip)
if [[ -z "${ip}" ]]; then
ip=$(wget -qO- -t1 -T2 members.3322.org/dyndns/getip)
if [[ -z "${ip}" ]]; then
ip="VPS_IP"
fi
fi
fi
clear && echo "————————————————" && echo
echo -e " Peerflix Server 信息 :" && echo
echo -e " 地址\t: ${Green_font_prefix}http://${ip}:${port}${Font_color_suffix}"
echo && echo "————————————————"
}
do_start(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME (PID ${PID}) 正在运行..." && exit 0
else
read_config
echo -e "${Info} $NAME 启动中..."
ulimit -n 51200
PORT=${port} nohup node ${FILE} > "${LOG}" 2>&1 &
sleep 2s
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME 启动成功 !"
View_User
else
echo -e "${Error} $NAME 启动失败(请运行脚本查看日志错误输出) !"
fi
fi
}
do_stop(){
check_running
if [[ $? -eq 0 ]]; then
kill -9 ${PID}
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo -e "${Info} $NAME 停止成功 !"
else
echo -e "${Error} $NAME 停止失败 !"
fi
else
echo -e "${Info} $NAME 未运行"
RETVAL=1
fi
}
do_status(){
check_running
if [[ $? -eq 0 ]]; then
read_config
View_User
echo -e "${Info} $NAME (PID ${PID}) 正在运行..."
else
echo -e "${Info} $NAME 未运行 !"
RETVAL=1
fi
}
do_restart(){
do_stop
do_start
}
case "$1" in
start|stop|restart|status)
do_$1
;;
*)
echo -e "使用方法: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL