[debian-edu-commits] debian-edu/ 01/64: Start on new package to shut down and wake up clients at night.

Mike Gabriel sunweaver at debian.org
Wed Oct 23 09:51:48 UTC 2013


This is an automated email from the git hooks/post-receive script.

sunweaver pushed a commit to branch master
in repository shutdown-at-night.

commit 4e686b82c9974002b0333a1d1c9e6b82edfe0a1b
Author: Petter Reinholdtsen <pere at hungry.com>
Date:   Sun Jun 8 14:39:42 2008 +0000

    Start on new package to shut down and wake up clients at night.
    
    git-svn-id: svn+ssh://svn.debian.org/svn/debian-edu/trunk/src/shutdown-at-night@41390 6e500793-9bee-0310-a5b0-9d0909bd054d
---
 Makefile          |   17 ++++++++++++++
 debian/changelog  |    5 +++++
 debian/compat     |    1 +
 debian/control    |   13 +++++++++++
 debian/copyright  |   10 +++++++++
 debian/cron.d     |    6 +++++
 debian/rules      |    7 ++++++
 shutdown-at-night |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 wakeupclients     |   36 ++++++++++++++++++++++++++++++
 9 files changed, 159 insertions(+)

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c5fff8d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+DESTDIR   =
+prefix    = /usr
+pkglibdir = $(prefix)/lib/shutdown-at-night
+sbindir   = $(prefix)/sbin
+sysconfdir= /etc
+
+INSTALL = install
+
+all:
+
+install:
+	$(INSTALL) -d $(DESTDIR)$(pkglibdir)/.
+	$(INSTALL) shutdown-at-night $(DESTDIR)$(pkglibdir)/.
+	$(INSTALL) wakeupclients $(DESTDIR)$(pkglibdir)/.
+
+distclean: clean
+clean:
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..cf6ec8c
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+shutdown-at-night (0.1) unstable; urgency=low
+
+  * Initial package.
+
+ -- Petter Reinholdtsen <pere at debian.org>  Sun,  8 Jun 2008 16:29:20 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..7ed6ff8
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..7d74b12
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,13 @@
+Source: shutdown-at-night
+Section: misc
+Priority: optional
+Maintainer: Petter Reinholdtsen <pere at debian.org>
+Standards-Version: 3.7.3
+Build-Depends: debhelper (>= 5), cdbs
+
+Package: shutdown-at-night
+Architecture: all
+Depends: ${misc:Depends}
+Description: System to shut down clients at night, and wake them up in the morning
+ Schedule shutdown in the evening, and uses nvram-wakeup or wakeonlan to wake
+ clients up in the morning.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..f10deb3
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,10 @@
+This package was debianized by the author Petter Reinholdtsen
+<pere at hungry.com> on Sun Jun  8 16:30:00 CEST 2008.
+
+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'.
diff --git a/debian/cron.d b/debian/cron.d
new file mode 100644
index 0000000..85909e3
--- /dev/null
+++ b/debian/cron.d
@@ -0,0 +1,6 @@
+# /etc/cron.d/shutdown-at-night
+
+SHELL=/bin/sh
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+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
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..471f555
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,7 @@
+#!/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)
diff --git a/shutdown-at-night b/shutdown-at-night
new file mode 100755
index 0000000..d791bca
--- /dev/null
+++ b/shutdown-at-night
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# 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?
+
+
+enabled_for_host() {
+    # Flag for now
+    if [ -f /etc/debian-edu/shutdown-at-night ] ; then
+        true
+    fi
+    false;
+}
+
+netgroup_lookup() {
+    innetgr -h $hostname host-shutdown-at-night
+}
+
+ldap_lookup() {
+    ldapsearch -LLL -w public \
+      -D "cn=svc.adbind,ou=servicekonti,ou=brukere,ou=i2-drift,dc=skolen,dc=local" \
+      -b "dc=skolen,dc=local" \
+      -x "(&(&(objectClass=user)(uidNumber=*))(samaccountname=slxtest0101))" unixhomedirectory
+}
+
+nvramwakeup() {
+# http://www.vdr-portal.de/board/thread.php?threadid=75582&sid=b7aced20e710aef12ffa56b5197fe168
+    wakeuptime=$1
+    when=$(date +%s -d 'tomorrow $wakeuptime')
+
+    # Make sure HW clock is correct, as it is used to decide when to wake up.
+    /etc/init.d/hwclock.sh stop
+    # Make sure /dev/nvram is available
+    modprobe nvram
+    # This require a supported motherboard
+    nvram-wakeup -s $when
+}
+
+wolwakeup() {
+    if=eth1
+    ethtool -s $if wol g
+}
+
+is_host_unused() {
+    # Logged in users, or ldm connection to a remote server
+    if [ "$(who)" ] ||  ps -efwww | egrep -q ' ssh .*LTSP_CLIEN[T]' ; then
+	false
+    fi
+    true
+}
+
+if enabled_for_host ; then
+    wakeuptime="07:00"
+    if is_host_unused; then
+	logger -t shutdown-at-night "Turning off unused client $hostname, turn on at $wakeuptime."
+	if type nvram-wakeup 2>/dev/null ; then
+	    nvramwakeup $wakeuptime
+	fi
+	shutdown -h now "Unused host being turned off for the night (cron)."
+    fi
+fi
diff --git a/wakeupclients b/wakeupclients
new file mode 100755
index 0000000..683e531
--- /dev/null
+++ b/wakeupclients
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $delay = 20;
+my $wakeuplist = "/etc/shutdown-at-night/clients";
+
+my %hwaddrs;
+
+# Locate hosts to wake up
+open(CLIENTS, "<", $wakeuplist) || exit 0;
+while (<CLIENTS>) {
+    chomp;
+    my ($ip, $hwaddr) = split(/\s+/);
+    $hwaddrs{$ip} = $hwaddr;
+}
+close(CLIENTS);
+
+# 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 (keys %hwaddrs) {
+    wakeup($ip, $hwaddrs{$ip});
+    sleep $delay;
+}
+
+# exit
+exit 0;
+
+sub wakeup {
+    my ($ip, $hwaddr) = @_;
+    `wakeonlan -i $ip $hwaddr`;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-edu/pkg-team/shutdown-at-night.git



More information about the debian-edu-commits mailing list