diff options
author | jim-p <jimp@pfsense.org> | 2013-08-27 21:48:51 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2013-08-27 21:48:51 -0400 |
commit | 1d30d667df0c29089c539c0bc10d1b67b46c2769 (patch) | |
tree | 42c1556e69a8817d30e437d2a56701334290091f /config/procwatch/procwatch.inc | |
parent | 42ce51dbf43450e455ffe212e51cefe934c396aa (diff) | |
download | pfsense-packages-1d30d667df0c29089c539c0bc10d1b67b46c2769.tar.gz pfsense-packages-1d30d667df0c29089c539c0bc10d1b67b46c2769.tar.bz2 pfsense-packages-1d30d667df0c29089c539c0bc10d1b67b46c2769.zip |
Add ProcWatch, a little package to monitor services and restart them if they are stopped. Needs more testing, but the basics work.
Diffstat (limited to 'config/procwatch/procwatch.inc')
-rw-r--r-- | config/procwatch/procwatch.inc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/config/procwatch/procwatch.inc b/config/procwatch/procwatch.inc new file mode 100644 index 00000000..b2210e03 --- /dev/null +++ b/config/procwatch/procwatch.inc @@ -0,0 +1,39 @@ +<?php +require_once("config.inc"); +require_once("services.inc"); +require_once("service-utils.inc"); +require_once("util.inc"); + +function procwatch_cron_job() { + global $config; + if (!is_array($config['installedpackages']['procwatch']['item'])) { + $config['installedpackages']['procwatch']['item'] = array(); + } + $a_pwservices = &$config['installedpackages']['procwatch']['item']; + + if (count($a_pwservices) > 0) { + // Add the cron job if it doesn't exist. + install_cron_job("/usr/local/pkg/procwatch_cron.php", true, "*/1"); + } else { + // Remove the cron job + install_cron_job("/usr/local/pkg/procwatch_cron.php", false, "*/1"); + } +} + +function procwatch_check_services() { + global $config; + if (!is_array($config['installedpackages']['procwatch']['item'])) { + $config['installedpackages']['procwatch']['item'] = array(); + } + $a_pwservices = &$config['installedpackages']['procwatch']['item']; + + foreach ($a_pwservices as $svc) { + if (!is_service_running($svc['name'])) { + $descr = strlen($svc['description']) > 50 ? substr($svc['description'], 0, 50) . "..." : $svc['description']; + log_error("ProcWatch detected service {$svc['name']} stopped. Restarting {$svc['name']} ({$descr})"); + service_control_start($svc['name'], $svc); + } + } +} + +?>
\ No newline at end of file |