May 2011 Archives
11-05-2011 13:59
apcupsd on Lenny
I am surprised it took me this long to work this out but the init script for apcupsd on my Proxmox VE server, which runs Debian Lenny, is broken. Two things it does wrong, 1) It does not create a pid file when it starts which is not terrible, but the stop procedure relies on their being a pid to stop it and gives up if there is not one. And 2) it does not pass the default /etc/apcupsd/apcupsd.conf file as the -f argument. So any changes you make to it are ignored in the running daemon. Add to that some other little scripting best practices are not followed, I have edited it and here it is. All working for me. Any feedback welcome:
#!/bin/sh ### BEGIN INIT INFO # Provides: apcupsd # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $local_fs # Should-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Starts apcupsd daemon # Description: apcupsd provides UPS power management for APC products. ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/sbin/apcupsd CONFIG=/etc/default/apcupsd NAME=apcupsd DESC="UPS power management" PID=/var/run/apcupsd.pid test -x $DAEMON || exit 0 test -e $CONFIG || exit 0 set -e . $CONFIG if [ $ISCONFIGURED = no ] then echo "Please check your configuration ISCONFIGURED in /etc/default/apcupsd" exit 0 fi case "$1" in start) echo -n "Starting $DESC: " rm -f /etc/apcupsd/powerfail if [ "$(pidof apcupsd)" == "" ] then start-stop-daemon --start --quiet --make-pidfile --pidfile $PID --exec $DAEMON -- -f /etc/apcupsd/apcupsd.conf echo "$NAME." else echo "" echo "A copy of the daemon is still running. If you just stopped it," echo "please wait about 5 seconds for it to shut down." exit 0 fi ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --oknodo --pidfile $PID|| echo "Not Running." rm -f $PID echo "$NAME." ;; restart|force-reload) $0 stop sleep 10 $0 start ;; status) $APCACCESS status ;; *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0
08-05-2011 00:12
I have used No-Ip (Maybe 10 years now). It is a Dynamic DNS service like DyDNS etc. It is good but it is limited how many clients you can have much like all others. So I have toyed with setting up something myself as I have a public Linux DNS server to receive the updated IP info. After trying a few methods that had varying success, I concluded that the following was the best method. DOMAIN would equal a domain name you have set aside for this purose.
- We setup passwordless ssh to the server. Do a search online with your favourite search engine as there is losts of tutorials already published for this.
-
On client side we run every 10mins
FILE="DOMAIN-ip" curl ifconfig.me/ip -o "$FILE" &>/dev/null scp -q "$FILE" dward.name: exit 0
-
Setup the zone to accept updates by adding the following to your named.conf for bind9:
allow-update { localhost;};
Restart bind9 -
On the server side run hourly cronjob or anything to your hearts content:
PHY="$(cat DOMAIN-ip)" TEMP="$(/bin/mktemp)" CMDS="$(/bin/mktemp)" CUR="$(host -t A DOMAIN localhost |grep DOMAIN|cut -d' ' -f4)" if [ ! "$CUR" == "$PHY" ] then TIME="$(date +%s)" cat > $CMDS <<EOF update delete DOMAIN A update add DOMAIN 1800 A $PHY send EOF /usr/bin/nsupdate $CMDS rm -f $CMDS rm -f $TEMP fi
Edit anything there to your needs of course.
References: https://www.debian-administration.org/users/JulienV/weblog/4
http://www.shakabuku.org/writing/dyndns.html