1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
# $Id: alcasar-daemon.sh 3170 2024-02-22 17:28:40Z rexy $
|
2 |
# $Id: alcasar-daemon.sh 3190 2024-04-07 22:35:03Z rexy $
|
3 |
|
3 |
|
4 |
# alcasar-daemon.sh
|
4 |
# alcasar-daemon.sh
|
5 |
# by Franck BOUIJOUX & Rexy
|
5 |
# by Franck BOUIJOUX & Rexy
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
7 |
# Watchdog of Services
|
7 |
# Watchdog of Services
|
8 |
# With the option "-after-update" checks if services or system need to be restarted after a RPM update
|
8 |
# With the option "-after-update" checks if services or system need to be restarted after a RPM update
|
9 |
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
|
9 |
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
|
10 |
|
10 |
|
11 |
conf_file="/usr/local/etc/alcasar.conf"
|
11 |
conf_file="/usr/local/etc/alcasar.conf"
|
12 |
SMS=`grep ^SMS= $conf_file|cut -d"=" -f2` # SMS active (on/off)
|
12 |
SMS=`grep ^SMS= $conf_file|cut -d"=" -f2` # SMS active (on/off)
|
13 |
SMS=${SMS:=off}
|
13 |
SMS=${SMS:=off}
|
14 |
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2` # ldap active (on/off)
|
14 |
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2` # ldap active (on/off)
|
15 |
LDAP=${LDAP:=off}
|
15 |
LDAP=${LDAP:=off}
|
16 |
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2` # INTIF name
|
16 |
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2` # INTIF name
|
17 |
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2` # EXTIF name
|
17 |
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2` # EXTIF name
|
18 |
SERVICES="mysqld lighttpd php-fpm ntpd unbound unbound-blacklist unbound-whitelist unbound-blackhole radiusd nfcapd e2guardian ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
|
18 |
SERVICES="mysqld lighttpd php-fpm ntpd unbound unbound-blacklist unbound-whitelist unbound-blackhole radiusd nfcapd e2guardian ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
|
19 |
nb_available_srv=`echo $SERVICES|wc -w`
|
19 |
nb_available_srv=`echo $SERVICES|wc -w`
|
20 |
|
20 |
|
21 |
function ServiceTest () {
|
21 |
function ServiceTest () {
|
22 |
service=$1
|
22 |
service=$1
|
23 |
if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
|
23 |
if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
|
24 |
logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
|
24 |
logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
|
25 |
echo "the $service service is disabled! trying to start it..."
|
25 |
echo "the $service service is disabled! trying to start it..."
|
26 |
if [ $service == 'gammu-smsd' ]; then
|
26 |
if [ $service == 'gammu-smsd' ]; then
|
27 |
/usr/local/bin/alcasar-sms.sh --start
|
27 |
/usr/local/bin/alcasar-sms.sh --start
|
28 |
fi
|
28 |
fi
|
29 |
if [ $service == 'sshd' ]; then
|
29 |
if [ $service == 'sshd' ]; then
|
30 |
[ -s /etc/ssh/ssh_host_rsa_key ] || rm -f /etc/ssh/ssh_host_* # sometimes sshd doesn't initialise its keys
|
30 |
[ -s /etc/ssh/ssh_host_rsa_key ] || rm -f /etc/ssh/ssh_host_* # sometimes sshd doesn't initialise its keys
|
31 |
fi
|
31 |
fi
|
32 |
/usr/bin/systemctl start $service.service
|
32 |
/usr/bin/systemctl start $service.service
|
33 |
else
|
33 |
else
|
34 |
nb_srv=$((nb_srv+1))
|
34 |
nb_srv=$((nb_srv+1))
|
35 |
fi
|
35 |
fi
|
36 |
}
|
36 |
}
|
37 |
|
37 |
|
38 |
usage="Usage: alcasar-daemon.sh {-after-update}"
|
38 |
usage="Usage: alcasar-daemon.sh {-after-update}"
|
39 |
case $1 in
|
39 |
case $1 in
|
40 |
-\? | -h* | --h*)
|
40 |
-\? | -h* | --h*)
|
41 |
echo "$usage"
|
41 |
echo "$usage"
|
42 |
exit 0
|
42 |
exit 0
|
43 |
;;
|
43 |
;;
|
44 |
-after-update)
|
44 |
-after-update)
|
45 |
# TODO : check precisely which processes should be restarted (reboot the system or restart alcasar processes)
|
45 |
# TODO : check precisely which processes should be restarted (reboot the system or restart alcasar processes)
|
46 |
# extract processes name : for i in `dnf needs-restarting|cut -d " " -f3|sort -u|tr -d ":"|rev|cut -d"/" -f1|rev`;do;echo $i;done
|
46 |
# extract processes name : for i in `dnf needs-restarting|cut -d " " -f3|sort -u|tr -d ":"|rev|cut -d"/" -f1|rev`;do;echo $i;done
|
47 |
# system_processes=`dnf needs-restarting|egrep 'dbus|python|systemd|agetty'|wc -l` # processes to be restarted after glibc update
|
47 |
# system_processes=`dnf needs-restarting|grep -E 'dbus|python|systemd|agetty'|wc -l` # processes to be restarted after glibc update
|
48 |
nb_processes=`dnf needs-restarting|wc -l`
|
48 |
nb_processes=`dnf needs-restarting|wc -l`
|
49 |
if [ $nb_processes -ne 0 ]; then
|
49 |
if [ $nb_processes -ne 0 ]; then
|
50 |
reboot
|
50 |
reboot
|
51 |
fi
|
51 |
fi
|
52 |
;;
|
52 |
;;
|
53 |
*)
|
53 |
*)
|
54 |
for NIC in $EXTIF $INTIF
|
54 |
for NIC in $EXTIF $INTIF
|
55 |
do
|
55 |
do
|
56 |
if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]; then
|
56 |
if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]; then
|
57 |
echo "The network interface card '$NIC' is down! Try to enable it"
|
57 |
echo "The network interface card '$NIC' is down! Try to enable it"
|
58 |
/usr/sbin/ifup $NIC
|
58 |
/usr/sbin/ifup $NIC
|
59 |
fi
|
59 |
fi
|
60 |
done
|
60 |
done
|
61 |
|
61 |
|
62 |
nb_srv=0
|
62 |
nb_srv=0
|
63 |
for service in $SERVICES; do
|
63 |
for service in $SERVICES; do
|
64 |
if [ $service == 'gammu-smsd' ]; then
|
64 |
if [ $service == 'gammu-smsd' ]; then
|
65 |
if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
|
65 |
if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
|
66 |
nb_available_srv=$((nb_available_srv-1))
|
66 |
nb_available_srv=$((nb_available_srv-1))
|
67 |
continue
|
67 |
continue
|
68 |
fi
|
68 |
fi
|
69 |
fi
|
69 |
fi
|
70 |
ServiceTest $service
|
70 |
ServiceTest $service
|
71 |
done
|
71 |
done
|
72 |
|
72 |
|
73 |
if [ $nb_available_srv -ne $nb_srv ]; then
|
73 |
if [ $nb_available_srv -ne $nb_srv ]; then
|
74 |
echo "Restart this script to know if all is ok"
|
74 |
echo "Restart this script to know if all is ok"
|
75 |
else
|
75 |
else
|
76 |
echo "$nb_srv services needed by ALCASAR are started."
|
76 |
echo "$nb_srv services needed by ALCASAR are started."
|
77 |
fi
|
77 |
fi
|
78 |
|
78 |
|
79 |
if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]; then
|
79 |
if [ `cat /proc/modules|grep -c ^ipt_NETFLOW` == 0 ]; then
|
80 |
logger -t alcasar-daemon -i "ipt_netflow is inactive."
|
80 |
logger -t alcasar-daemon -i "ipt_netflow is inactive."
|
81 |
echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
|
81 |
echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
|
82 |
else
|
82 |
else
|
83 |
echo "The Log system is active"
|
83 |
echo "The Log system is active"
|
84 |
fi
|
84 |
fi
|
85 |
if [ ! -e /etc/raddb/mods-enabled/ldap ]; then
|
85 |
if [ ! -e /etc/raddb/mods-enabled/ldap ]; then
|
86 |
if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]; then
|
86 |
if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]; then
|
87 |
echo "Enabling LDAP..."
|
87 |
echo "Enabling LDAP..."
|
88 |
/usr/local/bin/alcasar-ldap.sh -on
|
88 |
/usr/local/bin/alcasar-ldap.sh -on
|
89 |
fi
|
89 |
fi
|
90 |
fi
|
90 |
fi
|
91 |
;;
|
91 |
;;
|
92 |
esac
|
92 |
esac
|
93 |
|
93 |
|