[debian-edu-commits] debian-edu/ 05/07: shutdown-at-night: Evaluate the newly supported NIS netgroups shutdown-at-night-wakeup-hosts and shutdown-at-night-wakeup-hosts-blacklist and only prepare the NVRAM/RTC based host wake-up if configured accordingly via NIS netgroups.

Mike Gabriel sunweaver at debian.org
Tue Feb 23 20:51:48 UTC 2016


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 6ceafdee3cf545f08ca2aa84355125ec2b872073
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Tue Feb 23 21:46:35 2016 +0100

    shutdown-at-night: Evaluate the newly supported NIS netgroups shutdown-at-night-wakeup-hosts and shutdown-at-night-wakeup-hosts-blacklist and only prepare the NVRAM/RTC based host wake-up if configured accordingly via NIS netgroups.
---
 debian/changelog  |  4 ++++
 shutdown-at-night | 65 +++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 95583a5..6962924 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,10 @@ shutdown-at-night (0.17) UNRELEASED; urgency=medium
   * README: Document the blockage files for system wake-ups.
   * wakeupclients: Don't send alive pings to an empty address list. Prevents
     the script from hanging indefinitely when calling the fping command.
+  * shutdown-at-night: Evaluate the newly supported NIS netgroups
+    shutdown-at-night-wakeup-hosts and shutdown-at-night-wakeup-hosts-blacklist
+    and only prepare the NVRAM/RTC based host wake-up if configured accordingly
+    via NIS netgroups.
 
  -- Wolfgang Schweer <wschweer at arcor.de>  Sat, 17 Oct 2015 19:25:29 +0200
 
diff --git a/shutdown-at-night b/shutdown-at-night
index b08390f..ae186b4 100755
--- a/shutdown-at-night
+++ b/shutdown-at-night
@@ -38,28 +38,66 @@ fi
 wakeuptime="$WAKEUPTIME"
 
 hostname="$(uname -n)"
-netgroupname="shutdown-at-night-hosts"
+netgroupname_wakeup="shutdown-at-night-wakeup-hosts"
+netgroupname_nowakeup="shutdown-at-night-wakeup-hosts-blacklist"
+netgroupname_shutdown="shutdown-at-night-hosts"
 netgroupname_noshutdown="shutdown-at-night-hosts-blacklist"
 
+netgroup_wakeup_found=$(netgroup -h $netgroupname_wakeup 1>/dev/null 2>/dev/null && printf "FOUND" || printf "NOT-FOUND");
+
 # 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() {
+in_nowakeup_netgroup() {
+    # Try both long and short name
+    for h in "$(uname -n)" "$(hostname -s)" ; do
+        if innetgr -h "$h" "$netgroupname_nowakeup" ; then
+            return 0
+        fi
+    done
+    return 1
+}
+
+in_wakeup_netgroup() {
+    # Try both long and short name
+    for h in "$(uname -n)" "$(hostname -s)" ; do
+        if innetgr -h "$h" "$netgroupname_wakeup" ; then
+            return 0
+        fi
+    done
+    return 1
+}
+
+in_shutdown_netgroup() {
     # Try both long and short name
     for h in "$(uname -n)" "$(hostname -s)" ; do
         if innetgr -h "$h" "$netgroupname_noshutdown"; then
             return 1
-        elif innetgr -h "$h" "$netgroupname" ; then
+        elif innetgr -h "$h" "$netgroupname_shutdown" ; then
             return 0
         fi
     done
     return 1
 }
 
-enabled_for_host() {
+wakeup_enabled_for_host() {
+    # Flag for now
+    if [ -f /etc/shutdown-at-night/shutdown-at-night ]; then
+        return 0
+    elif in_nowakeup_netgroup; then
+        return 1
+    elif in_wakeup_netgroup; then
+        return 0
+    elif [ "x$netgroup_wakeup_found" != "xFOUND" ] && (! in_nowakeup_netgroup ) && in_shutdown_netgroup; then
+        return 0
+    fi
+    return 1
+}
+
+shutdown_enabled_for_host() {
     # Flag for now
-    if [ -f /etc/shutdown-at-night/shutdown-at-night ] || in_netgroup; then
+    if [ -f /etc/shutdown-at-night/shutdown-at-night ] || in_shutdown_netgroup; then
         return 0
     fi
     return 1
@@ -186,16 +224,19 @@ fatal() {
     exit 1
 }
 
-if enabled_for_host ; then
+if shutdown_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 ] && [ "$NVRAM_WAKE_ENABLED" = yes ] ; then
-            nvramwakeup $wakeuptime
-        fi
-        if [ "$ACPI_WAKE_ENABLED" = yes ] ; then
-            acpiwakeup $wakeuptime
+        if wakeup_enabled_for_host; then
+            logger -t shutdown-at-night "Preparing client $hostname for waking up in the morning."
+            if [ type nvram-wakeup >/dev/null 2>&1 ] && [ "$NVRAM_WAKE_ENABLED" = yes ] ; then
+                nvramwakeup $wakeuptime
+            fi
+            if [ "$ACPI_WAKE_ENABLED" = yes ] ; then
+                acpiwakeup $wakeuptime
+            fi
+            prepare_wakeonlan || fatal "unable to enable wake-on-lan - aborting shutdown."
         fi
-        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."

-- 
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