From 1d30d667df0c29089c539c0bc10d1b67b46c2769 Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 27 Aug 2013 21:48:51 -0400 Subject: Add ProcWatch, a little package to monitor services and restart them if they are stopped. Needs more testing, but the basics work. --- config/procwatch/procwatch.inc | 39 +++++ config/procwatch/procwatch.xml | 72 ++++++++++ config/procwatch/procwatch_cron.php | 6 + config/procwatch/services_procwatch.php | 211 ++++++++++++++++++++++++++++ config/procwatch/services_procwatch_add.php | 115 +++++++++++++++ 5 files changed, 443 insertions(+) create mode 100644 config/procwatch/procwatch.inc create mode 100644 config/procwatch/procwatch.xml create mode 100644 config/procwatch/procwatch_cron.php create mode 100644 config/procwatch/services_procwatch.php create mode 100644 config/procwatch/services_procwatch_add.php (limited to 'config') 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 @@ + 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 diff --git a/config/procwatch/procwatch.xml b/config/procwatch/procwatch.xml new file mode 100644 index 00000000..9db6d40d --- /dev/null +++ b/config/procwatch/procwatch.xml @@ -0,0 +1,72 @@ + + + + + + + + ProcWatch + None + Monitors for stopped services and restarts them. + ProcWatch + 1.0 + Services: Procwatch + /usr/local/pkg/procwatch.inc + + ProcWatch + +
Services
+ /services_procwatch.php +
+ + /usr/local/www/ + 644 + http://www.pfsense.com/packages/config/procwatch/services_procwatch.php + + + /usr/local/www/ + 644 + http://www.pfsense.com/packages/config/procwatch/services_procwatch_add.php + + + /usr/local/pkg/ + 755 + http://www.pfsense.com/packages/config/procwatch/procwatch_cron.php + + + /usr/local/pkg/ + 644 + http://www.pfsense.com/packages/config/procwatch/procwatch.inc + +
\ No newline at end of file diff --git a/config/procwatch/procwatch_cron.php b/config/procwatch/procwatch_cron.php new file mode 100644 index 00000000..f4cc7608 --- /dev/null +++ b/config/procwatch/procwatch_cron.php @@ -0,0 +1,6 @@ +#!/usr/local/bin/php -f + \ No newline at end of file diff --git a/config/procwatch/services_procwatch.php b/config/procwatch/services_procwatch.php new file mode 100644 index 00000000..c8a16b07 --- /dev/null +++ b/config/procwatch/services_procwatch.php @@ -0,0 +1,211 @@ + $pd) { + if (preg_match("/move_(\d+)_x/", $pn, $matches)) { + $movebtn = $matches[1]; + break; + } + } + /* move selected services before this service */ + if (isset($movebtn) && is_array($_POST['pwservices']) && count($_POST['pwservices'])) { + $a_pwservices_new = array(); + + /* copy all services < $movebtn and not selected */ + for ($i = 0; $i < $movebtn; $i++) { + if (!in_array($i, $_POST['pwservices'])) + $a_pwservices_new[] = $a_pwservices[$i]; + } + + /* copy all selected services */ + for ($i = 0; $i < count($a_pwservices); $i++) { + if ($i == $movebtn) + continue; + if (in_array($i, $_POST['pwservices'])) + $a_pwservices_new[] = $a_pwservices[$i]; + } + + /* copy $movebtn service */ + if ($movebtn < count($a_pwservices)) + $a_pwservices_new[] = $a_pwservices[$movebtn]; + + /* copy all services > $movebtn and not selected */ + for ($i = $movebtn+1; $i < count($a_pwservices); $i++) { + if (!in_array($i, $_POST['pwservices'])) + $a_pwservices_new[] = $a_pwservices[$i]; + } + $a_pwservices = $a_pwservices_new; + procwatch_cron_job(); + write_config(); + header("Location: services_procwatch.php"); + return; + } +} + +$closehead = false; +$pgtitle = array(gettext("Services"),gettext("ProcWatch")); +include("head.inc"); + +?> + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ +

+
  + + + + +
+ + " border="0" alt="delete" /> + + " onclick="return confirm('')" /> + + " alt="add" />
+
+ + + + + + + + + +
" height="17" type="image" width="17" border="0" />')">" alt="delete" />
+
+ + + + + + + + +
" border="0" alt="move" />" border="0" alt="move" />
+ + " border="0" alt="delete" /> + + " onclick="return confirm('')" /> + + " alt="add" />
+
+ +
+
+
+ + + diff --git a/config/procwatch/services_procwatch_add.php b/config/procwatch/services_procwatch_add.php new file mode 100644 index 00000000..457a93a4 --- /dev/null +++ b/config/procwatch/services_procwatch_add.php @@ -0,0 +1,115 @@ + + + + + + + + + +
+ + + + + + + + + + + + +
+ +
  + " /> " onclick="history.back()" /> +
+
+ + + -- cgit v1.2.3