特殊:Badtitle/NS100:UbuntuLTSP/AutomatedTCShutodwn:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Wikibot留言 | 贡献
创建新页面为 '{{From|https://help.ubuntu.com/community/UbuntuLTSP/AutomatedTCShutodwn}} {{Languages|UbuntuHelp:UbuntuLTSP/AutomatedTCShutodwn}} {|border="1" cellspacing="0" |This page is spec...'
 
Wikibot留言 | 贡献
无编辑摘要
 
(未显示同一用户的1个中间版本)
第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 = $$$ !)
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!
=== 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).
* 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!)
=== Installing cron in the chroot ===
* 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>
export LTSP_HANDLE_DAEMONS="false"
# 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>
* Now, if you haven't already, 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.
* Reboot your thin clients for the cron jobs to take effect.
* Now, let's install cron in our chroot (i386 chroot is assumed, modify for your specific setup):
=== 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 cron
sudo chroot /opt/ltsp/i386 apt-get install zenity
</nowiki></pre>
</nowiki></pre>
''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?''
* Copy the following script, called ''shutdownwarning'', to /opt/ltsp/i386/etc/ltsp:
* 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):
shutdownwarning:
<pre><nowiki>
<pre><nowiki>
sudo vim /opt/ltsp/i386/etc/crontab
#!/bin/bash
</nowiki></pre>
#
/opt/ltsp/i386/etc/crontab:
# Created 2009/10/09 Jordan Erickson (LNS)
<pre><nowiki>
#
30 15    * * 1-5   root    /sbin/halt
# This script warns any logged-in LTSP user that the client will
</nowiki></pre>
# shut down in 5 minutes (ala a cronjob) and gives them the chance
* Now update your chroot NBD image:
# to disable it.
<pre><nowiki>
#
ltsp-update-image
 
</nowiki></pre>
DISPLAY=$(ps -ef | grep -v awk | awk '/Xauthority/ { print $NF }')
* Reboot your thin-clients, and enjoy automated, configurable shutdown!
export DISPLAY
==== 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
# Ask the user what to do
called '''"CRONTAB_01"''' to '''"CRONTAB_10"''' (in the [default] section or any specific thin client section). This technique lets you:
main() {
* modify shutdown time (or any crontab command) without rebuilding the image.
  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."
* set different crontab tasks for different thin clients.
 
First, create this script as '''/opt/ltsp/i386/etc/ltsp/crontab''':
      if [ "$?" = 0 ]; then
<pre><nowiki>
        # Do nothing by default - shutdown is enabled already. Inform the user.
#!/bin/bash
        zenity --info --title="Shutdown ENABLED" --text="Shutdown will occur. Please save your work and log out immediately!"
#
 
# P. Baco - Carlit.net
      elif [ "$?" = 1 ]; then
# Crontab LTSP script
        # Remove the crontab entry for shutting the system down
#
        # See /opt/ltsp/i386/etc/ltsp/crontab.sh - Thanks to P. Baco @ Carlit.net !!
# This script, when started from lts.conf "RCFILE_XX = /etc/ltsp/crontab"
        TMPFILE=/tmp/crontab.tmp
# will add up to 10 tasks to the thin client's root crontab.
        TMPFILE2=/tmp/crontab.tmp2
# Tasks are defined as regular crontab lines in lts.conf variables
        # Re-create the crontab.tmp file via getltscfg and CRONTAB_NN environment vars
# "CRONTAB_01" to "CRONTAB_10"
        for i in 01 02 03 04 05 06 07 08 09 10
# ex:
        do
# CRONTAB_01 = "30 20 * * 1-5 /sbin/halt"
            JOB=$(getltscfg CRONTAB_$i)
# will halt the thin client at 20:30 monday to friday
            if [ -n "$JOB" ]; then
#
              echo >> $TMPFILE
# Note: Requires crontab to be installed in the chrooted image
              echo "# Found in CRONTAB_$i" >> $TMPFILE
#
              echo "$JOB" >> $TMPFILE
TMPFILE=/tmp/crontab.tmp
            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


rm -f $TMPFILE
# EOF
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
</nowiki></pre>
</nowiki></pre>
Chmod the script:
* Chmod your script:
<pre><nowiki>
<pre><nowiki>
chmod 755 /opt/ltsp/i386/etc/ltsp/crontab
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>
Then edit /var/lib/tftpboot/ltsp/i386/lts.conf:
* 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>
# Start the crontab creation script
CRONTAB_01 = "25 20 * * 1-5 /etc/ltsp/shutdownwarning"
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!\""
</nowiki></pre>
</nowiki></pre>
Reboot the thin client(s). Done.
=== 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]]!
== ***** UNDER CONSTRUCTION BELOW THIS LINE - MOVE ALONG, NOTHING TO SEE HERE ***** ==
* In addition to this, there is a software project called [http://www.cs.mcgill.ca/~james/code/ evanescent] which can shut systems down after a configurable amount of idle (I.E. no user input from keyboard/mouse) time.
=== 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:
<pre><nowiki>
    #!/bin/bash
    #
/usr/bin/crontab /etc/ltsp/root.crontab
</nowiki></pre>
* Make the script executable:
<pre><nowiki>
chmod 770 /opt/ltsp/arch/etc/ltsp/halt_via_cron.sh
</nowiki></pre>
* Make a crontab file for ''root'' (this example halts the system at 3:30pm every weekday):
/opt/ltsp/i386/etc/ltsp/root.crontab:
<pre><nowiki>
  # m h dom mon dow user command
  #
  # Halts the system
30 15  * * 1-5 root    /sbin/halt
</nowiki></pre>
* 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:
<pre><nowiki>
...
RCFILE_NN = /etc/ltsp/halt_via_cron.sh
</nowiki></pre>}
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
----
----
[[category:CategoryLtsp]]
[[category:CategoryLtsp]]


[[category:UbuntuHelp]]
[[category:UbuntuHelp]]

2010年5月20日 (四) 00:28的最新版本

{{#ifexist: :UbuntuLTSP/AutomatedTCShutodwn/zh | | {{#ifexist: UbuntuLTSP/AutomatedTCShutodwn/zh | | {{#ifeq: {{#titleparts:UbuntuLTSP/AutomatedTCShutodwn|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:UbuntuLTSP/AutomatedTCShutodwn|1|-1|}} | zh | | }}

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.