Nightly Shutdowns
To conserve electricity at home, all workstations and laptops are scheduled to shutdown nightly. With some modifications I adopted this routine to Linux workstations and laptops at work.
There are four shell scripts:
/usr/local/bin/nightly-shutdown-check
/usr/local/bin/nightly-shutdown-toggle
/usr/local/sbin/nightly-shutdown
/usr/local/sbin/nightly-shutdown-restore
There is one /usr/local/share/applications/nightly-shutdown-toggle.desktop
file to provide users a convenient pointy-clicky way of not using a terminal window:
There is one /etc/cron.d/nightly-shutdown
cron job.
There is one /etc/default/nightly
configuration file.
The shutdowns are performed through the nightly-shutdown
script. The script can be used manually, but is expected to run through the cron job. The script sources the variables stored in /etc/default/nightly
.
The cron job runs every hour. When an actual shutdown occurs is determined by the variables stored in /etc/default/nightly
. At home systems are scheduled to shutdown at 11:14 PM. At work the systems shutdown at 8:20 PM.
The nightly-shutdown script creates a status file /tmp/nightly-shutdown
that contains either Enabled
or Disabled
. Through the script, the status file is tagged chgrp users
and chmod 666
to allow all users to modify the file contents. The status file is created on boot from rc.local
through the nightly-shutdown-check
script.
Presumed is all affected systems are scheduled to shutdown nightly. The nightly shutdowns can be disabled two ways. One is to manually edit the cron job and comment out the execution time. This is a sledge hammer method and requires root privileges. The second method is through the nightly-shutdown-toggle
script. This script toggles the value stored in /tmp/nightly-shutdown
and creates an override file /tmp/no_shutdown
. The override file contains either true
or false
.
The nightly-shutdown-check
returns the value stored in /tmp/nightly-shutdown
. The script can be run manually but is intended to be run by Conky. The returned value is then displayed in the Conky display.
To avoid users forgetting the cron job being disabled, the nightly-shutdown-restore
script is run from rc.local
. The script removes the hash symbol from the cron job.
Why the layered approach?
Mostly because of the challenge of how to determine whether a computer is actively being used. Exactly what determines activity? Keyboard and mouse activity are traditional methods of detection, but prone to error. For example, reading involves no keyboard or mouse activity until desiring to scroll the page. Watching a video involves no human interaction. Sometimes users walk away from a computer for a while. Sometimes users enable tasks that require no user interaction. For example, running an email client.
At work we use laptops in the field to service customers. During summer months some overtime hours is common. Occasionally the overtime is quite late. In such an event, a forced laptop shutdown would be frustrating and counter productive. Powering on the laptop would only meet the same fate an hour later because of the cron job.
The /usr/local/share/applications/nightly-shutdown-toggle.desktop
file creates a menu entry. The desktop file runs the /usr/local/bin/nightly-shutdown-toggle
script. Users can toggle off the nightly shutdown without a terminal window. The Conky display provides immediate feedback of the nightly shutdown status.
As /tmp
is a tmpfs file system, both the /tmp/nightly-shutdown
and override file /tmp/no_shutdown
are deleted on reboot or shutdown. On boot only the /tmp/nightly-shutdown
is recreated.
Why bother at all with laptops? We configure the workstations to automatically update packages. We cannot afford any such interruptions when working in the field. We also cannot know when a field laptop will be powered down or placed into suspend mode. Such actions would interrupt any background update. Because of these concerns and requirements, we connect the laptops weekly to the office subnet. I remotely update the laptops manually. We don’t want the laptops running all night for no other reason. Hence, having the laptops shutdown automatically is preferred.
Posted: Usability Tagged: General
Category:Next: Magnificent Desolation
Previous: LUKS Encryption