Skip to content

Commit

Permalink
Merge pull request #162 from dennypage/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgarga committed Aug 4, 2016
2 parents a5b2fe9 + ef951e7 commit 6c6c877
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 30 deletions.
16 changes: 8 additions & 8 deletions sysutils/pfSense-pkg-nut/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-nut
PORTVERSION= 2.7.4
PORTVERSION= 2.7.4_1
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
Expand All @@ -10,17 +10,17 @@ EXTRACT_ONLY= # empty
MAINTAINER= coreteam@pfsense.org
COMMENT= Network UPS Tools

LICENSE= ESF
LICENSE= ESF

RUN_DEPENDS= ${LOCALBASE}/sbin/upsd:sysutils/nut \
RUN_DEPENDS= ${LOCALBASE}/sbin/upsd:sysutils/nut \
${LOCALBASE}/sbin/upsmon:sysutils/nut \
${LOCALBASE}/sbin/upsdrvctl:sysutils/nut

NO_BUILD= yes
NO_MTREE= yes
NO_BUILD= yes
NO_MTREE= yes

SUB_FILES= pkg-install pkg-deinstall
SUB_LIST= PORTNAME=${PORTNAME}
SUB_FILES= pkg-install pkg-deinstall
SUB_LIST= PORTNAME=${PORTNAME}

do-extract:
${MKDIR} ${WRKSRC}
Expand All @@ -30,7 +30,7 @@ do-install:
${MKDIR} ${STAGEDIR}${PREFIX}/pkg/nut
${MKDIR} ${STAGEDIR}/etc/inc/priv
${MKDIR} ${STAGEDIR}${PREFIX}/www
${MKDIR} ${STAGEDIR}${PREFIX}/www/shortcuts
${MKDIR} ${STAGEDIR}${PREFIX}/www/shortcuts
${MKDIR} ${STAGEDIR}${PREFIX}/www/widgets/widgets
${MKDIR} ${STAGEDIR}${PREFIX}/www/widgets/include
${MKDIR} ${STAGEDIR}${DATADIR}
Expand Down
4 changes: 2 additions & 2 deletions sysutils/pfSense-pkg-nut/files/usr/local/pkg/nut.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
]]>
</copyright>
<name>nut</name>
<version>2.7.4</version>
<version>2.7.4_1</version>
<title>Services: UPS</title>
<savetext>Change</savetext>
<include_file>/usr/local/pkg/nut/nut.inc</include_file>
<menu>
<name>UPS</name>
<tooltiptext>Network UPS Tools status</tooltiptext>
<section>Services</section>
<url>nut_status.php</url>
<url>/nut_status.php</url>
</menu>
<service>
<name>nut</name>
Expand Down
37 changes: 28 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,16 @@ 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 status 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 +121,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 +284,8 @@ function nut_sync_config() {
}

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


Expand Down Expand Up @@ -318,9 +324,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 +349,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 +441,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: 5 additions & 6 deletions sysutils/pfSense-pkg-nut/files/usr/local/www/nut_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@
if (!empty($a_nut['snmpcommunity']) && $a_nut['snmpcommunity'] != 'public') {
$pconfig['extra_args'] = "community=" . $a_nut['snmpcommunity'] . "\n";
}
/* prior version of nut package had v2c incorrectly marked as default */
if ($a_nut['snmpversion'] == 'v2c') {
$pconfig['extra_args'] .= "snmp_version=v2c\n";
}
/* The prior version of nut package had v2c incorrectly marked as default. Use
of 64 bit counters generally isn't desirable, so we explictly ignore that here.
Add "snmp_version=v2c" to Driver Extra Arguments to restore. */
} elseif ($a_nut['monitor'] == 'remote') {
$pconfig['type'] = 'remote_nut';
$pconfig['name'] = $a_nut['remotename'];
Expand Down Expand Up @@ -333,8 +332,8 @@
include("head.inc");

$tab_array = array();
$tab_array[] = array(gettext("UPS Status"), false, "nut_status.php");
$tab_array[] = array(gettext("UPS Settings"), true, "nut_settings.php");
$tab_array[] = array(gettext("UPS Status"), false, "/nut_status.php");
$tab_array[] = array(gettext("UPS Settings"), true, "/nut_settings.php");
display_top_tabs($tab_array);


Expand Down
15 changes: 12 additions & 3 deletions sysutils/pfSense-pkg-nut/files/usr/local/www/nut_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function print_row_pct($desc, $value) {
include("head.inc");

$tab_array = array();
$tab_array[] = array(gettext("UPS Status"), true, "nut_status.php");
$tab_array[] = array(gettext("UPS Settings"), false, "nut_settings.php");
$tab_array[] = array(gettext("UPS Status"), true, "/nut_status.php");
$tab_array[] = array(gettext("UPS Settings"), false, "/nut_settings.php");
display_top_tabs($tab_array);


Expand Down 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");
?>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
$nut_status_title = gettext("UPS Status");
$nut_status_title_link = "nut_status.php";
$nut_status_title_link = "/nut_status.php";
?>
6 changes: 5 additions & 1 deletion sysutils/pfSense-pkg-nut/pkg-descr
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Network UPS Tools
Network UPS Tools provides support for monitoring of Uninterruptible Power
Supplies. It supports UPS units attached locally via USB or serial, and remote
units via the SNMP protocol, the APCUPSD protocol or the NUT protocol.

WWW: https://forum.pfsense.org/index.php?topic=115349.0

0 comments on commit 6c6c877

Please sign in to comment.