Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Run commands when resuming from hibernation

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Run commands when resuming from hibernation

#1 Post by Scorpion »

Can I run commands automatically when resuming from hibernation?
Sometimes the mouse sensitivity commands are reset.

Code: Select all

xinput --set-prop '<mouse brand>' 'libinput Accel Profile Enabled' 0, 1 

xinput --set-prop '<mouse brand>' 'libinput Accel Speed' -0.8 

User avatar
Uptorn
Posts: 205
Joined: 2022-01-22 01:07
Has thanked: 171 times
Been thanked: 43 times

Re: Run commands when resuming from hibernation

#2 Post by Uptorn »

Create file at /lib/systemd/systemd-hibernate-resume/sensitivity.sh and populate it with something like:

Code: Select all

 #!/bin/bash
       if [ "${1}" == "post" ]; then
           xinput --set-prop '<mouse brand>' 'libinput Accel Profile Enabled' 0, 1 
           xinput --set-prop '<mouse brand>' 'libinput Accel Speed' -0.8 
       fi
 exit 0
Then chmod +x /lib/systemd/systemd-hibernate-resume/sensitivity.sh

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Run commands when resuming from hibernation

#3 Post by Scorpion »

It is not a folder but an executable:

Code: Select all

file /lib/systemd/systemd-hibernate-resume
/lib/systemd/systemd-hibernate-resume: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=382f32b991867a613da4b43a40429727d203dfd4, for GNU/Linux 3.2.0, stripped

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 45 times

Re: Run commands when resuming from hibernation

#4 Post by reinob »

The directory should be /lib/systemd/system-sleep/, IIRC.

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Run commands when resuming from hibernation

#5 Post by Scorpion »

I can see that folder, but it doesn't work I also tried this to see if it works:

Code: Select all

#!/bin/sh
set -e

if [ "$2" = "hibernate" ] || [ "$2" = "hybrid-sleep" ]; then
    case "$1" in
        post)
            /usr/bin/xzoom
            ;;
    esac
fi
It is based on /lib/systemd/system-sleep/unattended-upgrades.
I tried to launch xzoom because it's easy to see if it is working.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 45 times

Re: Run commands when resuming from hibernation

#6 Post by reinob »

@Scorpion,

Whatever is run from there is run as root, so running X apps is not going to work as you expect.
You could however create a systemd unit like this:

Code: Select all

[Unit]
Description=On wake-up
After=sleep.target

[Service]
User=your_username
Type=simple
ExecStart=/usr/local/bin/on_wakeup.sh

[Install]
WantedBy=sleep.target
.. which, if enabled, will run the script *as your user* (as specified in User).

With a bit of luck, you can run GUI programs from there (make sure the DISPLAY variable is not empty, otherwise it will fail).

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2020
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 138 times
Been thanked: 204 times

Re: Run commands when resuming from hibernation

#7 Post by Hallvor »

I did something similar here: viewtopic.php?f=16&t=149484

Just edit the script.
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Run commands when resuming from hibernation

#8 Post by Scorpion »

This is /etc/systemd/system/wakeup.service that I made:

Code: Select all

[Unit]
Description=Run script
After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target


[Service]
ExecStart=/etc/wakeup.sh
User=root
Environment=DISPLAY=:0


[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
Before I tried the default without User and Env, in Service.
Is this how do you specify the display so? It is from the link.
I tried to open xzoom and to set the mouse sensitivity that doesn't need to use the GUI, but it doesn't work.
I reloaded the service and suspended to test it.
My user is root.

/etc/wakeup.sh:

Code: Select all

#!/bin/sh

case $1 in
  post)
    #/usr/bin/xzoom  
    xinput --set-prop '<mouse brand>' 'libinput Accel Profile Enabled' 0, 1 
    xinput --set-prop '<mouse brand>' 'libinput Accel Speed' -0.8 
  ;;
esac

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 45 times

Re: Run commands when resuming from hibernation

#9 Post by reinob »

You don't want to run that as root, unless you're running X as root, which you most certainly are not and should not.

Make sure the User in the systemd unit is set to whatever user is running X.

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Run commands when resuming from hibernation

#10 Post by Scorpion »

I am running X as root.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 45 times

Re: Run commands when resuming from hibernation

#11 Post by reinob »

I think I didn't express myself correctly/accurately.
Running X as root is fine, but you should not log in as root in your desktop environment, if you are using one.

Maybe it's time for you to clearly state how you are starting X, i.e. if you use a desktop manager (and which), or if you are running startx or xinit from the console, and as which user, etc.

You should in any case not run xinput or xzoom, etc. as root.


Post Reply