Skip to content

Commit

Permalink
2015-08-20
Browse files Browse the repository at this point in the history
  • Loading branch information
macexx committed Aug 20, 2015
0 parents commit 789107d
Show file tree
Hide file tree
Showing 22 changed files with 1,069 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unRAID 6 Plugins
================
Binary file added nut/archive/nut-2015-08-20.txz
Binary file not shown.
69 changes: 69 additions & 0 deletions nut/source/etc/rc.d/rc.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh
# Slackware startup script for Network UPS Tools
# Copyright 2010 V'yacheslav Stetskevych
# Edited for unRAID by macester [email protected]

DPATH=/usr/bin
FILE=/boot/config/plugins/nut/nut.cfg
export PATH=$DPATH:$PATH



start_driver() {
/usr/sbin/upsdrvctl -u root start || exit 1
}

start_upsd() {
/usr/sbin/upsd -u root || exit 1
}

start_upsmon() {
/usr/sbin/upsmon -u root || exit 1
}

stop() {
echo "Stopping the UPS services... "
if pgrep upsd 2>&1 >/dev/null; then
/usr/sbin/upsd -c stop; fi
if pgrep upsmon 2>&1 >/dev/null; then
/usr/sbin/upsmon -c stop; fi
/usr/sbin/upsdrvctl stop
sleep 2
if [ -f /var/run/upsmon.pid ]; then
rm /var/run/upsmon.pid; fi
}

write_config() {
/usr/local/emhttp/plugins/nut/scripts/write_config.sh
}

case "$1" in
start) # starts everything (for a ups server box)
sleep 1
write_config
sleep 3
start_driver
start_upsd
start_upsmon
;;
start_upsmon) # starts upsmon only (for a ups client box)
start_upsmon
;;
stop) # stops all UPS-related daemons
stop
;;
shutdown) # shuts down the UPS
echo "Killing inverter..."
/usr/sbin/upsdrvctl shutdown
;;
reload)
write_config
/usr/sbin/upsd -c reload
/usr/sbin/upsmon -c reload
;;
write_config)
write_config
;;
*)
echo "Usage: $0 {start|start_upsmon|stop|shutdown|reload|restart|write_config}"
esac
30 changes: 30 additions & 0 deletions nut/source/etc/ups/notifycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# NUT NOTIFYCMD script macester [email protected]
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin

COUNT_DOWN=180

trap "exit 0" SIGTERM
if [ "$NOTIFYTYPE" = "ONLINE" ]
then
echo $0: power restored | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is no longer on battery" -i "normal"
# Cause all instances of this script to exit.
killall -s SIGTERM `basename $0`
fi
if [ "$NOTIFYTYPE" = "ONBATT" ]
then
echo $0: $COUNT_DOWN seconds till system powers down... | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is on battery" -i "alert"
# Loop with one second interval to allow SIGTERM reception.
let "n = $COUNT_DOWN"
while [ $n -ne 0 ]
do
sleep 1
let "n--"
done
echo $0: commencing shutdown | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is shutting down unRAID" -i "alert"
upsmon -c fsd
fi
1 change: 1 addition & 0 deletions nut/source/etc/ups/nut.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MODE=standalone
3 changes: 3 additions & 0 deletions nut/source/etc/ups/ups.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ups]
driver=none
port=auto
1 change: 1 addition & 0 deletions nut/source/etc/ups/upsd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LISTEN 0.0.0.0
8 changes: 8 additions & 0 deletions nut/source/etc/ups/upsd.users
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[admin]
password=adminpass
actions=set
actions=fsd
instcmds=all
[monuser]
password=pass
upsmon master
6 changes: 6 additions & 0 deletions nut/source/etc/ups/upsmon.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MONITOR ups@localhost 1 monuser pass master
SHUTDOWNCMD "/usr/local/sbin/powerdown"
POWERDOWNFLAG /etc/ups/flag/killpower
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYCMD "/etc/ups/notifycmd"
1 change: 1 addition & 0 deletions nut/source/etc/ups/upssched.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 14 additions & 0 deletions nut/source/usr/bin/nut_kill_inverter
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# This file is part of Network UPS Tools build for Slackware Linux.
# It should be sourced in /etc/rc.d/rc.0 as part of the poweroff sequence.
# Here, we signal the UPS to shut off the power.
# Reference: http://www.mail-archive.com/[email protected]/msg01099.html
# To be sourced after the genpowerd block and before the actual halt.
if [ -f /etc/ups/flag/killpower ]; then
echo "----------------------------------------Shutting down UPS power!"
/usr/sbin/upsdrvctl shutdown
sleep 40
echo "The UPS was not shut off properly, or the power came back in the"
echo "middle of the shutdown process, or USB communication failed."
sleep 10
fi
11 changes: 11 additions & 0 deletions nut/source/usr/bin/nut_restart_udev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# This file is part of Network UPS Tools build for Slackware Linux.
# It should be sourced in /etc/rc.d/rc.0 as part of the poweroff sequence.
# Here, we restart udev so that the system is able to kill off the UPS inverter.
# Reference: http://www.mail-archive.com/[email protected]/msg01099.html
# To be sourced after the rootfs has been remounted read-only.
if [ -f /etc/ups/flag/killpower ]; then
echo "Restarting udev to be able to shut the UPS inverter off..."
/etc/rc.d/rc.udev start
sleep 10
fi
108 changes: 108 additions & 0 deletions nut/source/usr/local/emhttp/plugins/nut/NUTsettings.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Menu="OtherSettings"
Type="xmenu"
Title="NUT Settings"
Icon="nut.png"
---
<?PHP
/* Copyright 2015, Dan Landon.
* Copyright 2015, Bergware International.
* Copyright 2015, Lime Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Modified by macester [email protected] for NUT plugin
*
*/
?>

<?
$sName = "nut";
$cfg = parse_plugin_cfg($sName);
?>

<script>
$(function() {
showStatus('upsmon');
});
</script>

<form markdown="1" name="nut_settings" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#file" value="<?=$sName?>/<?=$sName?>.cfg">
<input type="hidden" name="#include" value="/plugins/<?=$sName?>/include/update.nut.php">
<span style="float:right;margin-right:10px"><a href="http://www.networkupstools.org/docs/user-manual.chunked/" target="_blank" title="NUT UPS user manual"><i class="fa fa-file-text-o"></i> <u>Online Manual</u></a></span>

Start NUT UPS service:
: <select name="SERVICE" size="1">
<?=mk_option($cfg['SERVICE'], "disable", "No");?>
<?=mk_option($cfg['SERVICE'], "enable", "Yes");?>
</select>

> Set to 'Yes' to enable NUT and start the service, set to 'No' to disable NUT and stop the service.
> Setting 'Yes' will also enable NUT on unRAID boot.

UPS Driver:
: <input type="text" name="DRIVER" class="narrow" maxlength="25" value="<?=$cfg['DRIVER'];?>">

> Enter the *driver* which matches your UPS, check **"http://www.networkupstools.org/stable-hcl.html"** for a complete list.
>
> + **usbhid-ups** - **bcmxcp_usb** - **tripplite_usb** - **blazer_usb** - **richcomm_usbExample** USB-drivers.
>
> Above is the different usb drivers avaible. Example, enter **"usbhid-ups"** on the line without the quotes.

UPS Port:
: <input type="text" name="PORT" class="narrow" maxlength="25" value="<?=$cfg['PORT'];?>">

> Enter the *port* which your UPS connects to.
>
> + **auto** - Set to "auto" if the ups is connected by usb.
> + **/dev/tty0** - Example, for seriall devices**

UPS Mode:
: <input type="text" name="MODE" class="narrow" maxlength="25" value="<?=$cfg['MODE'];?>">

> Enter the *mode* which mode your UPS will run in.
>
> + **standalone** - When the ups is only used by the local host**
> + **netserver** - When nut clients/slaves need to connect to the ups**

Admin Username:
: <input type="text" name="ADMIN" class="narrow" maxlength="25" value="<?=$cfg['ADMIN'];?>">

> Enter the *username* for the administrator account for the UPS.
>
> + **EXAMPLE** - When you want to administrate or monitor the UPS remotely**

Admin Password:
: <input type="text" name="PASSWORD" class="narrow" maxlength="25" value="<?=$cfg['PASSWORD'];?>">

> Enter the *password* for the administrator account for the UPS.
>
> + **EXAMPLE** - When you want to administrate or monitor the UPS remotely**

Time on battery before shutdown (seconds):
: <input type="text" name="TIMER" class="narrow" maxlength="4" value="<?=$cfg['TIMER'];?>">

> The time in seconds before the system will power down if a power failure accours.

Turn off UPS after shutdown:
: <select name="UPSKILL" size="1">
<?=mk_option($cfg['UPSKILL'], "disable", "No");?>
<?=mk_option($cfg['UPSKILL'], "enable", "Yes");?>
</select>

> Set to *Yes* to turn off the power to the UPS after a shutdown.
>
> Check your bios and enable, "Automatically power on after power loss" so that the server starts again when powers is restored.


<input type="submit" name="#default" value="Default">
: <input type="submit" name="#apply" value="Apply"><input type="button" value="Done" onclick="done()">
</form>
<div id="title"><span class="left"><img src="/plugins/nut/icons/nutsettings.png" class="icon">NUT Status</span></div>

<?echo "<pre>".shell_exec("/usr/bin/upsc ups")."</pre>";?>
8 changes: 8 additions & 0 deletions nut/source/usr/local/emhttp/plugins/nut/default.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SERVICE="disable"
DRIVER="none"
PORT="auto"
MODE="standalone"
ADMIN="admin"
PASSWORD="adminpass"
TIMER="180"
UPSKILL="disable"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions nut/source/usr/local/emhttp/plugins/nut/include/update.nut.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?PHP
/* Copyright 2015, Dan Landon.
* Copyright 2015, Bergware International.
* Copyright 2015, Lime Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Edited by macester for NUT Plugin.
*/
?>
<?
$cfg = "/boot/config/plugins/nut/nut.cfg";

exec("/etc/rc.d/rc.nut stop");
exec("sed -i -e '/^SERVICE/c\\SERVICE=\"'{$_POST['SERVICE']}'\"' $cfg");
exec("sed -i -e '/^DRIVER/c\\DRIVER=\"'{$_POST['DRIVER']}'\"' $cfg");
exec("sed -i -e '/^PORT/c\\PORT=\"'{$_POST['PORT']}'\"' $cfg");
exec("sed -i -e '/^MODE/c\\MODE=\"'{$_POST['MODE']}'\"' $cfg");
exec("sed -i -e '/^ADMIN/c\\ADMIN=\"'{$_POST['ADMIN']}'\"' $cfg");
exec("sed -i -e '/^PASSWORD/c\\PASSWORD=\"'{$_POST['PASSWORD']}'\"' $cfg");
exec("sed -i -e '/^TIMER/c\\TIMER=\"'{$_POST['TIMER']}'\"' $cfg");
exec("sed -i -e '/^UPSKILL/c\\UPSKILL=\"'{$_POST['UPSKILL']}'\"' $cfg");

if ($_POST['SERVICE']=='enable') exec("/etc/rc.d/rc.nut start");
?>
15 changes: 15 additions & 0 deletions nut/source/usr/local/emhttp/plugins/nut/scripts/txt/go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###NUT-MARKER1###
#Start NUT on boot
while [[ ${LOOP:=30} -gt 1 && ! -d /mnt/user ]]
do
(( LOOP=LOOP-1 ))
echo "Waiting for Array to come online ($LOOP)"
sleep 5
done

run=$( grep -ic 'SERVICE="enable"' /boot/config/plugins/nut/nut.cfg )

if [ $run -eq 1 ]; then
/etc/rc.d/rc.nut start
fi
###NUT-MARKER2###
4 changes: 4 additions & 0 deletions nut/source/usr/local/emhttp/plugins/nut/scripts/txt/kill.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [ -x /usr/bin/nut_kill_inverter ]; then
. /usr/bin/nut_kill_inverter
fi

4 changes: 4 additions & 0 deletions nut/source/usr/local/emhttp/plugins/nut/scripts/txt/udev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

if [ -x /usr/bin/nut_restart_udev ]; then
. /usr/bin/nut_restart_udev
fi
Loading

0 comments on commit 789107d

Please sign in to comment.