Script on suspen and resume

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Baikan4ik

Script on suspen and resume

Post by Baikan4ik »

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 ...
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Script on suspen and resume

Post by rene »

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 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Script on suspen and resume

Post by rene »

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

Re: Script on suspen and resume

Post by Baikan4ik »

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

Return to “Scripts & Bash”