Skip to content

Commit 071d637

Browse files
committed
minor improvement
1 parent 4d6b0b2 commit 071d637

File tree

3 files changed

+118
-6
lines changed

3 files changed

+118
-6
lines changed

CPScripts/watchdog.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/bash
2+
3+
show_help() {
4+
echo -e "\nrun command: \e[31mnohup bash /etc/cyberpanel/watchdog.sh SERVICE_NAME >/dev/null 2>&1 &\e[39m"
5+
echo -e "\nreplace \e[31mSERVICE_NAME\e[39m to the service name, acceptable word: \e[31mmariadb\e[39m or \e[31mlsws\e[39m"
6+
echo -e "\nWatchdog will check service status every 60 seconds and tries to restart if it is not running and also send an email to designated address"
7+
echo -e "\nto exit watchdog , run command \e[31mbash /etc/cyberpanel/watchdog.sh kill\e[39m"
8+
echo -e "\n\nplease also create \e[31m/etc/cyberpanel/watchdog.flag\e[39m file with following format:"
9+
echo -e "TO=address@email.com"
10+
echo -e "SENDER=sender name"
11+
echo -e "FROM=sender@email.com"
12+
echo -e "You may proceed without flag file , but that will make email sending failed."
13+
}
14+
15+
watchdog_check() {
16+
echo -e "\nChecking LiteSpeed ..."
17+
pid=$(ps aux | grep "watchdog lsws" | grep -v grep | awk '{print $2}')
18+
if [[ "$pid" == "" ]] ; then
19+
echo -e "\nWatchDog for LSWS is gone , restarting..."
20+
nohup watchdog lsws > /dev/null 2>&1 &
21+
echo -e "\nWatchDog for LSWS has been started..."
22+
else
23+
echo -e "\nWatchDog for LSWS is running...\n"
24+
echo $(ps aux | grep "watchdog lsws" | grep -v grep)
25+
fi
26+
echo -e "\nChecking MariaDB ..."
27+
pid=$(ps aux | grep "watchdog mariadb" | grep -v grep | awk '{print $2}')
28+
if [[ "$pid" == "" ]] ; then
29+
echo -e "\nWatchDog for MariaDB is gone , restarting..."
30+
nohup watchdog mariadb > /dev/null 2>&1 &
31+
echo -e "\nWatchDog for MariaDB has been started..."
32+
else
33+
echo -e "\nWatchDog for MariaDB is running...\n"
34+
echo $(ps aux | grep "watchdog mariadb" | grep -v grep)
35+
fi
36+
}
37+
38+
if [[ $1 == "mariadb" ]] || [[ $1 == "database" ]] || [[ $1 == "mysql" ]] ; then
39+
NAME="mariadb"
40+
echo "Watchdog on MariaDB is started up ..."
41+
elif [[ $1 == "web" ]] || [[ $1 == "lsws" ]] || [[ $1 == "litespeed" ]] || [[ $1 == "openlitespeed" ]] ; then
42+
NAME="lsws"
43+
echo "Watchdog on LiteSpeed is started up ..."
44+
elif [[ $1 == "help" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $1 == "" ]] ; then
45+
show_help
46+
exit
47+
elif [[ $1 == "check" ]] || [[ $1 == "status" ]] ; then
48+
watchdog_check
49+
exit
50+
elif [[ $1 == "kill" ]] ; then
51+
pid=$(ps aux | grep "watchdog lsws" | grep -v grep | awk '{print $2}')
52+
if [[ "$pid" != "" ]] ; then
53+
kill -15 $pid
54+
fi
55+
pid=$(ps aux | grep "watchdog mariadb" | grep -v grep | awk '{print $2}')
56+
if [[ "$pid" != "" ]] ; then
57+
kill -15 $pid
58+
fi
59+
echo "watchdo has been killed..."
60+
exit
61+
else
62+
show_help
63+
64+
echo -e "\n\n\nunknown service name..."
65+
exit
66+
fi
67+
68+
69+
70+
while [ true = true ]
71+
do
72+
systemctl status $NAME 2>&1>/dev/null
73+
if [[ $? == "0" ]] ; then
74+
if [[ $NAME == "mariadb" ]] ; then
75+
pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}')
76+
echo "-1000" > /proc/$pid/oom_score_adj
77+
fi
78+
echo "$NAME service is running..."
79+
else
80+
echo "$NAME is down , try to restart it..."
81+
if [[ $NAME == "lsws" ]] ; then
82+
pkill lsphp
83+
fi
84+
if [[ $NAME == "mariadb" ]] ; then
85+
pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}')
86+
echo "-1000" > /proc/$pid/oom_score_adj
87+
fi
88+
systemctl stop $NAME
89+
systemctl start $NAME
90+
if [ -f /etc/cyberpanel/watchdog.flag ] ; then
91+
flag="/etc/cyberpanel/watchdog.flag"
92+
LINE3=$(awk 'NR==3' $flag)
93+
LINE2=$(awk 'NR==2' $flag)
94+
LINE1=$(awk 'NR==1' $flag)
95+
96+
FROM=${LINE3#*=}
97+
SENDER=${LINE2#*=}
98+
TO=${LINE1#*=}
99+
sendmail -F $SENDER -f $FROM -i $TO <<MAIL_END
100+
Subject: $NAME is down...
101+
To: $TO
102+
$NAME is down , watchdog attempted to restarting it...
103+
104+
MAIL_END
105+
fi
106+
fi
107+
sleep 60
108+
done

cyberpanel.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fi
7373

7474
watchdog_setup() {
7575
if [[ $WATCHDOG == "ON" ]] ; then
76-
wget -O /etc/cyberpanel/watchdog.sh https://$DOWNLOAD_SERVER/misc/watchdog.sh
76+
wget -O /etc/cyberpanel/watchdog.sh https://$GIT_CONTENT_URL/$BRANCH_NAME/CPScripts/watchdog.sh
7777
chmod 700 /etc/cyberpanel/watchdog.sh
7878
ln -s /etc/cyberpanel/watchdog.sh /usr/local/bin/watchdog
7979
pid=$(ps aux | grep "watchdog lsws" | grep -v grep | awk '{print $2}')
@@ -383,7 +383,7 @@ if [[ -d /etc/yum.repos.d ]] ; then
383383
if [[ $CENTOS_8 == "True" ]] ; then
384384
dnf install zip -y
385385
elif [[ $CENTOS_8 == "False" ]] ; then
386-
curl https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.0.1/install/CyberPanel.repo > /etc/yum.repos.d/CyberPanel.repo
386+
curl https://$GIT_CONTENT_URL/v2.0.1/install/CyberPanel.repo > /etc/yum.repos.d/CyberPanel.repo
387387
fi
388388
fi
389389

@@ -485,7 +485,7 @@ if [[ $SERVER_OS == "Ubuntu" ]] ; then
485485
DEBIAN_FRONTEND=noninteractive apt install -y lsphp72-memcached
486486
DEBIAN_FRONTEND=noninteractive apt install -y lsphp71-memcached
487487
DEBIAN_FRONTEND=noninteractive apt install -y lsphp70-memcached
488-
488+
489489
if [[ $TOTAL_RAM -eq "2048" ]] || [[ $TOTAL_RAM -gt "2048" ]] ; then
490490
DEBIAN_FRONTEND=noninteractive apt install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev git -y
491491
wget https://$DOWNLOAD/litespeed/lsmcd.tar.gz
@@ -656,21 +656,25 @@ check_process() {
656656
if systemctl is-active --quiet httpd; then
657657
systemctl disable httpd
658658
systemctl stop httpd
659+
systemctl mask httpd
659660
echo -e "\nhttpd process detected, disabling...\n"
660661
fi
661662
if systemctl is-active --quiet apache2; then
662663
systemctl disable apache2
663664
systemctl stop apache2
665+
systemctl mask apache2
664666
echo -e "\napache2 process detected, disabling...\n"
665667
fi
666668
if systemctl is-active --quiet named; then
667669
systemctl stop named
668670
systemctl disable named
671+
systemctl mask named
669672
echo -e "\nnamed process detected, disabling...\n"
670673
fi
671674
if systemctl is-active --quiet exim; then
672675
systemctl stop exim
673676
systemctl disable exim
677+
systemctl mask exim
674678
echo -e "\nexim process detected, disabling...\n"
675679
fi
676680
}
@@ -1423,11 +1427,11 @@ fi
14231427
echo -e "\033[0;32mTCP: 21\033[39m and \033[0;32mTCP: 40110-40210\033[39m for FTP"
14241428
echo -e "\033[0;32mTCP: 25\033[39m, \033[0;32mTCP: 587\033[39m, \033[0;32mTCP: 465\033[39m, \033[0;32mTCP: 110\033[39m, \033[0;32mTCP: 143\033[39m and \033[0;32mTCP: 993\033[39m for mail service"
14251429
echo -e "\033[0;32mTCP: 53\033[39m and \033[0;32mUDP: 53\033[39m for DNS service"
1426-
1430+
14271431
if ! timeout 3 telnet mx.zoho.com 25 | grep "Escape" > /dev/null 2>&1 ; then
14281432
echo -e "Your provider seems \e[31mblocked\033[39m port 25 , E-mail sending may \e[31mnot\033[39m work properly."
14291433
fi
1430-
1434+
14311435
if [[ $SERVER_COUNTRY = CN ]] ; then
14321436
if [[ $PROVIDER == "Tencent Cloud" ]] ; then
14331437
if [[ $SERVER_OS == "Ubuntu" ]] ; then

cyberpanel_utility.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ read TMP_YN
4747
if [[ $TMP_YN == "1" ]] ; then
4848
if [[ ! -f /etc/cyberpanel/watchdog.sh ]] ; then
4949
echo -e "\nWatchDog no found..."
50-
wget -O /etc/cyberpanel/watchdog.sh https://cyberpanel.sh/misc/watchdog.sh
50+
wget -O /etc/cyberpanel/watchdog.sh https://$GIT_CONTENT_URL/$BRANCH_NAME/CPScripts/watchdog.sh
5151
chmod 700 /etc/cyberpanel/watchdog.sh
5252
ln -s /etc/cyberpanel/watchdog.sh /usr/local/bin/watchdog
5353
echo -e "\nWatchDos has been installed..."

0 commit comments

Comments
 (0)