LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   XFCE (or related) Power Management "Inactivity" Settings/Exceptions (http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/)

jdackle 07-02-2013 11:14 PM

XFCE (or related) Power Management "Inactivity" Settings/Exceptions
 
Hello everyone,

I'm looking for a way to setup the XFCE Power Management (or some other Power Management software that XFCE will honour) "inactivity" status so that it does not go to sleep when a certain operation or application is running.

Examples: I don't want the PC to go to sleep when I am:
- Downloading messages with Claws-Mail;
- Downloading torrents with Deluge;
- Doing a system scan with ClamAV;
- Doing a 'fsck -c" ...
You get the picture...

Some non-GUI software that any GUI (XFCE or any other DE) will honour would actually be preferred - but I'm ok with configuring XFCE directly (through some config file...? )
I would also prefer it to be tailored to operations (such as continuous network or disk activity) rather than applications, but again, configuring the (in)activity status based on apps will be fine too.

Thanks in advance.

xl 07-07-2013 11:05 AM


I'm not entirely sure if you're okay with checking if the programs are running.
Monotoring if there is a network or disk activity is rather difficult. You had to grab (grep, awk, cut, sed), calculate (bc?) it and integrate the output in a script. Disks can be watched by iotop (--batch and --only options should do the trick). There are several tools to check the network but I unfortunaley only know nethogs that combines this with applications (all else do protocols and ports). It's also quite power-hungry if no delay (-d) is set.

On the other hand aren't mails steadily downloaded, isn't your bittorrent client always uploading?
The script below will only check if a program is running with pgrep. "clam" would also suffice for "clamav", just as "fsck" is enough for "fsck.ext4". You can set as many programs as you want but don't forget the double pipe "||" for OR. The xfconf command works with minutes: 15 is minimum, 350 is maximum. 0-14 means the system will never go to sleep. The sleep command is in seconds which you could technically set to your minimum inactivity time (900).
In only checked with
Code:

xfconf-query -c xfce4-power-manager -l -v
since I usually work with my computer, if not I turn it off. ;)
So the script will check once a minute if this or that program is running. If yes it will set the delay to 5:50 hours, if not it will set it to 0:15 hours.

Code:

#!/bin/bash
while true
do
        if        ( pgrep -l clamav ) ||
                ( pgrep -l fsck )
        then
                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -t string -s 350
        else
                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -t string -s 15
        fi
        sleep 60
done

I looked in advance how the system sets the power mode. I sought for DBus, APM and ACPI but I'm still not sure how inactivity is reported. In XFCE's case it looks this is all done by some xf* daemon I guess ... If someone could enlighten me.

man xfce4-power-manager says that applications can send an Inhibit to DBus so the system will not go to sleep. So a proper programmed program should do what you want (or at least offer as an option).

jdackle 07-07-2013 08:10 PM

Thank you very much, xl! That sounds like it will do it just fine, yes.

I understand (vaguely) he issues with monitoring disk/network activity (just asked in case...). So yes, monitoring programs instead will work just fine.

I was actually considering the use of cpufreqd (which was an absolute must on my old machine but not so much on this one) which provides similar functionality. But that seemed like a sort of dirty-hack to me (considering I would be using a cpufreqd's feature that was meant as an exception to cpu frequencies configurations, not directly to power management (though cpufreqd can be used in that respect quite well too).

So yes, the sollution you proposed looks much more straightforward and elegant! I'll try it out and report back later.

Thanks again.

jdackle 07-09-2013 06:12 PM

Following xl's suggestions, I expanded a tiny bit on his script and came up with three scripts I can use to easilly manage the inactivity settings of XFCE4 Power Management app.

Sorry if the comments on them sound a bit quaint; I just like to keep things documented in case I stumble upon them later on and don't remember what they do or how anymore...

First script is basically xl's script expanded a bit. I does not check for Network apps (Claws-Mail, Deluge ...). It will terminate the second script (posted bellow) if that one is running. And the second will payback the deed everytime too... First script:
powman-dab-nna
Code:

#!/bin/sh

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 07/07/2013

# JDAckle:
echo powman-dab-nna
echo PowerManagement Delayed, Applications-Based - NO Network Apps
echo

# In case it's running, kill the other version. powman-dab-nai (Network Apps included).
# Useful to get back to a more "normal" state
killall -q powman-dab-nai

while true
do
        if        ( pgrep -l clamscan ) ||
                ( pgrep -l clamdscan ) ||
                ( pgrep -l fsck ) ||
                ( pgrep -l make )
        then
                # Disable xfce4-power-manager putting the PC to sleep (any value < 15 disables XFCE put-to-sleep)
                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -t string -s 0
        else
                # Inactivity period set to 20 minutes
                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -t string -s 20
        fi
        # Recheck every 3 minutes
        sleep 180
done

The second one is a simple expansion on the first, to include a couple Network apps that can sometimes take a long time to do their job (and I may actually leave them to it overnight; so I'll run this script before going to bed...):
powman-dab-nai
Code:

#!/bin/sh

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 07/07/2013

# JDAckle:
echo powman-dab-nai
echo PowerManagement Delayed Applications-Based - Network Apps INCLUDED.
echo

# In case it's running, kill the other version. powman-dab-nna (No Network Apps).
# The applications listed in there are already listed here.
killall -q powman-dab-nna

while true
do
        if        ( pgrep -l clamscan ) ||
                ( pgrep -l clamdscan ) ||
                ( pgrep -l fsck ) ||
                ( pgrep -l make ) ||
                ( pgrep -l claws-mail ) ||
                ( pgrep -l deluge )
        then
                # Disable xfce4-power-manager putting the PC to sleep (any value < 15 disables XFCE put-to-sleep)
                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -t string -s 0
        else
                # Inactivity period set to 20 minutes
                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -t string -s 20
        fi
        # Recheck every 3 minutes
        sleep 180
done

The last script checks and displays info about whether any of the other two is running. It also displays xfce4-power-manager's current "inactivity before sleep" status:
powman-dab-status
Code:

#!/bin/sh

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 07/07/2013

echo powman-dab-status
echo PowerManagement Delayed, Applications-Based - Status
echo

if        ( pgrep -l powman-dab-nna ) ; then
        echo \"PowerManagement Delayed, Applications-Based - NO Network Apps\" is running.
elif        ( pgrep -l powman-dab-nai ) ; then
        echo \"PowerManagement Delayed, Applications-Based - Network Apps included\" is running.
else
        echo NO \"PowerManagement Delayed, Applications-Based\" script is running. You can run:
        echo \'powman-dab-nna\' for \"PowerManagement Delayed, Applications-Based - NO Network Apps\"
        echo or
        echo \'powman-dab-nai\' for \"PowerManagement Delayed, Applications-Based - Network Apps included\"
fi
echo

JDAINACTIVITY=$( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v )
if [ $JDAINACTIVITY -lt 15 ] ; then
        echo XFCE4 is currently set to NOT put the computer to sleep.
else
        echo XFCE4 PowerManager will put the computer to sleep after $JDAINACTIVITY minutes of inactivity.
fi
echo

I placed the first one on the list of programs to run at startup on XFCE's "Session and Startup" settings and everything is working fine.
I'm pretty sure these scripts with the ocasional tweaking will be plenty enough for a good while so I'm marking this as "solved".

Once again, many thanks, xl, you did all the work, I only made some cosmetics! Thanks! :)

jdackle 07-27-2013 07:23 AM

The above scripts DO NOT WORK!

They did detect whether the concerning applications were running or not and did execute the corresponding actions.
They did disable the sleep feature whenever the "/xfce4-power-manager/inactivity-on-ac" property value was set to 0.
But they did NOT bring the automatic go-to-sleep after n minutes of inactivity feature back up! Once disabled (set to 0), the auto-sleep would not be enabled again until reboot (or maybe relog)!

Oddly enough, my powman-dab-status script would report the property reset to 20 minutes and so would executing xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v directly on the terminal.
BUT the XFCE Power Manager settings GUI would display it as "never"! And this was what was actually happening on the system (it never went to sleep once it got disabled by my script at least once).

So I did three changes related to this (actually four but kept only three):
1. Set a condition to check whether the concerning property was set to auto-sleep or deactivated. I hadn't looked at the GUI yet and it had occured to me the resetting of the value might reset the inactivity count (thus the machine being reset to active every three minutes). It didn't fix it and I think this doesn't actually happen, but I kept it anyway for safe measure.
2. Removed the "-t string" part of the attribute-setting command. It's not needed and it should probably rather be set to "integer" or "number" or whatever. Didn't fix it either but still kept it.
3. Added a xfce-power-manager --restart after setting the property. Didn't fix it and I think it wiser to not keep it - this is the one that got removed.
4. Changed the disabling value from 0 to 14. I think this is what actually fixed it!

I haven't thoroughly tested it yet but it seems to be working.
The new versions of the scripts are pasted below and also include some additional applications not included before. Do note the case of dd which I had to set as pgrep -lf /bin/dd because "dd" is just too short (part of the name of other unrelated processes).

powman-dab-nna
Code:

#!/bin/sh

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 07/07/2013

# JDAckle:
echo powman-dab-nna
echo PowerManagement Delayed, Applications-Based - NO Network Apps
echo

# Kill the other version,  powman-dab-nai (Network Apps included), in case it's running.
# Useful to get back to a more "normal" state
killall -q powman-dab-nai

while true
do
        if        ( pgrep -l clamscan ) ||
                ( pgrep -l clamdscan ) ||
                ( pgrep -l fsck ) ||
                ( pgrep -l make ) ||
                ( pgrep -lf /bin/dd ) ||
                ( pgrep -l ntfsclone ) ||
                ( pgrep -l dpkg )
        then
                if [ $( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v ) -gt 14 ] ;
                then
                        # Disable xfce4-power-manager putting the PC to sleep (any value < 15 disables XFCE put-to-sleep)
                        xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -s 14
                fi
        else
                if [ $( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v ) -lt 15 ] ;
                then
                        # Inactivity period set to 20 minutes
                        xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -s 20
                fi
        fi
        # Recheck every 3 minutes
        sleep 180
done

powman-dab-nai
Code:

#!/bin/sh

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 07/07/2013

# JDAckle:
echo powman-dab-nai
echo PowerManagement Delayed Applications-Based - Network Apps INCLUDED.
echo

# Kill the other version. powman-dab-nna (No Network Apps), In case it's running.
# The applications listed in there are already listed here.
killall -q powman-dab-nna

while true
do
        if        ( pgrep -l clamscan ) ||
                ( pgrep -l clamdscan ) ||
                ( pgrep -l fsck ) ||
                ( pgrep -l make ) ||
                ( pgrep -lf /bin/dd ) ||
                ( pgrep -l ntfsclone ) ||
                ( pgrep -l dpkg ) ||
                ( pgrep -l claws-mail ) ||
                ( pgrep -l deluge ) ||
                ( pgrep -l curl ) ||
                ( pgrep -l wget )
        then
                if [ $( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v ) -gt 14 ] ;
                then
                        # Disable xfce4-power-manager putting the PC to sleep (any value < 15 disables XFCE put-to-sleep)
                        xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -s 14
                fi
        else
                if [ $( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v ) -lt 15 ] ;
                then
                        # Inactivity period set to 20 minutes
                        xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -s 20
                fi
        fi
        # Recheck every 3 minutes
        sleep 180
done

powman-dab-status
Same as in previous post, unchanged.

jdackle 07-29-2013 11:20 AM

Improved the scripts.
The checking for a relevant running program is now done in the same way (with the necessarya adaptations) Jack S. Lai coded his own "Disable KDE4 screensaver while watching a movie" script, posted at http://www.linuxquestions.org/questi...0/#post4997687 . This is IMHO a much more deficient way of doing it.

The current powman-dab-nna script:
Code:

#!/bin/sh

# Script suggested by user "xl" at LinuxQuestions.org in reply to a question of mine (JDAckle):
# XFCE (or related) Power Management "Inactivity" Settings/Exceptions
# http://www.linuxquestions.org/questions/linux-desktop-74/xfce-or-related-power-management-inactivity-settings-exceptions-4175468270/
# 02/07/2013 to 27/07/2013
# Process-running check modified according to the way Jack S. Lai coded his own  "Disable KDE4 screensaver while watching a movie" script, posted at http://www.linuxquestions.org/questions/linux-desktop-74/disable-kde4-screensaver-while-watching-a-movie-4175471090/#post4997687 (27/07/2013, 06:06 GMT

echo Program name: powman-dab-nna
echo PowerManagement Delayed, Applications-Based - NO Network Apps
echo

# Kill the other version,  powman-dab-nai (Network Apps included), in case it's running.
# Useful to get back to a more "normal" state
killall -q powman-dab-nai

# Space seperated list of programs to look for:
programs="clamscan clamdscan fsck make /bin/dd ntfsclone dpkg"

while true
do
        for pgm in ${programs}; do        # Check list of programs one by one
                if ps axo comm | grep $pgm ; then # Is a program running?
                # Yes, a relevant program is running.
                        if [ $( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v ) -gt 14 ] ;
                        # Is the "sleep on inactivity" property set to active?
                        then
                                # Yes. Disable putting the PC to sleep (any value < 15 disables XFCE put-to-sleep)
                                xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -s 14
                        fi
                        break        # All done, we had at least one program running.
                fi
                # Reached the end of the list of programs and no relevant one is running.
                if [ $( xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -v ) -lt 15 ] ;
                # Is the "sleep on inactivity" property disabled?
                then
                        # Yes. Set the inactivity period before sleep to 20 minutes
                        xfconf-query -c xfce4-power-manager -p "/xfce4-power-manager/inactivity-on-ac" -s 20
                fi
        done
        # Recheck every 3 minutes
        sleep 180
done

powman-dab-nai is now just the same as powman-dab-nna, only the list of programs changed (I might merge the two scripts into one somehow, at a later time):
Code:

programs="clamscan clamdscan fsck make /bin/dd ntfsclone dpkg claws-mail deluge curl wget apt"
powman-dab-status: Unchanged.


All times are GMT -5. The time now is 06:02 PM.