diff --git a/setup_monit.php b/setup_monit.php index 5e4d275d068c9470ca54c410c4abe0f585caa117..918e0c91d6303b03a4a4b84a1e3aaa16d4aa2ca3 100644 --- a/setup_monit.php +++ b/setup_monit.php @@ -37,6 +37,9 @@ if($i == $force_special) { return $passwd; } +// Set path to systemctl +$systemctlPath = trim(shell_exec('command -v systemctl')); + print('[INFO] Installing Monit' . "\n"); shell_exec('DEBIAN_FRONTEND="noninteractive" apt-get install -o Dpkg::Options::="--force-overwrite" -qq -y monit'); print('[INFO] Configuring Monit.' . "\n"); @@ -110,8 +113,8 @@ foreach ($services as $service) { if ($service == 'apache2') { $conf='check process apache with pidfile /var/run/apache2/apache2.pid group apache - start program = "/usr/bin/systemctl start apache2" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop apache2" + start program = "' . $systemctlPath . ' start apache2" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop apache2" if failed port 80 protocol http then restart if failed port 443 then restart if 5 restarts within 5 cycles then timeout @@ -130,8 +133,8 @@ check file apache_rc with path /etc/init.d/apache2 if ($service == 'nginx') { $conf='check process nginx with pidfile /var/run/nginx.pid group nginx - start program = "/usr/bin/systemctl start nginx" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop nginx" + start program = "' . $systemctlPath . ' start nginx" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop nginx" if failed port 80 protocol http then restart if failed port 443 then restart if 5 restarts within 5 cycles then timeout @@ -151,8 +154,8 @@ check file nginx_rc with path /etc/init.d/nginx if (file_exists('/etc/init.d/mariadb') && file_exists('/usr/sbin/mariadbd')) { $conf='check process mariadb with pidfile /var/run/mysqld/mysqld.pid group mysql - start program = "/usr/bin/systemctl start mariadb" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop mariadb" + start program = "' . $systemctlPath . ' start mariadb" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop mariadb" if failed host 127.0.0.1 port 3306 protocol mysql then restart if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 2 cycles then restart if 5 restarts within 5 cycles then timeout @@ -170,8 +173,8 @@ check file mysql_rc with path /etc/init.d/mariadb } elseif (file_exists('/etc/init.d/mysql') && file_exists('/usr/sbin/mysqld')) { $conf='check process mariadb with pidfile /var/run/mysqld/mysqld.pid group mysql - start program = "/usr/bin/systemctl start mariadb" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop mariadb" + start program = "' . $systemctlPath . ' start mariadb" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop mariadb" if failed host 127.0.0.1 port 3306 protocol mysql then restart if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 4 cycles then restart if 5 restarts within 5 cycles then timeout @@ -189,8 +192,8 @@ check file mysql_rc with path /etc/init.d/mysql } else { $conf='check process mariadb with pidfile /var/run/mysqld/mysqld.pid group mysql - start program = "/usr/bin/systemctl start mariadb" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop mariadb" + start program = "' . $systemctlPath . ' start mariadb" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop mariadb" if failed host 127.0.0.1 port 3306 protocol mysql then restart if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 4 cycles then restart if 5 restarts within 5 cycles then timeout'; @@ -202,8 +205,8 @@ check file mysql_rc with path /etc/init.d/mysql $phpfpm = 'php' . $curver . '-fpm'; if ($service == $phpfpm) { $conf='check process ' . $phpfpm . ' with pidfile /var/run/php/' . $phpfpm . '.pid - start program = "/usr/bin/systemctl start ' . $phpfpm .'" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop ' . $phpfpm . '" + start program = "' . $systemctlPath . ' start ' . $phpfpm .'" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop ' . $phpfpm . '" if failed unixsocket /var/run/php/' . $phpfpm . '.sock then restart if 5 restarts within 5 cycles then timeout'; } @@ -212,8 +215,8 @@ check file mysql_rc with path /etc/init.d/mysql if ($service == 'memcached') { $conf='check process memcached with pidfile /var/run/memcached/memcached.pid group memcached - start program = "/usr/bin/systemctl start memcached" - stop program = "/usr/bin/systemctl stop memcached" + start program = "' . $systemctlPath . ' start memcached" + stop program = "' . $systemctlPath . ' stop memcached" if failed host 127.0.0.1 port 11211 protocol memcache then restart if 5 restarts within 5 cycles then timeout @@ -232,16 +235,16 @@ check file memcache_rc with path /etc/init.d/memcached if ($service == 'pure-ftpd-mysql') { $conf='check process pure-ftpd-mysql with pidfile /var/run/pure-ftpd/pure-ftpd.pid - start program = "/usr/bin/systemctl start pure-ftpd-mysql" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop pure-ftpd-mysql" + start program = "' . $systemctlPath . ' start pure-ftpd-mysql" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop pure-ftpd-mysql" if failed port 21 protocol ftp then restart if 5 restarts within 5 cycles then timeout'; } if ($service == 'fail2ban') { $conf='check process fail2ban with pidfile /var/run/fail2ban/fail2ban.pid - start program = "/usr/bin/systemctl start fail2ban" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop fail2ban" + start program = "' . $systemctlPath . ' start fail2ban" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop fail2ban" if failed unixsocket /var/run/fail2ban/fail2ban.sock then restart if 5 restarts within 5 cycles then timeout @@ -253,8 +256,8 @@ check file fail2ban_log with path /var/log/fail2ban.log if ($service == 'sshd') { $conf='check process sshd with pidfile /var/run/sshd.pid group sshd - start program = "/usr/bin/systemctl start ssh" - stop program = "/usr/bin/systemctl stop ssh" + start program = "' . $systemctlPath . ' start ssh" + stop program = "' . $systemctlPath . ' stop ssh" if failed host localhost port 22 with proto ssh then restart if 5 restarts with 5 cycles then timeout depend on sshd_bin @@ -288,8 +291,8 @@ check file sshd_rc with path /etc/ssh/sshd_config $conf='check process crond with pidfile /var/run/crond.pid group system group crond - start program = "/usr/bin/systemctl start cron" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop cron" + start program = "' . $systemctlPath . ' start cron" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop cron" if 5 restarts with 5 cycles then timeout depend cron_bin depend cron_rc @@ -312,8 +315,8 @@ check directory cron_spool with path /var/spool/cron/crontabs if ($service == 'named') { $conf='check process named with pidfile /var/run/named/named.pid - start program = "/usr/bin/systemctl start named" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop named" + start program = "' . $systemctlPath . ' start named" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop named" if failed port 53 use type udp protocol dns then restart if 5 restarts within 5 cycles then timeout'; } @@ -322,8 +325,8 @@ check directory cron_spool with path /var/spool/cron/crontabs $conf='check process postfix with pidfile /var/spool/postfix/pid/master.pid group mail group postfix - start program = "/usr/bin/systemctl start postfix" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop postfix" + start program = "' . $systemctlPath . ' start postfix" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop postfix" if failed host localhost port 25 with protocol smtp for 2 times within 2 cycles then restart if 5 restarts with 5 cycles then timeout depend master_bin @@ -367,8 +370,8 @@ check file postfix_rc with path /etc/init.d/postfix if ($service == 'dovecot') { $conf='check process dovecot with pidfile /var/run/dovecot/master.pid group mail - start program = "/usr/bin/systemctl start dovecot" with timeout 60 seconds - stop program = "/usr/bin/systemctl stop dovecot" + start program = "' . $systemctlPath . ' start dovecot" with timeout 60 seconds + stop program = "' . $systemctlPath . ' stop dovecot" #if failed host mail.yourdomain.tld port 993 type tcpssl sslauto protocol imap then restart if failed port 143 protocol imap then restart if 5 restarts within 5 cycles then timeout'; @@ -377,8 +380,8 @@ check file postfix_rc with path /etc/init.d/postfix if ($service == 'rspamd') { $conf='check process rspamd matching \'rspamd: main process\' - start program = "/usr/bin/systemctl start rspamd" with timeout 60 seconds - stop program = "/usr/bin/systemctl start rspamd" + start program = "' . $systemctlPath . ' start rspamd" with timeout 60 seconds + stop program = "' . $systemctlPath . ' start rspamd" if cpu is greater than 40% then alert if cpu > 60% for 4 cycles then alert @@ -388,8 +391,8 @@ check file postfix_rc with path /etc/init.d/postfix if ($service == 'redis-server') { $conf='check process redis-server with pidfile "/var/run/redis/redis-server.pid" - start program = "/usr/bin/systemctl start redis-server" - stop program = "/usr/bin/systemctl stop redis-server" + start program = "' . $systemctlPath . ' start redis-server" + stop program = "' . $systemctlPath . ' stop redis-server" if failed host 127.0.0.1 port 6379 protocol redis then restart if 5 restarts within 5 cycles then timeout'; }