You are not logged in.

#1 2013-02-01 08:21:56

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 94

[solved] Simple auto-suspend...

I've similar problem:

(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.'

In this thread I could not find any comprehensible solution for me.
pm_utils article says: 'This article or section is out of date.' and refers to systemd.
systemd article does not answer the question, how to auto(!) suspend the system in any way.
Also tried laptop-mode-tools which are producing strange errors as described here and only react on acpi events during uptime (settings are ignored on boot till I manually restart laptop-mode or initiate an acpi event).

Hibernation and suspend work without problems when manual acticated.
It's 'only' the question, how to autosuspend after a specified time of inactivity.
Isn't there a simple, an easy way  (kiss?) to tell the system to suspend after a while without having to install a complete 'power management framework'. Perhaps some hidden *.conf or *.cfg somwhere in the depths of systemd or arch?

Any ideas?

Last edited by renegat (2013-02-01 20:13:43)

Offline

#2 2013-02-01 08:27:10

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [solved] Simple auto-suspend...

Does litemotive's solution not work? Can't you just combine it with systemctl suspend?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2013-02-01 08:50:26

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 94

Re: [solved] Simple auto-suspend...

The only 'solution' given in this thread was to install 'sleepd-git' which is 'Flagged out-of-date (2012-10-29)' and does not work for me (see comments). Or did I miss sth?

Offline

#4 2013-02-01 09:01:55

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [solved] Simple auto-suspend...

No; you just didn't mention in your first post that sleepd appears to be a dead project...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2013-02-01 12:39:28

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [solved] Simple auto-suspend...

That's what I'm using (place it e.g. at the bottom of .xinitrc):

pidof -s xautolock >& /dev/null
if [ $? -ne 0 ]; then
  xautolock -time 60 -locker "systemctl suspend" &
fi

:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#6 2013-02-01 14:45:06

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 94

Re: [solved] Simple auto-suspend...

Looks really fine but the ~/.xinitrc file is a shell script read by xinit and startx, right?
I use LXDM to autologin and start LXDE.
I don't know if .xinitrc will be even read.
Really thought this elementary functionality was already implemented somwhere inside arch or systemd (as it grabs more and more functionality from other programms) and has only to be enabled or set somewhere.

Offline

#7 2013-02-01 15:02:20

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [solved] Simple auto-suspend...

I'm not quite sure how LXDE organizes autostart applications, but you can simply create a script that's loaded with your DE. (BTW, that's how I do it, without any DE, though: I have a collection of executable bash scripts in my .config/autostart/ directory, with the following in .xinitrc:

if [ -d $HOME/.config/autostart ]; then
  for c in $HOME/.config/autostart/* ; do
    [ -x "$c" ] && . "$c"
  done
  unset c
fi

I believe that it shouldn't be difficult for you to create a 'suspend.desktop' file there as well and run it without any reference to .xinitrc.)

Last edited by bohoomil (2013-02-01 15:03:40)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#8 2013-02-01 16:14:55

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Re: [solved] Simple auto-suspend...

There are methods that work without Xorg, too. For example this autosuspend script i use on my server:

#!/bin/bash

# Source the configuration file
. /etc/autosuspend.conf

# Log system notice
logit()
{
        logger -p local0.notice -s -- AutoSuspend: $*
        return 0
}

# Look for other CLIENTS in the network
IsOnline()
{
        for i in $*; do
                ping $i -c1
                if [ "$?" == "0" ]; then
                  logit "CLIENT $i is still active, auto suspend terminated"
                  return 1
                fi
        done
        return 0
}

IsRunning()
{
        for i in $*; do
                if [[ `pgrep -c $i` > 0 ]] ; then
                        logit "PROCESS $i still active, auto suspend terminated"
                        return 1
                fi
        done
        return 0
}

IsDaemonActive()
{
        for i in $*; do
                if [[ `pgrep -c $i` > 1 ]] ; then
                        logit "DAEMON $i still active, auto suspend terminated"
                        return 1
                fi
        done
        return 0
}

IsBusy()
{
        # Samba
        if [ "$SAMBANETWORK" ]; then
                if [ `/usr/bin/smbstatus | grep $SAMBANETWORK | wc -l ` != "0" ]; then
                  logit "SAMBA connected, auto suspend terminated"
                  return 1
                fi
        fi

        #daemons that always have one process running
        IsDaemonActive $DAEMONS
        if [ "$?" == "1" ]; then
                return 1
        fi

        #backuppc, wget, wsus, ....
        IsRunning $APPLICATIONS
        if [ "$?" == "1" ]; then
                        return 1
        fi

        # No Suspend if there are any users logged in
        if [[ `who | wc -l` > 0 ]];then 
        logit "USERS still connected, auto suspend terminated";
        return 1
        fi
        
        IsOnline $CLIENTS
        if [ "$?" == "1" ]; then
                return 1
        fi

        return 0
}

IDLE_FILE="/var/spool/autosuspend_idle_marker"
OFFFILE="/var/spool/autosuspend_off"

# turns off the auto suspend
if [ -e $OFFFILE ]; then
        logit "auto suspend is turned off by existents of $OFFFILE"
        exit 0
fi

if [ "$AUTO_SUSPEND" = "no" ]; then
        logit "auto suspend is turned off in configuration file /etc/autosuspend.conf"
elif [ "$AUTO_SUSPEND" = "yes" ]; then
        # Check if system is busy now.
        IsBusy
        if [ "$?" == "0" ]; then
                # Idle now. Has the system been idle on the previous check?
                if [ -e $IDLE_FILE ]; then
                        # Suspend now.
                        logit "AUTO SUSPEND CAUSED"
                        rm -f $IDLE_FILE
                        systemctl suspend
                        exit 0
                else
                        # Mark system as idle for the next check.
                        touch $IDLE_FILE
                        logit "marked as idle for next check"
                        exit 0
                fi
        else
        # Busy now. Mark system as busy for the next check.
                rm -f $IDLE_FILE
                logit "marked as busy for the next check"
                exit 0
        fi
        exit 0

else
        logit "misconfiguration. Check /etc/autosuspend.conf"
fi
exit 1

Source:
http://wiki.ubuntuusers.de/Skripte/AutoSuspend
(German with code commented in english.)

Offline

#9 2013-02-01 20:12:31

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 94

Re: [solved] Simple auto-suspend...

Thank you - bohoomils ways work fine now by dropping LXDM and using autologin to virtual console and then autostart X in ~/.bash_profile.
Now the .xinitrc scripts are read.
@teateawhy: This script depends on pm-utils installed which I wanted to prevent.

Offline

#10 2013-02-01 20:41:44

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Re: [solved] Simple auto-suspend...

renegat wrote:

@teateawhy: This script depends on pm-utils installed which I wanted to prevent.

No this script does NOT depend on pm-utils, i changed it to use systemctl instead 3 months ago. The script runs on my server that does not have pm-utils.

$ pacman -Q pm-utils
error: package 'pm-utils' was not found

Please read my first post again.

Offline

#11 2013-02-02 06:47:31

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 94

Re: [solved] Simple auto-suspend...

@teateawhy: Sorry, you are right! Your script uses systemd functionality not pm-utils.
I only checked your given source @ubuntuusers.de which says so and did not recognize your script has been modified.
I'll try your script next days on my server without X.
Thank you.

Offline

#12 2024-02-28 18:00:27

loh.tar
Member
Registered: 2010-10-17
Posts: 49

Re: [solved] Simple auto-suspend...

I know posting to old threads is discouraged. But I found teateawhys script here some weeks ago, liked it, spend some love to it and made it now public.

Offline

#13 2024-02-28 18:20:16

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,300

Re: [solved] Simple auto-suspend...

Thanks for sharing something new and potentially related, If you want to discuss the script further, please open a new thread in "Community Contributions" or so.

Closing this old thread.

Offline

Board footer

Powered by FluxBB