You are not logged in.

#1 2010-04-29 10:17:52

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

[Solved] Simple auto-suspend script?

I'm looking for a simple solution to auto-suspend (ram/disk) a system after a certain time of inactivity. I can find surprisingly little info for this for linux (or perhaps i'm not looking in the right places), while windows for instance has this built in for years already.

The idea is simple but maybe tricky in practice; if there is no user input for x seconds, no video/audio playing or continuous disk/network usage, suspend the system. Basically the system just needs to be idle for a certain amount of time.

Does anyone know or have a working script or utility for this, or is writing one myself the only solution? The simplest approach i can think of is a combination of checking user idle time (with 'w') and sysload, though it might be necessary to determine a threshold for the latter to avoid simple jobs (cron etc.) producing a 0.01 sysload and thus preventing suspend.

Any other thoughts or suggestions about this?

Last edited by litemotiv (2010-05-07 11:03:55)


ᶘ ᵒᴥᵒᶅ

Offline

#2 2010-04-29 10:20:39

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: [Solved] Simple auto-suspend script?

xscreensaver should be able to do this.


neutral

Offline

#3 2010-04-29 10:45:24

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

sand_man wrote:

xscreensaver should be able to do this.

afaik xscreensaver only checks for user interaction, or requires 3rd party software (mplayer etc.) to explicitely keep-alive the system. i don't consider that a generic solution.


ᶘ ᵒᴥᵒᶅ

Offline

#4 2010-04-29 13:17:51

steve___
Member
Registered: 2008-02-24
Posts: 439

Re: [Solved] Simple auto-suspend script?

Have a look at 'sinac' in aur.  Maybe in .xinitrc you could:

while : ; do
    sinac -w 300
    slock     ## if you want to lock your screen
    pm-suspend
done

Last edited by steve___ (2010-04-29 13:18:57)

Offline

#5 2010-04-29 15:42:40

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

steve___ wrote:

Have a look at 'sinac' in aur.

from the source it seems to only check the X idle time through libxss, basically the same as xscreensaver?


ᶘ ᵒᴥᵒᶅ

Offline

#6 2010-04-29 15:48:09

steve___
Member
Registered: 2008-02-24
Posts: 439

Re: [Solved] Simple auto-suspend script?

Ahh you're not in X.  I didn't understand this.

Offline

#7 2010-04-30 17:17:38

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [Solved] Simple auto-suspend script?

sleepd-git works for me so I added it to AUR a while ago. No X required.

Last edited by Profjim (2010-04-30 17:19:58)

Offline

#8 2010-04-30 18:26:38

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

that looks very promising Profjim, thanks!


ᶘ ᵒᴥᵒᶅ

Offline

#9 2010-04-30 18:50:35

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

Profjim, don't know if you're still reading: with sleepd, do you know if it's possible to check for audio playing? i have an mpd instance running on the target machine which sometimes drops below measurable sysload (0.00), so i wonder how i could avoid suspend for that scenario with sleepd?


ᶘ ᵒᴥᵒᶅ

Offline

#10 2010-04-30 19:07:02

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [Solved] Simple auto-suspend script?

I don't know. It's pretty configurable what it looks for, but I just use the default (watch keyboard and mouse activity). A quick read of the man page didn't provide an answer to your need. But this is the only lightweight daemon I've found for doing this kind of thing. (The only other options I've seen are gnome-power-manager, etc.) So why don't you look into it and see what you find. Report back here if you find a solution, or an alternative that you think is more promising.

Offline

#11 2010-04-30 21:02:09

muunleit
Member
From: Germany
Registered: 2008-02-23
Posts: 234

Re: [Solved] Simple auto-suspend script?

maybe xautolock in combination with pm-utils could help you too


"The mind can make a heaven out of hell or a hell out of heaven" -- John Milton

Offline

#12 2010-05-01 09:44:11

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

muunleit: see the earlier posts, solutions depending on libxss will only check for user-input (mouse/keyboard). xautolock basically does the same thing as xscreensaver and sinac.

i have now added the hda-intel irq to sleepd's watchlist, that seems to work well. if linux doesn't decide to change the irq on reboot, this could be a working approach. smile


ᶘ ᵒᴥᵒᶅ

Offline

#13 2010-05-01 12:15:33

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [Solved] Simple auto-suspend script?

litemotiv wrote:

i have now added the hda-intel irq to sleepd's watchlist, that seems to work well. if linux doesn't decide to change the irq on reboot, this could be a working approach.

What are your exact changes? I'm assuming you added soemthing like this to the PARAMS array in /etc/conf.d/sleepd:

    ...
    -i somethingorother
    -a
    ...

Offline

#14 2010-05-01 12:55:47

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: [Solved] Simple auto-suspend script?

Sorry for hijacking your thread but I tryed sleepd to suspend and lock my screen after a certain amount of time. So far it's working smoothly except when I am watching something with xbmc.

So I just set --load=1 in /etc/conf.d/sleepd but it still goes to suspend. And I verified with the key o in xbmc that the cpu load is higher than 1%. I also added "-N" as sometime I let my computer download stuff for me in the background.

PARAMS=("--unused=600" "--ac-unused=600" "--load=1" "-N" "--sleep-command=su lymphatik -c slock & dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0" "--battery=2" "--hibernate-command=dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate int32:0")

Last edited by lymphatik (2010-05-01 12:56:42)

Offline

#15 2010-05-01 13:13:18

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

Profjim:

"--irq=22" "--auto" "--load=0.01"

lymphatik:

a load of 1 is quite high (100% for 1 core), try lowering it to 0.1 for 10% or 0.01 for 1%


ᶘ ᵒᴥᵒᶅ

Offline

#16 2010-05-01 14:54:19

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: [Solved] Simple auto-suspend script?

Oh ok thanks I thought it was in percent ;( thanks.

And litemotiv you might want to add "-N" for internet or ethernet activity.

Offline

#17 2010-05-01 15:16:25

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

lymphatik wrote:

And litemotiv you might want to add "-N" for internet or ethernet activity.

i figured that any network activity would surely raise sysload above 0.01 wink


ᶘ ᵒᴥᵒᶅ

Offline

#18 2010-05-07 11:03:35

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved] Simple auto-suspend script?

i raised the sysload threshold to 0.25 and sleepd has been working great on both my laptop and atom-server for about a week now. i'm going to mark this topic solved. smile


ᶘ ᵒᴥᵒᶅ

Offline

Board footer

Powered by FluxBB