Script on suspen and resume

Forum rules
Before you post please read how to get help
Post Reply
Baikan4ik
Level 1
Level 1
Posts: 2
Joined: Mon Apr 02, 2018 10:46 am

Script on suspen and resume

Post by Baikan4ik » Mon Apr 02, 2018 10:52 am

good evening. I'm trying to write a script that runs when suspend system and resume system. I need the LCDd to terminate at suspend, and starts when resume system. Tell me how to implement this? At the moment I'm putting the script in the /etc/pm/sleep.d folder, another script is taken for the template, where I change the case code to the code I need, but it does not work ...

rene
Level 8
Level 8
Posts: 2068
Joined: Sun Mar 27, 2016 6:58 pm

Re: Script on suspen and resume

Post by rene » Mon Apr 02, 2018 5:31 pm

Cannot check anything currently but hooking into systemd is likely the correct course of action on Mint 18.x. I.e., as per https://wiki.archlinux.org/index.php/Po ... leep_hooks. See if that helps any.

rene
Level 8
Level 8
Posts: 2068
Joined: Sun Mar 27, 2016 6:58 pm

Re: Script on suspen and resume

Post by rene » Mon Apr 02, 2018 9:15 pm

Back at a useful machine. Assuming that "LCDd" is the one from the standard lcdproc package you can as what I would consider the likely best approach create the following /etc/systemd/system/LCDd-sleep.service:

Code: Select all

[Unit]
Description=Restart LCDd over sleep

[Service]
ExecStart=/bin/systemctl stop LCDd.service
ExecStop=/bin/systemctl start LCDd.service

[Install]
WantedBy=sleep.target
and enable it via sudo systemctl enable LCDd-sleep.service. This unit makes itself part of systemd's sleep.target which gets invoked on suspend and stops LCDd.service. On resume sleep.target is stopped and it conversely starts LCDd.service again. Seems to work well here; cannot test the actual LCDd service but some logging seems to imply that the above should be all you need.

However: It is also the case that systemd in fact provides for suspend/resume hooks and some might consider that better; see man systemd-sleep for the information that you can also just dump a script in the /lib/systemd/system-sleep/ directory. There does not seem to be an /etc counterpart to that directory and that alone means I'd myself prefer the above method.

A note for anyone who'd like to: it seems not a good idea to adjust LCDd.service itself, mostly due to a seemingly missing "wake.target" and the resulting asymmetry between suspend and resume actions...

Baikan4ik
Level 1
Level 1
Posts: 2
Joined: Mon Apr 02, 2018 10:46 am

Re: Script on suspen and resume

Post by Baikan4ik » Tue Apr 03, 2018 1:02 am

Thank you very much) in the evening I will try and write about the results)

Post Reply

Return to “Scripts & Bash”