Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pfSense-pkg-apcupsd - new option for set shutdown behavior #273

Merged
merged 3 commits into from
Feb 1, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sysutils/pfSense-pkg-apcupsd/Makefile
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

PORTNAME= pfSense-pkg-apcupsd
PORTVERSION= 0.3.9
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
22 changes: 20 additions & 2 deletions sysutils/pfSense-pkg-apcupsd/files/usr/local/pkg/apcupsd.inc
Original file line number Diff line number Diff line change
@@ -140,6 +140,7 @@ function sync_package_apcupsd() {
$annoy = $apcupsd_config['annoy'] ?: "300";
$annoydelay = $apcupsd_config['annoydelay'] ?: "60";
$killdelay = $apcupsd_config['killdelay'] ?: "0";
$shutdownbehavior = $apcupsd_config['shutdownbehavior'];
$netserver = $apcupsd_config['netserver'];
$nisip= $apcupsd_config['nisip'] ?: "0.0.0.0";
$nisport = $apcupsd_config['nisport'] ?: "3551";
@@ -184,7 +185,7 @@ function sync_package_apcupsd() {
)
);

apccontrol_scripts_install($emailnotification);
apccontrol_scripts_install($emailnotification,$shutdownbehavior);

if (!file_exists("{$g['tmp_path']}/.rc.start_packages.running")) {
log_error("Starting service apcupsd");
@@ -195,7 +196,7 @@ function sync_package_apcupsd() {
conf_mount_ro();
}

function apccontrol_scripts_install($emailnotification) {
function apccontrol_scripts_install($emailnotification,$shutdownbehavior) {
global $config, $g;

define('APCUPSD_BASE', '/usr/local');
@@ -259,6 +260,23 @@ EOF;
file_put_contents(APCUPSD_BASE . "/etc/apcupsd/" . $apccontrol_script, $apccontrol_script_file, LOCK_EX);
}

if ($shutdownbehavior == "poweroff") {
$doshutdown_script_file =<<<EOF
#!/bin/sh

printf "Beginning Shutdown Sequence (shutdown -p)" | wall
/etc/rc.halt

exit 99

EOF;

file_put_contents(APCUPSD_BASE . "/etc/apcupsd/doshutdown", $doshutdown_script_file, LOCK_EX);
@chmod(APCUPSD_BASE . "/etc/apcupsd/doshutdown", 0744);
} else {
unlink_if_exists(APCUPSD_BASE . "/etc/apcupsd/doshutdown");
}

}

function check_nis_running_apcupsd() {
19 changes: 19 additions & 0 deletions sysutils/pfSense-pkg-apcupsd/files/usr/local/pkg/apcupsd.xml
Original file line number Diff line number Diff line change
@@ -246,6 +246,25 @@
<size>10</size>
<default_value>0</default_value>
</field>
<field>
<fielddescr>Shutdown Behavior</fielddescr>
<fieldname>shutdownbehavior</fieldname>
<description>
<![CDATA[
Halt - /sbin/shutdown -h now <br />
The system is halted at the specified time. (default) <br />
<br />
Power Off - /sbin/shutdown -p now <br />
The system is halted and the power is turned off (hardware support required) at the specified time.
]]>
</description>
<type>select</type>
<default_value>halt</default_value>
<options>
<option><name>Halt</name><value>halt</value></option>
<option><name>Power Off</name><value>poweroff</value></option>
</options>
</field>
<field>
<name>Configuration statements for Network Information Server</name>
<type>listtopic</type>