diff options
author | V'yacheslav Stetskevych <slava18@gmail.com> | 2010-06-17 02:52:26 -0500 |
---|---|---|
committer | Robby Workman <rworkman@slackbuilds.org> | 2010-06-17 14:42:26 -0500 |
commit | dbebec2717a01c40b62a2da7e53b677954eb47ca (patch) | |
tree | c42b7979842ff65d71e38dab04c6d724db803c61 | |
parent | da30a3f51b9d22e19fe9b692f446526b1c48491e (diff) |
system/nut: Added (Network UPS Tools)
Signed-off-by: Robby Workman <rworkman@slackbuilds.org>
-rw-r--r-- | system/nut/README | 8 | ||||
-rw-r--r-- | system/nut/README.SLACKWARE | 43 | ||||
-rw-r--r-- | system/nut/doinst.sh | 21 | ||||
-rw-r--r-- | system/nut/nut.SlackBuild | 153 | ||||
-rw-r--r-- | system/nut/nut.info | 10 | ||||
-rw-r--r-- | system/nut/nut_kill_inverter | 15 | ||||
-rw-r--r-- | system/nut/nut_restart_udev | 12 | ||||
-rw-r--r-- | system/nut/rc.ups | 73 | ||||
-rw-r--r-- | system/nut/slack-desc | 19 |
9 files changed, 354 insertions, 0 deletions
diff --git a/system/nut/README b/system/nut/README new file mode 100644 index 0000000000000..2d5a3b11d1eb5 --- /dev/null +++ b/system/nut/README @@ -0,0 +1,8 @@ +The Network UPS Tools is a collection of programs which provide a common +interface for monitoring and administering UPS hardware. It uses a +layered apporoach to connect all the components. Drivers are provided +for a wide assortment of equipment. The primary goal of the NUT project +is to provide reliable monitoring of UPS hardware and ensure safe +shutdowns of the systems which are connected. + +See README.SLACKWARE for configuration hints. diff --git a/system/nut/README.SLACKWARE b/system/nut/README.SLACKWARE new file mode 100644 index 0000000000000..a73275956ccf6 --- /dev/null +++ b/system/nut/README.SLACKWARE @@ -0,0 +1,43 @@ +README.SLACKWARE +Written by V'yacheslav Stetskevych <slava18 dont_spam_me gmail com> + +In order to configure Network UPS tools on Slackware you need to rename +or make copies of the sample config files in /etc/nut and edit them +to suit your needs. See documentation in /usr/doc/nut-* for reference. +As you make your new config files, don't forget to secure them: + chown root:nut /etc/nut/*.conf /etc/nut/*.users + chmod 640 /etc/nut/*.conf /etc/nut/*.users + +If you are using a serial-connected UPS, be sure to add the nut user to +the 'dialout' group: + usermod -a -G dialout nut + +A startup script /etc/rc.d/rc.ups is provided with this build. +You can add these lines to /etc/rc.d/rc.local to launch it on system start: + if [ -x /etc/rc.d/rc.ups ]; then + /etc/rc.d/rc.ups start + fi + +If you have more than one box sitting on the same UPS, you should only use +'start' on the one box that is connected to the device using a signal cable. +On the other boxes, start rc.ups with the 'start_upsmon' parameter to only +monitor the power status (client mode). Configure access permissions on the +server box accordingly. + +If you wish for your UPS to turn off it's power during an extended power outage +in order not to drain it's battery completely, you should make two simple edits +to the Slackware shutdown script /etc/rc.d/rc.6 near the end of it. +These are only needed on the server box, one that is connected to the UPS: +1) Insert after the rootfs has been remounted read-only: + if [ -x /usr/libexec/nut/nut_restart_udev ]; then + . /usr/libexec/nut/nut_restart_udev + fi +2) Insert after the genpowerd block and before the actual halt: + if [ -x /usr/libexec/nut/nut_kill_inverter ]; then + . /usr/libexec/nut/nut_kill_inverter + fi + +Don't forget to set your motherboard BIOS to automatically turn the machine on +when the power comes back. + +Have fun! diff --git a/system/nut/doinst.sh b/system/nut/doinst.sh new file mode 100644 index 0000000000000..ea64d25add047 --- /dev/null +++ b/system/nut/doinst.sh @@ -0,0 +1,21 @@ +config() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + # If there's no config file by that name, mv it over: + if [ ! -r $OLD ]; then + mv $NEW $OLD + elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then + # toss the redundant copy + rm $NEW + fi + # Otherwise, we leave the .new copy for the admin to consider... +} + +# Keep same perms on rc.ups.new: +if [ -e etc/rc.d/rc.ups ]; then + cp -a etc/rc.d/rc.ups etc/rc.d/rc.ups.new.incoming + cat etc/rc.d/rc.ups.new > etc/rc.d/rc.ups.new.incoming + mv etc/rc.d/rc.ups.new.incoming etc/rc.d/rc.ups.new +fi + +config etc/rc.d/rc.ups.new diff --git a/system/nut/nut.SlackBuild b/system/nut/nut.SlackBuild new file mode 100644 index 0000000000000..a6ed5b9952d2a --- /dev/null +++ b/system/nut/nut.SlackBuild @@ -0,0 +1,153 @@ +#!/bin/sh + +# Slackware build script for nut (Network UPS Tools) + +# Copyright 2010 V'yacheslav Stetskevych <slava18 dont_spam_me gmail com> +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +PRGNAM=nut +VERSION=${VERSION:-2.4.3} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} + +NUTUSER=${NUTUSER:-nut} +NUTGROUP=${NUTGROUP:-nut} + +# The user and group accounts have to be created manually. +# For slackbuilds.org, assigned nut uid/gid are 218/218. +# See http://slackbuilds.org/uid_gid.txt +if ! grep -q ^$NUTGROUP: /etc/group; then + echo " You must have a \"$NUTGROUP\" group to run this script." + echo " # groupadd -g 218 $NUTGROUP" + exit 1 +elif ! grep -q ^$NUTUSER: /etc/passwd; then + echo " You must have a \"$NUTUSER\" user to run this script." + echo " # useradd -u 218 -g $NUTGROUP -s /bin/false $NUTUSER" + exit 1 +fi + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i486 ;; + arm*) ARCH=arm ;; + # Unless $ARCH is already set, use uname -m for all other archs: + *) ARCH=$( uname -m ) ;; + esac +fi + +CWD=$(pwd) +TMP=${TMP:-/tmp/SBo} +PKG=$TMP/package-$PRGNAM +OUTPUT=${OUTPUT:-/tmp} + +if [ "$ARCH" = "i486" ]; then + SLKCFLAGS="-O2 -march=i486 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "i686" ]; then + SLKCFLAGS="-O2 -march=i686 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "x86_64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +else + SLKCFLAGS="-O2" + LIBDIRSUFFIX="" +fi + +set -e + +rm -rf $PKG +mkdir -p $TMP $PKG $OUTPUT +cd $TMP +rm -rf $PRGNAM-$VERSION +tar xvf $CWD/$PRGNAM-$VERSION.tar.gz +cd $PRGNAM-$VERSION +chown -R root:root . +find . \ + \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ + -exec chmod 755 {} \; -o \ + \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ + -exec chmod 644 {} \; + +CFLAGS="$SLKCFLAGS" \ +CXXFLAGS="$SLKCFLAGS" \ +./configure \ + --prefix=/usr \ + --libdir=/usr/lib${LIBDIRSUFFIX} \ + --sysconfdir=/etc/$PRGNAM \ + --localstatedir=/var \ + --datadir=/usr/share/nut \ + --mandir=/usr/man \ + --docdir=/usr/doc/$PRGNAM-$VERSION \ + --build=$ARCH-slackware-linux \ + --enable-strip \ + --with-dev \ + --with-serial \ + --with-usb \ + --with-hal \ + --with-snmp \ + --with-neon \ + --with-wrap \ + --with-ipv6 \ + --with-cgi\ + --with-cgipath=/var/www/cgi-bin/nut \ + --with-htmlpath=/var/www/htdocs/ups \ + --with-drvpath=/usr/libexec/nut \ + --with-statepath=/var/run/nut \ + --with-pidpath=/var/run/nut \ + --with-altpidpath=/var/run/nut \ + --with-user=nut \ + --with-group=nut +make +make install DESTDIR=$PKG + +find $PKG/usr/man -type f -exec gzip -9 {} \; +for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done + +# Install the bash_completion script +install -d $PKG/etc/bash_completion.d +install -m 755 scripts/misc/nut.bash_completion $PKG/etc/bash_completion.d/nut + +# Install the startup script +install -d $PKG/etc/rc.d +install -m 755 $CWD/rc.ups $PKG/etc/rc.d/rc.ups.new + +# Create the state and run dirs +install -d -o root -g $NUTGROUP -m 770 $PKG/var/state/ups +install -d -o $NUTUSER -g $NUTGROUP -m 770 $PKG/var/run/nut + +# Install shutdown helper files +install -m 755 $CWD/nut_restart_udev $CWD/nut_kill_inverter $PKG/usr/libexec/nut + +# Install documentation +mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION +cp -ar docs \ + AUTHORS COPYING ChangeLog INSTALL MAINTAINERS NEWS README UPGRADING \ + $PKG/usr/doc/$PRGNAM-$VERSION +rm $PKG/usr/doc/$PRGNAM-$VERSION/docs/Makefile* +cat $CWD/README.SLACKWARE > $PKG/usr/doc/$PRGNAM-$VERSION/README.SLACKWARE +cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild + +mkdir -p $PKG/install +cat $CWD/slack-desc > $PKG/install/slack-desc +cat $CWD/doinst.sh > $PKG/install/doinst.sh + +cd $PKG +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} diff --git a/system/nut/nut.info b/system/nut/nut.info new file mode 100644 index 0000000000000..88be96b964a75 --- /dev/null +++ b/system/nut/nut.info @@ -0,0 +1,10 @@ +PRGNAM="nut" +VERSION="2.4.3" +HOMEPAGE="http://www.networkupstools.org/" +DOWNLOAD="http://www.networkupstools.org/source/2.4/nut-2.4.3.tar.gz" +MD5SUM="6f893b61b07915e7a139324fa3f79121" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +MAINTAINER="V'yacheslav Stetskevych" +EMAIL="slava18@gmail.com" +APPROVED="rworkman" diff --git a/system/nut/nut_kill_inverter b/system/nut/nut_kill_inverter new file mode 100644 index 0000000000000..251a047df7b78 --- /dev/null +++ b/system/nut/nut_kill_inverter @@ -0,0 +1,15 @@ +#!/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/nut-upsdev@lists.alioth.debian.org/msg01099.html +# To be sourced after the genpowerd block and before the actual halt. + +if [ -f /etc/killpower ]; then + echo "----------------------------------------Shutting down UPS power!" + /etc/rc.d/rc.ups 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 diff --git a/system/nut/nut_restart_udev b/system/nut/nut_restart_udev new file mode 100644 index 0000000000000..d289c0f87a45e --- /dev/null +++ b/system/nut/nut_restart_udev @@ -0,0 +1,12 @@ +#!/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/nut-upsdev@lists.alioth.debian.org/msg01099.html +# To be sourced after the rootfs has been remounted read-only. + +if [ -f /etc/killpower ]; then +echo "Restarting udev to be able to shut the UPS inverter off..." +/etc/rc.d/rc.udev start +sleep 10 +fi diff --git a/system/nut/rc.ups b/system/nut/rc.ups new file mode 100644 index 0000000000000..0d9f4bc769183 --- /dev/null +++ b/system/nut/rc.ups @@ -0,0 +1,73 @@ +#!/bin/sh +# Slackware startup script for Network UPS Tools +# Copyright 2010 V'yacheslav Stetskevych + +# UPS drivers live here +DRIVERPATH=/usr/libexec/nut +export PATH=$DRIVERPATH:$PATH + +POWERDOWNFLAG=/etc/killpower +NUTUSER=nut +NUTGROUP=nut +UPSDCONF=/etc/ups/upsd.conf +UPSCONF=/etc/ups/ups.conf +UPSMONCONF=/etc/ups/upsmon.conf + +# Check for existense of the nut user and group +# For slackbuilds.org, assigned nut uid/gid are 218/218. +# See http://slackbuilds.org/uid_gid.txt +if ! grep -q ^$NUTGROUP: /etc/group; then + echo " You must have a \"$NUTGROUP\" group to run this script." + echo " # groupadd -g 218 $NUTGROUP" + exit 1 +elif ! grep -q ^$NUTUSER: /etc/passwd; then + echo " You must have a \"$NUTUSER\" user to run this script." + echo " # useradd -u 218 -g $NUTGROUP -s /bin/false $NUTUSER" + exit 1 +fi + +start_driver() { + upsdrvctl -u $NUTUSER start || exit 1 +} + +start_upsd() { + upsd -u $NUTUSER || exit 1 +} + +start_upsmon() { + upsmon -u $NUTUSER || exit 1 +} + +stop() { + echo "Stopping the UPS services... " + if pgrep upsd 2>&1 >/dev/null; then + upsd -c stop; fi + if pgrep upsmon 2>&1 >/dev/null; then + upsmon -c stop; fi + upsdrvctl stop +} + +case "$1" in + start) # starts everything (for a ups server box) + 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..." + upsdrvctl shutdown + ;; + reload) + echo "Reloading config files..." + upsd -c reload + upsmon -c reload + ;; + *) + echo "Usage: $0 {start|start_upsmon|stop|shutdown|reload}" +esac diff --git a/system/nut/slack-desc b/system/nut/slack-desc new file mode 100644 index 0000000000000..742cbb92ebccb --- /dev/null +++ b/system/nut/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. Line +# up the first '|' above the ':' following the base package name, and the '|' +# on the right side marks the last column you can put a character in. You must +# make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':'. + + |-----handy-ruler------------------------------------------------------| +nut: nut (Network UPS Tools) +nut: +nut: The Network UPS Tools is a collection of programs which provide a +nut: common interface for monitoring and administering UPS hardware. +nut: It uses a layered apporoach to connect all the components. Drivers +nut: are provided for a wide assortment of equipment. The primary goal of +nut: the NUT project is to provide reliable monitoring of UPS hardware +nut: and ensure safe shutdowns of the systems which are connected. +nut: +nut: Homepage: http://www.networkupstools.org +nut: |