Skip to content

Commit

Permalink
Allow service status to be pending on system boot or service restart.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennypage committed Aug 3, 2016
1 parent 8be509d commit 0cc3600
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
38 changes: 29 additions & 9 deletions sysutils/pfSense-pkg-nut/files/usr/local/pkg/nut/nut.inc
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ function nut_write_rcfile($driver) {
$start .= "\n /usr/bin/killall -q -9 upsdrvctl";
if (isset($driver)) {
$start .= "\n /usr/bin/killall -q -9 $driver";
}

/* Service start may run nut.sh in the background, and monitoring keys off
upsmon, so start it first. */
$start .= "\n /usr/local/sbin/upsmon";
if (isset($driver)) {
$start .= "\n /usr/local/sbin/upsdrvctl start &";
/* Since we are starting the driver in backgroud, give it a moment to start. */
$start .= "\n sleep 1";
$start .= "\n /usr/local/sbin/upsd -u root";
}
$start .= "\n /usr/local/sbin/upsmon";
$start .= "\n return 0";

$stop = "echo stopping NUT";
Expand Down Expand Up @@ -116,9 +122,9 @@ function nut_write_file($file, $content) {
function nut_sync_config() {
global $config;

if (is_service_running("nut")) {
if (is_service_running('nut')) {
log_error("Stopping service nut");
stop_service("nut");
stop_service('nut');
}

$nut_config = &$config['installedpackages']['nut']['config'][0];
Expand Down Expand Up @@ -279,7 +285,8 @@ function nut_sync_config() {
}

log_error("Starting service nut");
start_service("nut");
start_service('nut');
sleep(3);
}


Expand Down Expand Up @@ -318,9 +325,13 @@ function nut_ups_status()
$status['_name'] = $ups;

/* Even though upsc might actually work (no password) it's better to report failure of upsmon */
if (!is_process_running("upsmon")) {
$status['_summary'] = "UPS Monitor not running";
$status['_alert'] = true;
if (!is_service_running('nut')) {
if (get_uptime_sec() < 60) {
$status['_summary'] = "UPS Monitor pending";
} else {
$status['_summary'] = "UPS Monitor not running";
$status['_alert'] = true;
}
return $status;
}

Expand All @@ -339,6 +350,15 @@ function nut_ups_status()
}

if (count($status) < 2) {
/* If we are using a local upsd, allow it a minute to initialize before declaring an alert */
if (file_exists("/var/db/nut/upsd.pid")) {
$stat = stat("/var/db/nut/upsd.pid");
if (time() - $stat['mtime'] < 60) {
$status['_summary'] = "UPS Daemon pending";
return $status;
}
}

$status['_summary'] = "Failed to retrieve status";
$status['_alert'] = true;
return $status;
Expand Down Expand Up @@ -422,9 +442,9 @@ function nut_ups_status()


function nut_deinstall_command() {
if (is_service_running("nut")) {
if (is_service_running('nut')) {
log_error("Stopping service nut");
stop_service("nut");
stop_service('nut');
}

unlink_if_exists(NUT_RCFILE);
Expand Down
11 changes: 10 additions & 1 deletion sysutils/pfSense-pkg-nut/files/usr/local/www/nut_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,22 @@ function print_row_pct($desc, $value) {
print '<td>' . htmlspecialchars($value) . '</td>';
print '</tr>';
}
?>
?>

</table>
</div>
</div>
</div>

<?php
/* If there is a status error, reload the page after 10 seconds */
if ($status['_alert'] || count($status) <= 2) {
print "<script type=\"text/javascript\">\n";
print "//<![CDATA[\n";
print "setTimeout(function(){ window.location.reload(1); }, 10000);\n";
print "//]]>\n";
print "</script>\n";
}

include("foot.inc");
?>

0 comments on commit 0cc3600

Please sign in to comment.