“UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn”的版本间的差异
来自Ubuntu中文
小 (创建新页面为 '{{From|https://help.ubuntu.com/community/UbuntuLTSP/AutomatedTCShutodwn}} {{Languages|UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn}} {|border="1" cellspacing="0" |This page is spec...') |
小 |
||
第2行: | 第2行: | ||
{{Languages|UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn}} | {{Languages|UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn}} | ||
{|border="1" cellspacing="0" | {|border="1" cellspacing="0" | ||
− | |This page is specific to Ubuntu versions 8.04 | + | |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.'' | ''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 = $$$ !) | 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 to [[UbuntuHelp:UbuntuLTSP/UnlockChrootRootAcct|unlock|the chroot 'root' account]]. Unlocking the chroot root account is necessary for cron jobs to run successfully. | ||
+ | * Now follow the instructions in [[UbuntuHelp:UbuntuLTSP/ChrootCronjobs|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: | ||
<pre><nowiki> | <pre><nowiki> | ||
− | + | # This one will halt client(s) at 20:30 from Monday to Friday | |
+ | CRONTAB_01 = "30 20 * * 1-5 /sbin/halt" | ||
</nowiki></pre> | </nowiki></pre> | ||
− | * | + | * 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: | ||
<pre><nowiki> | <pre><nowiki> | ||
− | chroot /opt/ltsp/i386 apt-get install | + | sudo chroot /opt/ltsp/i386 apt-get install zenity |
</nowiki></pre> | </nowiki></pre> | ||
− | '' | + | * Copy the following script, called ''shutdownwarning'', to /opt/ltsp/i386/etc/ltsp: |
− | + | shutdownwarning: | |
<pre><nowiki> | <pre><nowiki> | ||
− | + | #!/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. | |
− | + | # | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | #!/bin/bash | + | |
− | # | + | |
− | # | + | |
− | + | ||
− | # | + | |
− | # This script | + | |
− | + | ||
− | # | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | # | + | |
− | + | ||
− | # | + | |
− | + | ||
− | + | DISPLAY=$(ps -ef | grep -v awk | awk '/Xauthority/ { print $NF }') | |
− | for i in 01 02 03 04 05 06 07 08 09 10 | + | export DISPLAY |
− | do | + | |
− | + | # 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." | |
− | + | ||
− | done | + | if [ "$?" = 0 ]; then |
− | if [ -f $TMPFILE ]; 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!" | |
− | fi | + | |
− | rm $TMPFILE | + | 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 | ||
</nowiki></pre> | </nowiki></pre> | ||
− | Chmod | + | * Chmod your script: |
<pre><nowiki> | <pre><nowiki> | ||
− | chmod 755 /opt/ltsp/i386/etc/ltsp/ | + | sudo chmod 755 /opt/ltsp/i386/etc/ltsp/shutdownwarning |
</nowiki></pre> | </nowiki></pre> | ||
− | Rebuild your image | + | * Rebuild your chroot image: |
<pre><nowiki> | <pre><nowiki> | ||
− | ltsp-update-image | + | sudo ltsp-update-image |
</nowiki></pre> | </nowiki></pre> | ||
− | + | * Add this as a CRONTAB_NN entry in lts.conf, 5 minutes before the cronjob to shut the system down: | |
+ | lts.conf: | ||
<pre><nowiki> | <pre><nowiki> | ||
− | + | CRONTAB_01 = "25 20 * * 1-5 /etc/ltsp/shutdownwarning" | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | CRONTAB_01 = " | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</nowiki></pre> | </nowiki></pre> | ||
− | |||
=== Notes === | === Notes === | ||
* You might now want to follow the instructions for [[UbuntuHelp:UbuntuLTSP/InstallNTPServer|Installing an NTP server]] so your thin-client time is in sync with the server time. | * You might now want to follow the instructions for [[UbuntuHelp:UbuntuLTSP/InstallNTPServer|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 [[UbuntuHelp:UbuntuLTSP/AutomatedTCStartup|Automated thin-client startup]]! | * If you like automated shut-down, you'll probably like [[UbuntuHelp:UbuntuLTSP/AutomatedTCStartup|Automated thin-client startup]]! | ||
− | + | * As an alternative to the zenity idle logout script above, there is a software project called [http://www.cs.mcgill.ca/~james/code/ evanescent] which could do the job as well. It is more configurable, and interacts with the users session more coherently. | |
− | + | ||
− | + | ||
− | + | ||
− | / | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | / | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
---- | ---- | ||
[[category:CategoryLtsp]] | [[category:CategoryLtsp]] | ||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2009年11月17日 (二) 20:51的版本
点击翻译: |
English |
请不要直接编辑翻译本页,本页将定期与来源同步。 |
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 to unlock|the chroot 'root' account. Unlocking the chroot root account is necessary for cron jobs to run successfully.
- Now 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!
- As an alternative to the zenity idle logout script above, there is a software project called evanescent which could do the job as well. It is more configurable, and interacts with the users session more coherently.