个人工具

UbuntuHelp:UbuntuLTSP/ChrootCronjobs

来自Ubuntu中文

跳转至: 导航, 搜索
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.


This page is dedicated to managing cronjobs for LTSP clients. There are multiple benefits for this functionality, such as Automated|Client Shutdown. There are plenty of other reasons to have this, it is up to you to think of them!

Steps

  • 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.
export LTSP_HANDLE_DAEMONS="false"
  • Install cron in our chroot (i386 chroot is assumed, modify for your specific setup):
sudo 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.

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.sh:

 #!/bin/bash 
 #
 # P. Baco - Carlit.net
 # Crontab LTSP script
 #
 # This script, when started from lts.conf "RCFILE_XX = /etc/ltsp/crontab.sh"
 # 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 thin client image
 #
 TMPFILE=/tmp/crontab.tmp

 echo "# Crontab file for LTSP thin clients" > $TMPFILE
 echo "# See CRONTAB_01 to CRONTAB_10 in lts.conf" >> $TMPFILE
 
 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
 if [ -f $TMPFILE ]; then
   crontab $TMPFILE
 fi
 rm -f $TMPFILE

Chmod the script:

sudo chmod 755 /opt/ltsp/i386/etc/ltsp/crontab.sh

Rebuild your image.

sudo ltsp-update-image

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

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

# Example crontab entry for shutting down thin clients at 16:00:
CRONTAB_01 = "00 16 * * 1-5 /sbin/halt"

Reboot the thin client(s). Done.