This page is specific to Ubuntu versions 8.04 / 8.10 / 9.04

If you find this information applicable to additional versions/releases, please edit this page and modify this header to reflect that. Please also include any necessary modifications for this information to apply to the additional versions.


Introduction

This page is dedicated to configuring automated thin-client shutdown. This is a useful feature for environments such as schools (and anywhere that is concerned about energy consumption), as it will ensure all clients are shut down at a specified time, saving power (which = $$$ !)

Warning

Using /sbin/halt to shutdown terminal station does not involve proper closing X-session (as it is performed from LDM menu), and leave all related processes on server alive (ssh session, kde daemons, etc).

Installing cron in the chroot

  • Follow the instructions in ChrootCronjobs to be able to configure cron jobs in client chroot sessions easily via lts.conf. (Thanks to P. Baco at Carlit.net for this script!)

  • Edit your lts.conf file on the server to configure cron jobs for your LTSP clients. Here's an example:

# This one will halt client(s) at 20:30 from Monday to Friday
CRONTAB_01 = "30 20 * * 1-5 /sbin/halt"
  • Reboot your thin clients for the cron jobs to take effect.

Using a script to warn users of pending shutdown

Here are instructions on using a little script I wrote (with the help of the above script) which will warn users that the LTSP client will shut down in 5 minutes.

  • Install zenity in the chroot:

sudo chroot /opt/ltsp/i386 apt-get install zenity
  • Copy the following script, called shutdownwarning, to /opt/ltsp/i386/etc/ltsp:

shutdownwarning:

 #!/bin/bash
 #
 # Created 2009/10/09 Jordan Erickson (LNS)
 #
 # This script warns any logged-in LTSP user that the client will
 # shut down in 5 minutes (ala a cronjob) and gives them the chance
 # to disable it.
 #

DISPLAY=$(ps -ef | grep -v awk | awk '/Xauthority/ { print $NF }')
export DISPLAY

# Ask the user what to do
main() {
   zenity --question --title="Shutdown Warning" --text="This computer will automatically shut down in 5 minutes. Press [OK] to save your work and log out, or [Cancel] to disable automatic shutdown and keep working." 

      if [ "$?" = 0 ]; then
         # Do nothing by default - shutdown is enabled already. Inform the user.
         zenity --info --title="Shutdown ENABLED" --text="Shutdown will occur. Please save your work and log out immediately!"

      elif [ "$?" = 1 ]; then
         # Remove the crontab entry for shutting the system down
         # See /opt/ltsp/i386/etc/ltsp/crontab.sh - Thanks to P. Baco @ Carlit.net !!
         TMPFILE=/tmp/crontab.tmp
         TMPFILE2=/tmp/crontab.tmp2
         # Re-create the crontab.tmp file via getltscfg and CRONTAB_NN environment vars
         for i in 01 02 03 04 05 06 07 08 09 10
         do
            JOB=$(getltscfg CRONTAB_$i)
            if [ -n "$JOB" ]; then
               echo >> $TMPFILE
               echo "# Found in CRONTAB_$i" >> $TMPFILE
               echo "$JOB" >> $TMPFILE
            fi
         done
         # Pick out the crontab entry to halt the system - looks for /sbin/halt only...
         if [ -f $TMPFILE ]; then
            grep -v "/sbin/halt" $TMPFILE > $TMPFILE2
            # Recreate crontab without shutdown job
            crontab $TMPFILE2
         fi
         rm -f $TMPFILE $TMPFILE2

         # Tell the user what just happened
         zenity --info --title="Shutdown DISABLED" --text="Shutdown has been disabled. Please log out and shut down when you are finished. Thank you!"

      fi

}

main

# EOF
  • Chmod your script:

sudo chmod 755 /opt/ltsp/i386/etc/ltsp/shutdownwarning
  • Rebuild your chroot image:

sudo ltsp-update-image
  • Add this as a CRONTAB_NN entry in lts.conf, 5 minutes before the cronjob to shut the system down:

lts.conf:

CRONTAB_01 = "25 20  * * 1-5 /etc/ltsp/shutdownwarning"

Notes

  • You might now want to follow the instructions for Installing an NTP server so your thin-client time is in sync with the server time.

  • If you like automated shut-down, you'll probably like Automated thin-client startup!

  • In addition to this, there is a software project called evanescent which can shut systems down after a configurable amount of idle (I.E. no user input from keyboard/mouse) time.


CategoryLtsp

UbuntuLTSP/AutomatedTCShutodwn (last edited 2010-02-15 08:50:24 by svg)