The officially official Devuan Forum!

You are not logged in.

#1 Yesterday 19:41:17

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,984  

How can I run a script on resume from hibernation?

If I want to run a script when resuming from hibernation, google tells me to do something with systemd. That's not an option. I poked around in /etc/acpi/ and /etc/elogind/ and I can't figure it out. I did read a few man pages, too. It's probably not difficult, but requires knowing where/what to tweak.

Offline

#2 Yesterday 20:29:49

greenjeans
Member
Registered: 2017-04-07
Posts: 1,760  
Website

Re: How can I run a script on resume from hibernation?

Possibly add something in /etc/initramfs-tools/conf.d , I use it to get rid of boot warnings (RESUME=none), but possibly add a line about running the script after resuming normally? So maybe RESUME=<swap partition or whatever you use> && somescript.sh

Sounds hacky, but ya never know. Then update-initramfs and see what happens, lol.

Last edited by greenjeans (Yesterday 20:32:58)


https://sourceforge.net/projects/vuu-do/ Vuu-do GNU/Linux, Devuan-based Openbox systems.
Devuan 6 mate-mini iso, pure Devuan, 100% no-vuu-do. Now with Xlibre as well.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
https://devuanusers.com/ Apps source : https://git.devuan.org/greenjeans

Offline

#3 Yesterday 21:23:18

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,744  

Re: How can I run a script on resume from hibernation?

@greenjeans that's just stupid.

@fsmithred, tt of course depends on which hibernate-resume pathway you actually are using. Some go via pm-utils and for that you may check out man pm-hibernate. Or maybe you rely on logind in which case you'd check out man loginctl instead.

Offline

#4 Yesterday 21:24:45

rbit
Administrator
Registered: 2018-06-12
Posts: 148  

Re: How can I run a script on resume from hibernation?

I've got this script (for an example) from when I used to hibernate/suspend.  It might require pmtools pm-utils (as Ralph noted above).

#!/bin/bash
# Script name: /etc/pm/sleep.d/50_network
# Purpose: Restore network settings upon thaw / resume

case $1 in
  suspend|suspend_hybrid|hibernate)
    :
    ;;
  resume|thaw)
    # wait 10s for network to come back
    sleep 10
    logger -s "/etc/pm/sleep.d/50_network: Restoring network settings..."
    # restore network settings
    /usr/local/sbin/netconfig.sh
    logger -s "/etc/pm/sleep.d/50_network: Done."
    ;;
esac

Offline

#5 Yesterday 22:16:50

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,984  

Re: How can I run a script on resume from hibernation?

Thanks. I got it to work with pm-hibernate. I put a simple script in /etc/sleep.d/testmessage and it ran. Just this...

#!/usr/bin/env bash

echo "$(date)" > /home/user/TESTMESSAGE

exit 0

Offline

#6 Today 01:16:05

greenjeans
Member
Registered: 2017-04-07
Posts: 1,760  
Website

Re: How can I run a script on resume from hibernation?

@greenjeans that's just stupid.

lol

I'm sure you're right, but it's fun to brainstorm, and in the end fsmithred go it to work with a similar simple hack, Not convinced my idea wouldn't work though, I may have to try it, though I don't typically use hibernate for anything.


https://sourceforge.net/projects/vuu-do/ Vuu-do GNU/Linux, Devuan-based Openbox systems.
Devuan 6 mate-mini iso, pure Devuan, 100% no-vuu-do. Now with Xlibre as well.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
https://devuanusers.com/ Apps source : https://git.devuan.org/greenjeans

Offline

#7 Today 01:35:21

Mercury
Member
Registered: 2024-11-14
Posts: 50  

Re: How can I run a script on resume from hibernation?

This is timely as I had a similar problem on my checklist. After consulting Gemini and getting past its initial wrong answer, I got the following, which works with elogind, which is what I got installed by default in Devuan:

Create /etc/elogind/system-sleep/your_script.sh

Make it executable.

Fill the contents:

#!/bin/sh
if [ "$1" = "post" ]; then
    # Your wakeup commands here
    echo "Woke up at $(date)" >> /tmp/wakeup.log
fi

This works. The $1 variable will be either "pre" or "post" for suspend or wakeup respectively.

ralph.ronnquist wrote:

iOr maybe you rely on logind in which case you'd check out man loginctl instead

...which gives the bad info (as Gemini did initially) that scripts in [/usr]/lib[64]/elogind/system-sleep will be executed. In fact, empirical testing shows they are not. Only those in /etc/elogind/system-sleep/ are, which shows once again that bad documentation is worse than no documentation. I suppose I should be expected to file a bug to fix the docs?

Last edited by Mercury (Today 01:48:38)

Online

#8 Today 01:55:54

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,744  

Re: How can I run a script on resume from hibernation?

Yes, filing a bug for elogind would be helpul. You file to Debian (bugs.debian.org) against the package although, I believe, upstream source is in Devuan's git store.

Offline

Board footer