shutdown-at-night-git/0002755000000000000000000000000012243630614012114 5ustar shutdown-at-night-git/debian/0002755000000000000000000000000012243727477013354 5ustar shutdown-at-night-git/debian/rules0000755000000000000000000000030512232012164014402 0ustar #!/usr/bin/make -f include /usr/share/cdbs/1/class/makefile.mk include /usr/share/cdbs/1/rules/debhelper.mk DEB_MAKE_CLEAN_TARGET = clean DEB_MAKE_INSTALL_TARGET = install DESTDIR=$(DEB_DESTDIR) shutdown-at-night-git/debian/changelog0000644000000000000000000001402012243727417015213 0ustar shutdown-at-night (0.13) unstable; urgency=low [ Mike Gabriel ] * Package becomes team-maintained: Debian Edu Packaging Team. * debian/control: + Package migrated to Git. Update Vcs-*: fields and point to Git on Alioth. + Bump Standards: to 3.9.4. No changes necessary. + Improve LONG_DESCRIPTION. + Mention ACP wakeup functionality in LONG_DESCRIPTION. * debian/source/format: + Add file. Use format 1.0 to match capabilities of Debian Edu's dak. [ Petter Reinholdtsen ] * Rewrite logic checking if a host is unused to look for the KDM, Gnome or lightdm login screen to confirm the X sessions are unused (Closes: #729553). * Add depend on x11-utils for the xlsclients tool used to check unused X sessions. -- Petter Reinholdtsen Fri, 22 Nov 2013 20:22:08 +0100 shutdown-at-night (0.12) unstable; urgency=low [ Petter Reinholdtsen ] * Add support for using the ACPI RTC wakeup interface to wake up the machine (Closes: #717441). * Correct time zone calculations, try to ensure that the 07:00 wake up time is in the local time zone and not UTC. * Make sure to syslog that ACPI RTC is used to set wakeup time when it is used. [ Mike Gabriel ] * The -i option in the wakeonlan executable is only useful on networks with static ARP tables available. For networks using dynamic ARP tables (common with most switches), a broadcast address instead of a host IP should be given here. The wakeonlan default (255.255.255.255) is just fine for most network setups. So we omit the -i option completely when calling wakeonlan in the wakeupclients script. * debian/control: + Add myself to Uploaders: field. -- Mike Gabriel Wed, 23 Oct 2013 11:13:51 +0200 shutdown-at-night (0.11) unstable; urgency=low * Quiet down cron job to wake up client to not complain when fping notice they are unavailable. * Add support for extending the "busy" detection in shutdown-at-night by adding code to run hooks in /etc/shutdown-at-night/unused.d and /usr/lib/shutdown-at-night/unused.d. (Closes: #619950) -- Petter Reinholdtsen Mon, 15 Jul 2013 17:26:07 +0200 shutdown-at-night (0.10) unstable; urgency=low * Do not shut down if uptime is less then an hour. Based on patch and idea from Jonathan Jackson in BTS report #619950. * Fix typo in syslog message (ist -> is). * Update standards-version from 3.8.0 to 3.9.2. No changes needed. -- Petter Reinholdtsen Mon, 13 Feb 2012 23:42:41 +0100 shutdown-at-night (0.9) unstable; urgency=low * Sync with Ubuntu version 0.8ubuntu1: - Apply patch from Mike Gabriel clarifying reasons for host(s) not shutting down. (LP: #608616) (Closes: #636672) - Add ethtool as a dependency. (LP: #607021) (Closes: #636671) -- Petter Reinholdtsen Wed, 04 Jan 2012 14:43:31 +0100 shutdown-at-night (0.8) unstable; urgency=low * Make sure netgroup membership is checked using both the full and short hostname, to work with different netgroup styles (Solves Skolelinux bug #1435). -- Petter Reinholdtsen Wed, 03 Mar 2010 22:02:07 +0100 shutdown-at-night (0.7) unstable; urgency=low [ Petter Reinholdtsen ] * Rename netgroup used to enable shutdown-at-night, from host-shutdown-at-night to shutdown-at-night-hosts, to match the name structure used in Debian Edu. * Updated Standards-Version from 3.7.3 to 3.8.0. No changes needed. [ Holger Levsen ] * Add Vcs: headers to debian/control. -- Petter Reinholdtsen Wed, 16 Jul 2008 14:34:35 +0200 shutdown-at-night (0.6) unstable; urgency=low * Change GPL file reference in copyright to use GPL-2 instead of GPL, to avoid surprises when the content of the GPL file changes between Debian versions. -- Petter Reinholdtsen Sun, 22 Jun 2008 00:20:25 +0200 shutdown-at-night (0.5) unstable; urgency=low * Make sure to not give the same wakeup time to all BIOSes, to avoid machines with good hardware clock to wake up at the same time and thus reduce the chance that a fuse breaks. * Add comment in Makefile explaining why the internal scripts are in /usr/lib/ and not /usr/share/. * Improve copyright file on request from the Debian ftpmasters. * Adjust return value from nvramwakeup() in shutdown-at-night, to return success if the BIOS wakeup time was updated. -- Petter Reinholdtsen Sun, 15 Jun 2008 19:28:09 +0200 shutdown-at-night (0.4) unstable; urgency=low * Make sure the /etc/shutdown-at-night/ directory is part of the package. * Change shutdown-at-night to abort the shutdown if wake-on-lan could not be enabled. * Add 'cron | fcron' as dependency, to make sure the cron jobs run as they should. * Improve setup instructions in the README. -- Petter Reinholdtsen Sun, 15 Jun 2008 00:40:36 +0200 shutdown-at-night (0.3) unstable; urgency=low * Convert wakeupclients to use syslog. * Add suggests on sitesummary (>= 0.0.41) to suggest a version that can generate the client list automatically. * Add support in wakeupclients to run a script /etc/shutdown-at-night/clients-generator to extract the clients to wake up dynamically. * Add ${perl:Depends} to package dependencies. -- Petter Reinholdtsen Fri, 13 Jun 2008 11:06:29 +0200 shutdown-at-night (0.2) unstable; urgency=low * Add server side cron job to start waking up clients Monday-Friday at 06:30. * Change wakeupclients to log progress, and to check if a client is up before trying to wake it. * Change wakeupclients to use fping to check for alive clints, to speed up the script. Reduce sleep time between wakeups to 5 seconds. * Correct typos in the shutdown-at-night script. -- Petter Reinholdtsen Fri, 13 Jun 2008 08:58:00 +0200 shutdown-at-night (0.1) unstable; urgency=low * Initial package. -- Petter Reinholdtsen Sun, 8 Jun 2008 18:18:53 +0200 shutdown-at-night-git/debian/cron.d0000644000000000000000000000063212232012164014433 0ustar # /etc/cron.d/shutdown-at-night SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin # Shutdown clients 0 16,17,18,19,20,21,22,23,0,1,2,3,4,5,6 * * * root test -x /usr/lib/shutdown-at-night/shutdown-at-night && /usr/lib/shutdown-at-night/shutdown-at-night # Try to wake up clients on work days 30 6 * * 1,2,3,4,5 root test -x /usr/lib/shutdown-at-night/wakeupclients && /usr/lib/shutdown-at-night/wakeupclients shutdown-at-night-git/debian/compat0000644000000000000000000000000212232012164014522 0ustar 5 shutdown-at-night-git/debian/control0000644000000000000000000000271212243345710014741 0ustar Source: shutdown-at-night Section: misc Priority: optional Maintainer: Debian Edu Packaging Team Uploaders: Petter Reinholdtsen , Mike Gabriel , Standards-Version: 3.9.4 Build-Depends: debhelper (>= 5), cdbs Vcs-Git: git://anonscm.debian.org/debian-edu/pkg-team/shutdown-at-night.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=debian-edu/pkg-team/shutdown-at-night.git Package: shutdown-at-night Architecture: all Depends: ${misc:Depends}, ${perl:Depends}, cron | fcron, wakeonlan, ng-utils, fping, ethtool, x11-utils Recommends: nvram-wakeup Suggests: sitesummary (>= 0.0.41) Description: System to shut down clients at night, and wake them in the morning With this tool you can schedule regular shutdowns of workstations in the evening, and also wake them up every morning, using either nvram-wakeup, ACPI wakeup or wake-on-lan. . For the wake-on-lan wake-up sequence you need one awake machine on your local network / subnet. This can be a server machine or a client machine that got just previously woken up by nvram-wakeup. . The shutdown sequence will be initiated hourly after 4pm via a CRON job. However, only machines that appear inactive / unused will be shut down. Machines that are currently in use will remain up and running. . The Shutdown-at-Night tool can be activated via a config file or via membership in a NIS netgroup called shutdown-at-night-hosts. shutdown-at-night-git/debian/source/0002755000000000000000000000000012232012164014626 5ustar shutdown-at-night-git/debian/source/format0000644000000000000000000000000312232012164016030 0ustar 1.0shutdown-at-night-git/debian/copyright0000644000000000000000000000122712232012164015261 0ustar This package was debianized by the author Petter Reinholdtsen on Sun Jun 8 16:30:00 CEST 2008. It was downloaded using svn from: svn://svn.debian.org/debian-edu/trunk/src/shutdown-at-night Upstream Author: Petter Reinholdtsen Copyright: 2008 Petter Reinholdtsen This program and these scripts are free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. On Debian GNU/Linux systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL-2'. shutdown-at-night-git/README0000644000000000000000000000462712232012164012773 0ustar Saving power by turning off clients at night ============================================ It is possible to save power by turning off clients at night, and turn them automatically on in the morning. There are some considerations to make when doing this: - The clients should not be shut down when someone is using them. This is done by checking the output from 'who', and as a special case, checking for the LDM ssh connection command to work with LTSP thin clients. - To avoid breaking fuses, it is a good idea to make sure all clients do not start at the same time. - There are two different methods available to wake up clients. One uses a BIOS feature and require a working and correct hardware clock, as well as a motherboard and BIOS version supported by nvram-wakeup, The other require a server with knowledge about all the clients to wake up and for all the clients to have support for wake-on-lan. How to set it up ---------------- On clients that should turn off at night, touch /etc/shutdown-at-night/shutdown-at-night, or add the hostname (ie the output from 'uname -n' or 'hostname -s' on the client) to the netgroup "shutdown-at-night-hosts". The clients might need to have wake-on-lan configured in the BIOS. It is also important that the switches and routers used between the wake-on-lan server and the clients will pass the WOL packages to the clients even if the clients are turned off. Some switches fail to pass on packages to clients that are missing in the ARP table on the switch, and this block the WOL packages. To enable wake-on-lan on the server, add the clients to /etc/shutdown-at-night/clients, with one line per client, IP address first, and MAC address (ethernet address) next, with space between them, or create a script /etc/shutdown-at-night/clients-generator to generate the list of clients on the fly. Here is an example /etc/shutdown-at-night/clients-generator for use with sitesummary: #!/bin/sh PATH=/usr/sbin:$PATH export PATH sitesummary-nodes -w An alternative if the netgroup is used to activate shutdown-at-night on clients is this script using the netgroup tool from the ng-utils package: #!/bin/sh PATH=/usr/sbin:$PATH export PATH netgroup -h shutdown-at-night-hosts License ------- This package is licensed using GNU General Public License v2 or later. Bugreporting ------------ Report issues to the debian-edu@lists.debian.org mailing list. shutdown-at-night-git/Makefile0000644000000000000000000000107412232012164013544 0ustar DESTDIR = prefix = /usr sbindir = $(prefix)/sbin sysconfdir= /etc pkgsysconfdir= $(sysconfdir)/shutdown-at-night # Install scripts in lib/, to make it trivial to rewrite the internal tools # in any language, even compiled ones, without having to update the path used # by the callers. pkglibdir = $(prefix)/lib/shutdown-at-night INSTALL = install all: install: $(INSTALL) -d $(DESTDIR)$(pkglibdir)/. $(DESTDIR)$(pkgsysconfdir)/. $(INSTALL) shutdown-at-night $(DESTDIR)$(pkglibdir)/. $(INSTALL) wakeupclients $(DESTDIR)$(pkglibdir)/. distclean: clean clean: shutdown-at-night-git/shutdown-at-night0000755000000000000000000001166312243346103015430 0ustar #!/bin/bash # Using /bin/bash and not /bin/sh to get a shell with support for random number # generation. # # Automatically turn off computers at night, defined as 16:00 - 06:00. # Should schedule wakeup in the morning. # How do we decide if it should be enabled for this host? Netgroup # membership? LDAP search? Flag file? #set -e wakeuptime="07:00" hostname="$(uname -n)" netgroupname="shutdown-at-night-hosts" # Hook directories to allow custom code to detect if a machine is used # or not. unuseddlist="/etc/shutdown-at-night/unused.d /usr/lib/shutdown-at-night/unused.d" in_netgroup() { # Try both long and short name for h in "$(uname -n)" "$(hostname -s)" ; do if innetgr -h "$h" "$netgroupname" ; then return 0 fi done return 1 } enabled_for_host() { # Flag for now if [ -f /etc/shutdown-at-night/shutdown-at-night ] || in_netgroup; then return 0 fi return 1 } # Take wakeup hour:minute in local time zone and return wake up time # in seconds since EPOC UTC, radomized around the target wakeup time. whentowakeup() { wakeuptime=$1 # Spread the BIOS wakeup time across a 20 minute period, to avoid # all of them waking up at the same time, killing a fuse. # Convert local target time in seconds since EPOC UTC targettime=$(date +%s -d "tomorrow $wakeuptime $(date +%z)") echo $(( $targettime - 600 + $RANDOM % 1200)) } nvramwakeup() { # http://www.vdr-portal.de/board/thread.php?threadid=75582&sid=b7aced20e710aef12ffa56b5197fe168 wakeuptime=$1 when=$(whentowakeup $wakeuptime) # Make sure HW clock is correct, as it is used to decide when to # wake up. /etc/init.d/hwclock.sh stop > /dev/null # Make sure /dev/nvram is available modprobe nvram # This require a supported motherboard if nvram-wakeup -s $when > /dev/null ; then logger -t shutdown-at-night "scheduled $hostname to turn itself on at $wakeuptime using nvram-wakeup." return 0 else return 1 fi } # This method might not work if the hardware clock is updated during # shutdown. Changing /etc/default/hwclock to list HWCLOCKACCESS=yes # to disable it. # Based on acpiwakeup() { wakeuptime="$1" if [ -e /sys/class/rtc/rtc0/wakealarm ] ; then when=$(whentowakeup $wakeuptime) # First reset alarm echo 0 > /sys/class/rtc/rtc0/wakealarm # Next, set it to our selected time echo $when > /sys/class/rtc/rtc0/wakealarm logger -t shutdown-at-night "scheduled $hostname to turn itself on at $wakeuptime using /sys/class/rtc/rtc0/wakealarm." return 0 else return 1 fi } prepare_wakeonlan() { interface="$(/sbin/route -n | awk '/^0\.0\.0\.0 / { print $8 }')" ethtool -s $interface wol g } # Return true if local user is logged in, false otherwise is_local_user() { if [ "$(who)" ] ; then return 0 else return 1 fi } # Return true if ldm login is active is_active_ldm_session() { if ps -efwww | egrep -q ' ssh .*LTSP_CLIEN[T]' ; then return 0 else return 1 fi } # Return false if X session is confirmed unused (ie login screen is # shown). If not sure, claim it is used to be safe. is_xsession_used() { for s in \ /var/run/gdm3/auth-for-Debian-gdm-*/database \ /var/lib/lightdm/.Xauthority \ /var/run/xauth/* \ /run/xauth/*; do if [ -e "$s" ] ; then if XAUTHORITY="$s" DISPLAY=:0 xlsclients | egrep -q 'kdmgreet|lightdm-gtk-greeter|razor-lightdm-greeter|lightdm-kde-greeter|gdm-simple-greeter' ; then return 1 fi fi done return 0 } is_host_unused() { # Logged in users, or ldm connection to a remote server if is_xsession_used || is_local_user || is_active_ldm_session; then return 1 fi # Uptime is less than one hour if (( $(cat /proc/uptime | awk '{print int($1)}') < 3600 )) ; then return 1 fi for dir in $unuseddlist ; do if [ -d $dir ] ; then for f in $dir/* ; do if [ -x $f ] && ! $f ; then return 1 fi done fi done return 0 } fatal() { logger -t shutdown-at-night "$1" exit 1 } if enabled_for_host ; then if is_host_unused; then logger -t shutdown-at-night "turning off unused client $hostname." if type nvram-wakeup >/dev/null 2>&1 ; then nvramwakeup $wakeuptime fi acpiwakeup $waketime prepare_wakeonlan || fatal "unable to enable wake-on-lan - aborting shutdown." shutdown -h 5 "Unused host being turned off for the night (cron)." < /dev/null > /dev/null 2>&1 & else logger -t shutdown-at-night "client $hostname is in use; shutdown sequence will NOT be initiated." fi else logger -t shutdown-at-night "shutdown-at-night is not enabled for client $hostname." fi shutdown-at-night-git/wakeupclients0000755000000000000000000000306512232012164014712 0ustar #!/usr/bin/perl use strict; use warnings; use Sys::Syslog qw(openlog syslog closelog LOG_NOTICE); my $delay = 5; my $wakeuplist = "/etc/shutdown-at-night/clients"; my $wakeupgenerator = "/etc/shutdown-at-night/clients-generator"; my %hwaddrs; sub load_clients { my $fh = shift; while (<$fh>) { chomp; my ($ip, $hwaddr) = split(/\s+/); $hwaddrs{$ip} = $hwaddr; } } # Locate hosts to wake up, from file if ( -f $wakeuplist ) { if (open(CLIENTS, "<", $wakeuplist)) { load_clients(*CLIENTS); close(CLIENTS); } } # Or using a dynamic script if ( -x $wakeupgenerator ) { if (open(CLIENTS, "$wakeupgenerator |")) { load_clients(*CLIENTS); close(CLIENTS); } } my %alive; map { $alive{$_} = 1; } get_alive_list(keys %hwaddrs); # Calculate when to start, assuming 20-30 seconds between each host #my $duration = $delay * scalar keys %hwaddrs; #my $allup = time(); # Start sending wakeup calls for my $ip (sort keys %hwaddrs) { if (! defined $alive{$ip}) { logmsg("sending wake-on-lan to $ip [$hwaddrs{$ip}]"); wakeup($ip, $hwaddrs{$ip}); sleep $delay; } else { logmsg("not sending wake-on-lan to already awake $ip [$hwaddrs{$ip}]"); } } # exit exit 0; sub wakeup { my ($ip, $hwaddr) = @_; `wakeonlan $hwaddr`; } sub get_alive_list { my @addresses = @_; return split(/\s+/, `fping -a @addresses 2>/dev/null`); } sub logmsg { my $msg = shift; openlog("wakeupclients", undef, 'user'); syslog(LOG_NOTICE, "%s", $msg); closelog; }