Nieuws:

Welkom, Gast. Alsjeblieft inloggen of registreren.
Heb je de activerings-mail niet ontvangen?

Auteur Topic: Automatische suspend bij inactiviteit voor Xubuntugebruikers  (gelezen 1176 keer)

Automatische suspend bij inactiviteit voor Xubuntugebruikers
« Gepost op: 2008/02/28, 13:07:18 »
Ik heb een wiki gemaakt hiervan:

https://wiki.ubuntu.com/NL_Automatische_Suspend_Xubuntu

Het onderstaande staat daar in beschreven.


In Xubuntu (7.04) kan je geen automatische suspend instellen, alleen een screensaver of het scherm uitzetten. Gnome powermanagement werkt bij mij niet voor deze standby. In de volgende link vond ik een manier om toch automatisch de computer in standby te zetten na een bepaalde tijd van inactiviteit. Hiervoor is het wel nodig dat suspend werkt. Dit kan je testen door in een terminal het volgende te toetsen:

sudo /etc/acpi/sleep.shAls dat werkt, dan kan je de onderstaande wiki gebruiken, ook te vinden op:

http://www.thinkwiki.org/wiki/Installing_Debian_Lenny_on_a_ThinkPad_T60#automated_sleep

 Ik heb in het gebruikte script het checken van geluid weggehaald. Als ik geluid luister zit mijn CPU toch boven de 10%. Dat scheelt weer een pakket om te installeren.

Er zijn twee manieren:
- zonder script, kijkt alleen naar toets en muis(pad) gebruik:
stappen:
1) installeren sleepd en xosview pakketjes
2) toevoegen regel aan rc.local
3) opnieuw opstarten

- met script, kijkt ook naar schijfgebruik, netwerkgebruik en cpu gebruik:
stappen:
1) installeren pakketjes sleepd, xosview, sysstat (alleen nodig bij gebruik script) (en eventueel sox sox-fmt-all als je geluid wilt checken, anders geluidsdeel in script weghalen)
2) opslaan script als /etc/acpi/autosleep.sh en rechten aanpassen met chmod
3) lijn toevoegen aan rc.local zodat sleepd bij opstarten wordt geactiveerd en het script aanstuurd.
4) opnieuw opstarten

Hier zie je hoe:

Citaat
automated sleep

You could also set it up so that your laptop goes to sleep when you close the lid. I however prefer to have my laptop remain awake when the lid is closed so that it can continue background tasks such as ripping a cd, downloading a file, compiling a kernel, playing music, etc. I do however want to have some system of going to sleep during inactivity. For this I use the sleepd package which automatically puts the laptop to sleep after a period of inactivity. It does however requires some configuration to make it actually do this.

First of all, if you haven't already installed it, do so

aptitude install sleepd

Now edit the configuration file /etc/default/sleepd (edit: hoeft niet, je kan ook gewoon de parameters aan het commando meegeven). Set PARAMS to the arguments you want to give the sleepd daemon as started by init. You can take a look at the sleepd man page to get an idea of what you might want to put here. As an example, you might have

PARAMS="-u 180 -U 1800 -s /etc/acpi/sleep.sh -i 1 -i 12 -i 23"

This tells sleepd to sleep after three minutes of inactivity while on battery(-u 180) and after half an hour of inactivity while on ac (-U 1800). I have defined "activity" as signals on irqs 1(keyboard), 12(mouse), and 23(usb mouse) (-i 1 -i 12 -i 23). 1 and 12 will be autodetected (edit: niet in Xubuntu!), but 23 may not be. You can see what uses the various interrupts by running the command cat /proc/interupts.You can also use the xosview utility (edit: om te installeren: sudo apt-get install xosview) to discover when the various IRQ's are used. Finally sleepd itself doesn't actually know how to put the computer to sleep, so you have to supply it with the command to do so (-s /etc/acpi/sleep.sh). You could really put anything at all here.
Je kan dus in een terminal het volgende commando toetsen, en dan gaat de computer na 15 minuten zonder gebruik toetsenbord, touchpad of toetsenbord in de slaapstand (de irq nummers gelden op mijn computer, kunnen dus afwijken, code aanpassen dus, gebruik xosview om de irq's van toetsenbord, muispad en muis te achterhalen, in mijn geval dus 1, 11 en 12):

sleepd -U 900 -u 180 -s /etc/acpi/sleep.sh -i 1 -i 11 -i 12Als je deze regel nu toevoegd aan /etc/rc.local vóór het commando exit, en opnieuw opstart dan heb je een primitieve automatische standby, die alleen kijkt naar gebruik toetsenbord, mousepad of muis. Wil je een betere activiteitscheck, verder met de wiki:

Citaat
You'll note however, that the above is a rather limited definition of "inactivity". Unfortunately, it's the best sleepd has to offer. Alas, none of the above mentioned background tasks that I want my computer to continue doing can be reliably mapped to the use of a particular IRQ. The next best thing then is to have our sleep command be a script that before putting the computer to sleep checks for a wider range of activity before actually going to sleep and aborts the sleep process if such activity is detected. This will reset the sleepd timer so that it must wait for an other interval of human inactivity before running the sleep/check script again.

There are four checks that I want to do before going to sleep:

   1. CPU activity
   2. Disk activity
   3. Network activity
   4. Is sound playing?

The first three can be checked using the sar utility included in the sysstat package, while the latter can be checked using the rec utility included in the sox package. If you haven't already, install those packages. Sox is additionally going to need alsa support, so you could install that package, or just go ahead an install off of sox since its a handy program to have the full functionality of.

aptitude install sysstat sox sox-fmt-all

The following script autosleep.sh is intended to be called by sleepd after user inactivity to check for the background inactivity described above. If there is inactivity in these four fronts, it calls the sleep.sh script and puts the computer to sleep.

#!/bin/bash
# autosleep.sh
# Checks if the computer is inactive before going to sleep. Aborts if it looks like
# there's some action.
#

# Thresholds - these may depend on what you do with your computer and what
# you want it to stay awake for.
CPUTHRESH=5        # in percent
DISKTHRESH=500     # in blocks/sec (the sar manpage says blocks are 512 bytes in normal cases)
NETTHRESH=10       # in kB/s
SNDTHRESH=200      # in ???? rms
# (no sound playing is ~25 while playing mp3 w/ pcm+master turned all the way to zero is ~250)

# Sample times (in seconds) - again needs may vary
CPUTIME=1  
DISKTIME=2  
NETTIME=2
SNDTIME=2


# Check CPU usage defined as non-idle time.
CPU=`sar $CPUTIME 1 | awk '/Average/ { printf "%d\n",100-$8}'`
echo "CPU = $CPU%"
if [ $CPUTHRESH -lt $CPU ];then
    echo CPU is working, not sleeping
    exit;
fi

# Check disk usage (read + write)
DISK=`sar -b $DISKTIME 1 | awk '/Average:/ { printf "%d",$5 + $6 }'`
echo "DISK = $DISK"
if [ $DISKTHRESH -lt $DISK ];then
    echo Disk is working, not sleeping
    exit;
fi

# Check net usage (exclude wifi0 which appears to have activity all the time for some weird reason)
NET=`sar -n DEV $NETTIME 1 | awk '/Average:/ && $2 !~ /(IFACE|wifi0)/ { SUM += $5 + $6 } END { printf ("%d\n",SUM)}'`
echo "NETWORK = $NET"
if [ $NETTHRESH -lt $NET ]; then
    echo Network is in use, not sleeping
    exit;
fi

# Set the mixer to some controlled values and set it to record the mixed sound output
# This unfortunately is going to be sound-chip specific.
alsactl -f /var/tmp/sound.state store
amixer sset Capture 20% cap
amixer sset Digital 20%
amixer sset Mix cap
# Record to null and use RMS amplitude in resulting statistics with a convenience
# factor to make it integer
SND=`rec -n stat trim 0 $SNDTIME 2>&1 | sed -n 's/^RMS[ ]*amplitude:[ ]*/1000000 * /gp' | bc | cut -d. -f 1`
# Restore previous mixer state
alsactl -f /var/tmp/sound.state restore
echo "SOUND = $SND"
if [ $SNDTHRESH -lt $SND ];then
    echo Sound is playing, not sleeping
    exit;
fi

. /etc/acpi/sleep.sh
Als je dit script opslaat als /etc/acpi/autosleep.sh en vervolgens de rechten aanpast met:

sudo chmod uog+x /etc/acpi/autosleep.shVervolgens in /etc/rc.local de volgende lijn (aangepast naar eigen situatie wat betrefd tijden en irq's zoals boven uitgelegd) toevoegen:

sleepd -U 900 -u 180 -s /etc/acpi/autosleep.sh -i 1 -i 11 -i 12Dat geeft in mijn geval /etc/rc.local :
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sleepd -U 900 -u 180 -s /etc/acpi/autosleep.sh -i 1 -i 11 -i 12
exit 0
Vervolgens opnieuw opstarten, en het zou moeten werken.

Wat ik ook nog handig vond om te doen in Xubuntu is het koppelen van de aan en uit knop van mijn laptop aan /usr/bin/xfce4-session-logout. Dan krijg je het keuzescherm voor uitloggen, hibernate, suspend, enz.
Dit kan door te gaan naar Applications --> Settings --> Keyboard Settings en daar de tab Shortcuts kiezen. Dan toevoegen van een shortcut, bovenstaande commando invoeren, en als om een toets gevraagd wordt op de aan en uitknop drukken.

Automatische suspend bij inactiviteit voor Xubuntugebruikers
« Reactie #1 Gepost op: 2008/02/28, 16:19:57 »
Tommy74, volgens mij kan je er beter een officiële document van maken, dan verdwijnt het niet. Zonde van je werk anders.

Met vriendelijke groet,

Gijs
In der Beschränkung zeigt sich der Meister.

Automatische suspend bij inactiviteit voor Xubuntugebruikers
« Reactie #2 Gepost op: 2008/02/28, 19:24:20 »
Ok Gijsbert, gedaan... maar dat viel niet mee.. zo'n wiki schrijven. Niet echt een gebruiksvriendelijke tool om makkelijk een pagina te maken. Misschien komt dat omdat ik niet wist wat een goede template was voor de Nederlandse paginas, en heb ik dus maar de code van een andere pagina aangepast. Misschien gaat het schrijven van een wiki heel eenvoudig als je een template gebruikt.

Het resultaat:

https://wiki.ubuntu.com/NL_Automatische_Suspend_Xubuntu#preview

Voorlopig geen wikis meer voor mij.. kost veel tijd, en op het forum kan je ook makkelik iets terugvinden toch..

Automatische suspend bij inactiviteit voor Xubuntugebruikers
« Reactie #3 Gepost op: 2008/02/29, 20:19:02 »
Geen idee van dat zo'n wiki zo lastig te schrijven is, ik heb het zelf nog nooit gedaan.
Misschien dat een van de moderators weet of er een template bestaat.
Het ziet er in ieder geval goed uit Tommie74.

Met vriendelijke groet,

Gijs
In der Beschränkung zeigt sich der Meister.