-
Notifications
You must be signed in to change notification settings - Fork 24
/
DDNS
executable file
·117 lines (103 loc) · 2.23 KB
/
DDNS
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
#!/bin/bash
# chkconfig:2345 60 30
# description: DDNS
# 以上为开机自启配置
# 配置工作目录
cd /root/NameSilo-DDNS
check=`ls|grep 'ddns.py\|conf.json'`
if [ -z "$check" ]
then
echo $"The working directory is incorrect, please check the configuration on the 13 line of $0"
exit -1
fi
# 设置python3路径
pythonBin=python3
service_name=DDNS
key_word=ddns.py
function findps()
{
if [ "$1" = "print" ]
then
ps -ef|grep $key_word|grep -vE "(grep|$0|service.*$key_word|systemctl)"
else
fps=`ps -ef|grep $key_word|grep -vE "(grep|$0|service.*$key_word|systemctl)"`
fi
}
function startps()
{
if [ ! -d "log" ]
then
mkdir log
fi
nohup $pythonBin ddns.py >> log/DDNS.log 2>&1 &
}
function killps()
{
ps -ef|grep $key_word|grep -vE '(grep|$0|service.*$key_word|systemctl)'| cut -c 7-16|xargs kill -9
}
case "$1" in
start)
findps;
if [ -z "$fps" ]
then
startps;
echo -e "\033[32;1mStarted successfully\033[0m"
else
echo -e "\033[31;1m$service_name service is already running! \033[0m"
exit 1
fi
;;
################################
stop)
findps;
if [ -z "$fps" ]
then
echo -e "\033[31;1m$service_name service is not running! \033[0m"
exit 1
else
killps;
fi
echo -e "\033[32;1mStopped successfully\033[0m"
;;
#################################
restart|force-reload)
findps;
if [ -n "$fps" ]
then
killps;
fi
echo -e "\033[32;1mStopped successfully\033[0m"
sleep 0.5
startps;
echo -e "\033[32;1mStarted successfully\033[0m"
;;
########################################
status)
findps;
if [ -z "$fps" ]
then
echo -e "\033[31;1m$service_name service is stopped\033[0m"
else
echo -e "\033[32;1m$service_name service is running\033[0m"
findps print
echo "================="
echo "Update history:"
grep -B 0 'update_dns_api:.*update.*completed.*' log/DDNS.log
echo "================="
echo "Latest operation:"
tail -2 log/DDNS.log
fi
;;
########################################
testEmail)
$pythonBin ddns.py --test-email
;;
########################################
archiveLog)
$pythonBin ddns.py --archive
;;
########################################
*)
echo $"Usage: $0 {start|stop|status|restart|force-reload|testEmail|archiveLog}"
esac
exit 0