Xfce Forum

Sub domains
 

You are not logged in.

#1 2019-10-21 15:19:55

rayandrews
Member
From: Vancouver B.C. Canada
Registered: 2011-12-30
Posts: 177

On return from hibernation how can a command be executed?

So, I return from hibernation, and there's a thing or two that I'd like to have done automatically.  There are ways of doing this at the systemd level, but once xfce restarts the systemd level changes get lost.  For example I always want my backup disk to be put to sleep, but it seems that when it resumes xfce always polls the disk and spins it up again. How to make the 'hdparm -y /dev/sdb' command the very last thing that happens such that xfce has finished restarting before that command is executed?  There's a few other things that get lost after a resume and it would be nice to have some script or other that's always the very last thing executed.  Can it be done?

Offline

#2 2019-10-21 15:45:13

Hussam
Member
Registered: 2019-10-16
Posts: 7

Re: On return from hibernation how can a command be executed?

Hello. Create a file /usr/lib/systemd/system-sleep/somethingsomething
with content

#!/bin/bash

case $1 in
    pre)
        ## commands I want to do before hibernation or standby start.
        /usr/bin/firstthingbeforehibernate
        ## add more stuff here or use &&
    ;;
    post)
        ## commands I want to do after resuming from hibernation or standby.
        /usr/bin/firstcommandafteresume
        ## add more stuff here or use && or use the "sleep" command to wait a bit first while xfce settled down
    ;;
esac

then chmod +x /usr/lib/systemd/system-sleep/somethingsomething
(lower case x to make it executable).

Another idea is to umount the backup disk first.

Last edited by Hussam (2019-10-21 15:48:51)

Offline

#3 2019-10-21 16:54:12

rayandrews
Member
From: Vancouver B.C. Canada
Registered: 2011-12-30
Posts: 177

Re: On return from hibernation how can a command be executed?

Thanks.  I have no such directory.  Here's anything *sleep*

/usr/lib/klibc/bin/sleep
/usr/share/hibernate/scriptlets.d/acpi_sleep
/usr/share/man/man5/systemd-sleep.conf.5.gz
/usr/share/man/man3/sleep.3.gz
/usr/share/man/man3/usleep.3.gz
/usr/share/man/man2/nanosleep.2.gz
/usr/share/man/man2/clock_nanosleep.2.gz
/usr/share/man/man1/sleep.1.gz
/usr/share/lightning/components/calSleepMonitor.manifest
/usr/share/lightning/components/calSleepMonitor.js
/lib/systemd/system/systemd-hybrid-sleep.service
/lib/systemd/system/sleep.target
/lib/systemd/system/hybrid-sleep.target
/lib/systemd/systemd-sleep
/bin/sleep

Here's anything *hibernate*:

files:

/usr/sbin/hibernate
/usr/share/icons/hicolor/48x48/apps/system-hibernate.png
/usr/share/icons/hicolor/48x48/apps/xfsm-hibernate.png
/usr/share/doc/hibernate/examples/hibernate.vim.gz
/usr/share/man/man5/hibernate.conf.5.gz
/usr/share/man/man8/systemd-hibernate-resume@.service.8.gz
/usr/share/man/man8/systemd-hibernate-resume-generator.8.gz
/usr/share/man/man8/hibernate.8.gz
/usr/share/bash-completion/completions/pm-hibernate
/var/log/hibernate.log.5
/var/log/hibernate.log.1
/var/log/hibernate.log
/var/log/hibernate.log.2
/var/log/hibernate.log.3
/var/log/hibernate.log.4
/var/lib/dpkg/info/hibernate.postinst
/var/lib/dpkg/info/hibernate.conffiles
/var/lib/dpkg/info/hibernate.preinst
/var/lib/dpkg/info/hibernate.postrm
/var/lib/dpkg/info/hibernate.md5sums
/var/lib/dpkg/info/hibernate.prerm
/var/lib/dpkg/info/hibernate.list
/lib/systemd/system-generators/systemd-hibernate-resume-generator
/lib/systemd/systemd-hibernate-resume
/lib/systemd/system/systemd-hibernate.service
/lib/systemd/system/hibernate.target
/lib/systemd/system/systemd-hibernate-resume@.service
/etc/hibernate/hibernate.conf
/etc/logrotate.d/hibernate

directories:

/usr/local/share/hibernate
/usr/share/hibernate
/usr/share/doc/hibernate
/usr/share/bug/hibernate
/var/lib/systemd/deb-systemd-helper-enabled/hibernate.target.wants
/etc/hibernate
/etc/systemd/system/hibernate.target.wants


Systemd doesn't make things simple, does it?

Last edited by rayandrews (2019-10-21 16:55:56)

Offline

#4 2019-10-22 09:14:40

Hussam
Member
Registered: 2019-10-16
Posts: 7

Re: On return from hibernation how can a command be executed?

Which systemd version are you using?
Systemd configuration depends on the distribution to be fair. Stock systemd installations work best.
I am afraid I am not sure how Debian implements it as I have not used Debian or one of its derivatives in the past decade.
However, since Debian is one of the prominent distributions, what I would do in this case is consult Debian support on how to add "sleep hooks" in their systemd installation. Perhaps they offer some documentation.

Offline

#5 2019-10-22 10:28:02

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: On return from hibernation how can a command be executed?

@OPs seems to be located at /lib/systemd/systemd-sleep.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#6 2019-10-22 13:00:43

rayandrews
Member
From: Vancouver B.C. Canada
Registered: 2011-12-30
Posts: 177

Re: On return from hibernation how can a command be executed?

HussamT wrote:

Which systemd version are you using?
Systemd configuration depends on the distribution to be fair. Stock systemd installations work best.
I am afraid I am not sure how Debian implements it as I have not used Debian or one of its derivatives in the past decade.
However, since Debian is one of the prominent distributions, what I would do in this case is consult Debian support on how to add "sleep hooks" in their systemd installation. Perhaps they offer some documentation.

Yep, it's Debian.  But I do recall trying this before, and I did figure out the 'sleep hooks' but it didn't work anyway.  Xfce seemed to always spin up the disks regardless.  Dunno, maybe I should try again.  As for systemd, I can't say I love it, they seem to go  out of their way to make things more complicated than the tax code.

Offline

#7 2019-10-22 15:19:28

rayandrews
Member
From: Vancouver B.C. Canada
Registered: 2011-12-30
Posts: 177

Re: On return from hibernation how can a command be executed?

Got it:

file is /etc/hibernate/common.conf :

>### misclaunch
>OnSuspend 20 echo "Good night!"
>OnResume 20 echo "Good morning!"
>OnResume 21 hdparm -S60 /dev/sdb; hdparm -C /dev/sdb; hdparm -y /dev/sdb
>OnResume 22 . /aWorking/Zsh/System/mouse

... spins down my 2nd disk, and resets my mouse parameters (which are also lost on resume).  One of the two dozen or so possible files had to work ;-) 

Thanks guys.

Last edited by rayandrews (2019-10-22 15:21:36)

Offline

Board footer

Powered by FluxBB