-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharia2_debian
120 lines (116 loc) · 3.52 KB
/
aria2_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
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
116
117
118
119
120
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
### BEGIN INIT INFO
# Provides: aria2 is a lightweight multi-protocol & multi-source command-line download utility.
# 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: aria2 is a lightweight multi-protocol & multi-source command-line download utility.
# Description: Start or stop the Aria2
### END INIT INFO
NAME="Aria2"
NAME_BIN="aria2c"
CONFIG="/root/.aria2/aria2.conf"
LOG="/root/.aria2/aria2.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}[Info]${Font_color_suffix}"
Error="${Red_font_prefix}[Error]${Font_color_suffix}"
RETVAL=0
check_running(){
PID=`ps -ef |grep "${NAME_BIN}" |grep -v "grep" | grep -v "aria2.sh"| grep -v "init.d" |grep -v "service" |awk '{print $2}'`
if [[ ! -z ${PID} ]]; then
return 0
else
return 1
fi
}
Read_config(){
[[ ! -e ${CONFIG} ]] && echo -e "${Error} ${NAME} 配置文件不存在 !" && exit 1
Download_dir=$(cat ${CONFIG}|grep -v '#'|grep "dir=")
[[ ! -z "${Download_dir}" ]] && Download_dir=$(echo "${Download_dir}"|awk -F '=' '{print $2}')
RPC_listen_port=$(cat ${CONFIG}|grep -v '#'|grep "rpc-listen-port=")
[[ ! -z "${RPC_listen_port}" ]] && RPC_listen_port=$(echo "${RPC_listen_port}"|awk -F '=' '{print $2}')
RPC_secret=$(cat ${CONFIG}|grep -v '#'|grep "rpc-secret=")
[[ ! -z "${RPC_secret}" ]] && RPC_secret=$(echo "${RPC_secret}"|awk -F '=' '{print $2}')
}
View_Config(){
Read_config
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(External IP detection failed)"
fi
fi
fi
[[ -z "${Download_dir}" ]] && Download_dir="/usr/local/aria2/"
[[ -z "${RPC_listen_port}" ]] && RPC_listen_port="6800"
[[ -z "${RPC_secret}" ]] && RPC_secret="No token password"
clear
echo -e "\nAria2 Simple configuration information:\n
address\t: ${Green_font_prefix}${ip}${Font_color_suffix}
port\t: ${Green_font_prefix}${RPC_listen_port}${Font_color_suffix}
password\t: ${Green_font_prefix}${RPC_secret}${Font_color_suffix}
table of contents\t: ${Green_font_prefix}${Download_dir}${Font_color_suffix}\n"
}
do_start(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME (PID ${PID}) running..." && exit 0
else
echo -e "${Info} $NAME starting..."
ulimit -n 51200
nohup aria2c -c "${CONFIG}" >> "${LOG}" 2>&1 &
sleep 2s
check_running
if [[ $? -eq 0 ]]; then
View_Config
echo -e "${Info} $NAME successfully started !"
else
echo -e "${Error} $NAME failed to activate !"
fi
fi
}
do_stop(){
check_running
if [[ $? -eq 0 ]]; then
kill -9 ${PID}
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo -e "${Info} $NAME stopped successfully !"
else
echo -e "${Error} $NAME stop failed !"
fi
else
echo -e "${Info} $NAME not running"
RETVAL=1
fi
}
do_status(){
check_running
if [[ $? -eq 0 ]]; then
View_Config
echo -e "${Info} $NAME (PID $(echo ${PID})) running..."
else
echo -e "${Info} $NAME not running !"
RETVAL=1
fi
}
do_restart(){
do_stop
do_start
}
case "$1" in
start|stop|restart|status)
do_$1
;;
*)
echo "Instructions: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL