Page 1 of 1

Script on suspen and resume

Posted: Mon Apr 02, 2018 10:52 am
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 ...

Re: Script on suspen and resume

Posted: Mon Apr 02, 2018 5:31 pm
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.

Re: Script on suspen and resume

Posted: Mon Apr 02, 2018 9:15 pm
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...

Re: Script on suspen and resume

Posted: Tue Apr 03, 2018 1:02 am
by Baikan4ik
Thank you very much) in the evening I will try and write about the results)