Rev 2815 | Rev 2864 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log
Rev | Author | Line No. | Line |
---|---|---|---|
2601 | tom.houday | 1 | #!/bin/bash |
825 | franck | 2 | # $Id: alcasar-daemon.sh 2840 2020-06-27 22:35:40Z rexy $ |
807 | franck | 3 | |
824 | franck | 4 | # alcasar-daemon.sh |
1474 | richard | 5 | # by Franck BOUIJOUX & Rexy |
807 | franck | 6 | # This script is distributed under the Gnu General Public License (GPL) |
7 | # Watchdog of Services |
||
8 | # See /etc/cron.d/alcasar-daemon-watchdog for config the time |
||
9 | |||
824 | franck | 10 | conf_file="/usr/local/etc/alcasar.conf" |
2474 | tom.houday | 11 | SSH=`grep ^SSH= $conf_file|cut -d"=" -f2` # sshd active (on/off) |
824 | franck | 12 | SSH=${SSH:=off} |
2620 | rexy | 13 | SMS=`grep ^SMS= $conf_file|cut -d"=" -f2` # SMS active (on/off) |
14 | SMS=${SMS:=off} |
||
2572 | rexy | 15 | LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2` # ldap active (on/off) |
2574 | rexy | 16 | LDAP=${LDAP:=off} |
2583 | rexy | 17 | INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2` # INTIF name |
18 | EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2` # EXTIF name |
||
2840 | rexy | 19 | SERVICES="mysqld lighttpd php-fpm ntpd unbound unbound-blacklist unbound-whitelist dnsmasq-whitelist unbound-blackhole radiusd nfcapd e2guardian clamav-daemon clamav-freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd" |
1596 | richard | 20 | nb_available_srv=`echo $SERVICES|wc -w` |
807 | franck | 21 | |
824 | franck | 22 | function ServiceTest () { |
2601 | tom.houday | 23 | service=$1 |
24 | if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then |
||
25 | logger -t alcasar-daemon -i "$service is inactive. Activation attempt" |
||
26 | echo "the $service service is disabled! trying to start it..." |
||
27 | /usr/bin/systemctl start $service.service |
||
1596 | richard | 28 | else |
29 | nb_srv=$((nb_srv+1)) |
||
30 | fi |
||
824 | franck | 31 | } |
807 | franck | 32 | |
2583 | rexy | 33 | for NIC in $EXTIF $INTIF |
34 | do |
||
35 | if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ] |
||
36 | then |
||
37 | echo "The network interface card '$NIC' is down! Try to enable it" |
||
38 | /usr/sbin/ifup $NIC |
||
39 | fi |
||
40 | done |
||
41 | |||
1596 | richard | 42 | nb_srv=0 |
2601 | tom.houday | 43 | for service in $SERVICES; do |
44 | if [ $service == 'sshd' ]; then |
||
45 | if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then |
||
2520 | rexy | 46 | nb_available_srv=$((nb_available_srv-1)) |
2601 | tom.houday | 47 | continue |
1596 | richard | 48 | fi |
2601 | tom.houday | 49 | elif [ $service == 'gammu-smsd' ]; then |
2620 | rexy | 50 | if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then |
2601 | tom.houday | 51 | nb_available_srv=$((nb_available_srv-1)) |
52 | continue |
||
53 | fi |
||
807 | franck | 54 | fi |
2601 | tom.houday | 55 | ServiceTest $service |
807 | franck | 56 | done |
2537 | tom.houday | 57 | |
1596 | richard | 58 | if [ $nb_available_srv -ne $nb_srv ] |
2520 | rexy | 59 | then |
60 | echo "Restart this script to know if all is ok" |
||
1596 | richard | 61 | else |
2520 | rexy | 62 | echo "$nb_srv services needed by ALCASAR are started." |
1596 | richard | 63 | fi |
2520 | rexy | 64 | |
2815 | rexy | 65 | if [ `lsmod|grep ^ipt_NETFLOW|wc -l` == 0 ] |
2520 | rexy | 66 | then |
2537 | tom.houday | 67 | logger -t alcasar-daemon -i "ipt_netflow is inactive." |
2520 | rexy | 68 | echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)" |
69 | else |
||
70 | echo "The Log system is active" |
||
71 | fi |
||
2572 | rexy | 72 | if [ ! -e /etc/raddb/mods-enabled/ldap ] |
73 | then |
||
74 | if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ] |
||
75 | then |
||
76 | echo "Enable LDAP..." |
||
77 | /usr/local/bin/alcasar-ldap.sh -on |
||
78 | fi |
||
79 | fi |
||
2583 | rexy | 80 |