mrepo=https://git.ictmaatwerk.com/VPS-scripts/Monit mbranch=main mkdir /var/run/monit if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then monitconf=/etc/monit/monitrc #ServiceDefenition monitMysqlserv=mysql monitApachepro=apache monitPhpSock=/var/run/php/"$phpFPMService".sock monitPhpPid=/var/run/php/"$phpFPMService".pid monitPhpPro=$phpFPMService /var/run/php/PHPSRV.sock elif [ "$shortdist" = "el8" ]; then monitconf=/etc/monitrc rm -rf /etc/monit.d #ServiceDefenition monitMysqlserv=mysqld monitApachepro=httpd monitPhpSock=/var/opt/remi/php"${phpver//.}"/run/php-fpm/www.sock 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/.*)?" restorecon -R -v "/var/run/monit" fi systemctl stop monit 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 /conf/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) #SystemMonitor curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/system.conf -o /etc/monit/conf.d/system.conf #sshd if echo "$SysServiceList" | grep -Fq 'sshd'; then curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/sshd.conf -o /etc/monit/conf.d/sshd.conf fi #Fail2Ban if echo "$SysServiceList" | grep -Fq 'fail2ban'; then curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/fail2ban.conf -o /etc/monit/conf.d/fail2ban.conf fi if echo "$SysServiceList" | grep -Fq "$monitMysqlserv"; then curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/mysql.conf -o /etc/monit/conf.d/mysql.conf sed -i "s/MYSQLserv/$monitMysqlservice/g" /etc/monit/conf.d/mysql.conf fi if echo "$SysServiceList" | grep -Fq 'nginx'; then curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/nginx.conf -o /etc/monit/conf.d/nginx.conf fi if echo "$SysServiceList" | grep -Fq "$phpFPMService" && test ! -z "$phpFPMService"; then curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/php-fpm.conf -o /etc/monit/conf.d/php"$phpver".conf sed -i "s/PHPpid/$monitPhpPid/g" /etc/monit/conf.d/php"$phpver".conf sed -i "s/PHPpro/$monitPhpPro/g" /etc/monit/conf.d/php"$phpver".conf sed -i "s/PHPsrv/$phpFPMService/g" /etc/monit/conf.d/php"$phpver".conf sed -i "s/PHPsock/$monitPhpSock/g" /etc/monit/conf.d/php"$phpver".conf fi if echo "$SysServiceList" | grep -Fq "$apacheService" && test ! -z "$apacheService"; then curl --retry 7 --retry-delay 5 -s "$mrepo"/raw/branch/"$mbranch"/conf/monit/apache.conf -o /etc/monit/conf.d/apache.conf sed -i "s/APAserv/$apacheService/g" /etc/monit/conf.d/apache.conf sed -i "s/APApro/$monitApachepro/g" /etc/monit/conf.d/apache.conf fi systemctl enable monit systemctl start monit unset monitMysqlserv monitApachepro monitPhpSock monitPhpPid monitPhpPro monitconf