个人工具

UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn

来自Ubuntu中文

Wikibot讨论 | 贡献2009年5月18日 (一) 17:59的版本 (创建新页面为 '{{From|https://help.ubuntu.com/community/UbuntuLTSP/AutomatedTCShutodwn}} {{Languages|UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn}} {|border="1" cellspacing="0" |This page is spec...')

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索
This page is specific to Ubuntu versions 8.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.


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 = $$$ !) This method has not been tested extensively yet, so please, if you have implemented this method, append your results here so we can make sure it works correctly and everything is covered. Thanks!


  • First, we need to tell the LTSP server chroot to not start/handle daemons when installed. This will prevent the server from (re)starting its own cron process when you install it in the client chroot (which will have many ill effects such as running cron jobs you implemented in the chroot, including, in this case, shutting down!)
export LTSP_HANDLE_DAEMONS="false"
  • Now, if you haven't already, follow the instructions to unlock|the chroot 'root' account. Unlocking the chroot root account is necessary for cron jobs to run successfully.
  • Now, let's install cron in our chroot (i386 chroot is assumed, modify for your specific setup):
chroot /opt/ltsp/i386 apt-get install cron

Note: Not using 'sudo' in this example because when you do, it doesn't honor the LTSP_HANDLE_DAEMONS var we set earlier for some reason. Can someone tell me why?

  • Now let's edit our chroot /etc/crontab file, to specify a time to "halt" our cilents (3:30pm Monday-Friday is assumed in this example - again, modify it for your setup):
sudo vim /opt/ltsp/i386/etc/crontab

/opt/ltsp/i386/etc/crontab:

30 15    * * 1-5   root    /sbin/halt
  • Now update your chroot NBD image:
ltsp-update-image
  • Reboot your thin-clients, and enjoy automated, configurable shutdown!

Managing thin client crontab from lts.conf

Once crontab installed in the image (see above), the following script lets you create the thin client(s) crontab from lts.conf variables called "CRONTAB_01" to "CRONTAB_10" (in the [default] section or any specific thin client section). This technique lets you:

  • modify shutdown time (or any crontab command) without rebuilding the image.
  • set different crontab tasks for different thin clients.

First, create this script as /opt/ltsp/i386/etc/ltsp/crontab:

#!/bin/bash
#
# P. Baco - Carlit.net
# Crontab LTSP script
#
# This script, when started from lts.conf "RCFILE_XX = /etc/ltsp/crontab"
# will add up to 10 tasks to the thin client's root crontab.
# Tasks are defined as regular crontab lines in lts.conf variables
# "CRONTAB_01" to "CRONTAB_10"
# ex:
# CRONTAB_01 = "30 20 * * 1-5 /sbin/halt"
# will halt the thin client at 20:30 monday to friday
#
# Note: Requires crontab to be installed in the chrooted image
#
TMPFILE=/tmp/crontab.tmp

rm -f $TMPFILE
for i in 01 02 03 04 05 06 07 08 09 10
do
  JOB=$(getltscfg CRONTAB_$i)
  if [ -n "$JOB" ]; then
    echo "$JOB" >> $TMPFILE
  fi
done
if [ -f $TMPFILE ]; then
  crontab $TMPFILE
fi
rm $TMPFILE

Chmod the script:

chmod 755 /opt/ltsp/i386/etc/ltsp/crontab

Rebuild your image.

ltsp-update-image

Then edit /var/lib/tftpboot/ltsp/i386/lts.conf:

# Start the crontab creation script
RCFILE_02 = /etc/ltsp/crontab

# Crontab lines for the thin client root crontab
# First one will halt ALL the thin clients at 20:30 from monday to friday
CRONTAB_01 = "30 20 * * 1-5 /sbin/halt"

[192.168.100.200]
# This one will pop up a zenity info window at 20:15
# on the thin client 192.168.100.200 display
# (make sure zenity is installed in the chroot image)
CRONTAB_02 = "15 20 * * 1-5 /usr/bin/zenity --info -text=\"Time to leave!\""

Reboot the thin client(s). Done.

Notes

***** UNDER CONSTRUCTION BELOW THIS LINE - MOVE ALONG, NOTHING TO SEE HERE *****

Creating a flexible automated environment

This method allows for removing/modifying when stations shut down. You need to have sshd running in the client chroot to do this.

  • Make a wrapper script for calling crontab, used in lts.conf:

/opt/ltsp/arch/etc/ltsp/halt_via_cron.sh:

    #!/bin/bash
    # 
/usr/bin/crontab /etc/ltsp/root.crontab
  • Make the script executable:
chmod 770 /opt/ltsp/arch/etc/ltsp/halt_via_cron.sh
  • Make a crontab file for root (this example halts the system at 3:30pm every weekday):

/opt/ltsp/i386/etc/ltsp/root.crontab:

   # m h dom mon dow user	command
   #
   # Halts the system
30 15   * * 1-5 root    /sbin/halt
  • Execute the wrapper script upon LTSP client bootup to add the root cronjob, by modifying your lts.conf file:

/var/lib/tftpboot/ltsp/i386/lts.conf:

...
RCFILE_NN = /etc/ltsp/halt_via_cron.sh
}

Now that we have a (root) user-based cronjob, we can easily modify it using scripts, if so desired, by creating a script to ssh into each workstation and remove root's crontab.

  • apt-get install openssh-server in chroot (remember LTSP_HANDLE_DAEMONS var)
  • as root (not in chroot!): ssh-keygen (save into alternate name, such as id_rsa.chroot) (use empty passwords)
  • copy pubkey to chroot's /root/.ssh/authorized_keys
  • rebuild chroot
  • reboot clients
  • WARNING: THIS IS INSECURE!!! use ssh to connect w/o host key verification by using "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user@ip"
  • get IPs of connected clients with: arp -an | cut -d " " -f 2 | sed -e s/"("//g -e s/")"//g