diff --git a/conf.sh b/conf.sh index 9543654..a5b78a2 100644 --- a/conf.sh +++ b/conf.sh @@ -1,7 +1,10 @@ mrepo=https://git.ictmaatwerk.com/VPS-scripts/Monit mbranch=main -mkdir /var/run/monit +mkdir /var/run/monit +chmod 0755 /var/run/monit +chown www-data:root /var/run/monit +echo "D /var/run/monit 0755 www-data root -" > /usr/lib/tmpfiles.d/monitSock.conf if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then monitconf=/etc/monit/monitrc @@ -23,20 +26,20 @@ elif [ "$shortdist" = "el8" ]; then monitPhpPid=/var/opt/remi/php"${phpver//.}"/run/php-fpm/php-fpm.pid monitPhpPro=php-fpm - semanage fcontext -at httpd_sys_rw_content_t "/var/run/monit/.*)?" + semanage fcontext -at httpd_sys_rw_content_t "/var/run/monit/(.*)?" restorecon -R -v "/var/run/monit" fi systemctl stop monit +if [ ! -d "/var/lib/monit" ] ; then mkdir -p /var/lib/monit; fi +mkdir -p /etc/monit/conf.d + curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/monitrc -o $monitconf curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/monitwebsocket -o /etc/monit/websocket touch /opt/MonitNotify.sh chmod +x /opt/MonitNotify.sh -if [ ! -d "/var/lib/monit" ] ; then mkdir -p /var/lib/monit; fi -mkdir -p /etc/monit/conf.d - SysServiceList=$(systemctl list-units --full -all) diff --git a/conf/monit/monitrc b/conf/monit/monitrc index 17d2347..566efd5 100644 --- a/conf/monit/monitrc +++ b/conf/monit/monitrc @@ -2,6 +2,7 @@ ## Monit control file ## ######################## set daemon 30 # check services at 2-minute intervals + with start delay 60 set log /var/log/monit.log set idfile /var/lib/monit/id diff --git a/conf/monit/nginx.conf b/conf/monit/nginx.conf index 5e69400..0df00d1 100644 --- a/conf/monit/nginx.conf +++ b/conf/monit/nginx.conf @@ -2,5 +2,5 @@ check process nginx with pidfile /var/run/nginx.pid start program = "/bin/systemctl start nginx" stop program = "/bin/systemctl stop nginx" if not exist for 1 cycles then restart - if not exist for 3 cycles then exec "/opt/MonitNotify.sh 'SRV-WARN: Nginx" + if not exist for 3 cycles then exec "/opt/MonitNotify.sh 'SRV-WARN: Nginx'" else if recovered then exec "/opt/MonitNotify.sh 'SRV-OK: Nginx'" diff --git a/conf/monit/system.conf b/conf/monit/system.conf index c34969e..ca29ded 100644 --- a/conf/monit/system.conf +++ b/conf/monit/system.conf @@ -1,8 +1,8 @@ check system $HOST #SystemLoad - if loadavg (5min) > 4 then exec "/opt/MonitNotify.sh 'SYS-WARN:: High load (5min)'" + if loadavg (5min) > 4 then exec "/opt/MonitNotify.sh 'SYS-WARN: High load (5min)'" else if recovered then exec "/opt/MonitNotify.sh 'SYS-OK: load (5min)'" - if loadavg (15min) > 2 then exec "/opt/MonitNotify.sh 'SYS-WARN:: High load (15min)'" + if loadavg (15min) > 2 then exec "/opt/MonitNotify.sh 'SYS-WARN: High load (15min)'" else if recovered then exec "/opt/MonitNotify.sh 'SYS-OK: load (15min)'" #Memory @@ -18,7 +18,7 @@ check system $HOST else if recovered then exec "/opt/MonitNotify.sh 'SYS-OK: CPU(sys) threshold'" if cpu usage (wait) > 80% for 4 cycles then exec"/opt/MonitNotify.sh 'SYS-WARN: CPU(wait) threshold'" else if recovered then exec "/opt/MonitNotify.sh 'SYS-OK: CPU(wait) threshold'" - if cpu usage > 200% for 4 cycles then exec "/opt/MonitNotify.sh /opt/MonitNotify.sh 'SYS-WARN: CPU threshold'" + if cpu usage > 200% for 4 cycles then exec "/opt/MonitNotify.sh 'SYS-WARN: CPU threshold'" else if recovered then exec "/opt/MonitNotify.sh 'SYS-OK: CPU threshold'" #Disk