Run a script, using service, before suspend


i try to make a service turning off monitor(TV whit webos) when system suspend:

Description=off screen before suspend

ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/lgtv MyTv off ssl


This script WORK if i test him, but suspending manjaro make lan disconnected IMMEDIATLY (red X on lan icon) i use sleep 5 to see what’s happening while service running:

  • click suspend
  • lan disconnect immediatly
  • remote command error beaucause lan is disconnected
  • 5 seconds pass
  • system will suspend

My question: there is a way to tell at service “don’t stop ethernet when suspend?” Or configure lan to NOT disable when suspend system? Modify suspend rules?


Hi @Dareku,

I’m by no means an expert, but I think that should be After instead of Before:

Check the man page for more information:

man systemd-suspend.service


Also see

Edit #2


Alternate answer using systemd

Create a file /lib/systemd/system-sleep/ with the following content:

case $1/$2 in
# commands to be executed before suspend, hibernate, etc. goes below
echo "This example does nothing"
# commands to be executed on wake, resume, etc. goes below
echo "Nothing to see here"

Edit and add the commands you need to add instead of the lines starting with echo above. Save the file and make it executable. See How to make a file (e.g. a .sh script) executable, so it can be run from a terminal for more.

Edit 3:

Also see:

Edit #4



I’m almost certain that this will make your script be executed as soon as your network is marked “online”, so remove that :wink:

Note: Don’t blindly copy over your config from your previous script in the other thread which had different requirements and goals…

The sequence of units used when booting, are not the same as those used to suspend nor resume from a suspended state…


as soon as i can i will try with your precious suggestions!!!

@TriMoon I’m almost certain that this will make your script be executed as soon as your network is marked “online”, so remove that

i didn’t understand why i shouldn’t tell to the script to run when my network is online, like a check.

@TriMoon mentioned right after it has been started, so not when you’re shutting down the PC, AFAIK.

1 Like

That line is not a check, it tells systemd to execute your script when the network comes online.
But your script’s functionality is to put your TV OFF right?
So think about powering off your TV when you boot your PC, is that correct behavior you want? :wink:

Checks that must be valid before a service is run, are using different keywords, and none of them can check for presence of a service on a remote machine…

1 Like

no way, i try all you suggest (thx) and read all tutorial.
Best explanation is:

According to a reply from systemd-devel mailing list, this is impossible using solely systemd while using Network Manager as Network Manager listens for the sleep signal on its own. A workaround is to put what you need to run into:


i think this workaround not working well… imagine various network failure scenario and monitor flip on/off… not good.

But let’s move on to the positive results! Now i can turn off the tv during shutdown and during system startup, not bad at all!

PS: Is there a way to politely ask the manjaro developers to make script working before the network off while suspend? It could be useful to everyone.

Seems like you want to speak to the network manager or systemd devs…or maybe they need to speak to each other.

Anyway, if you aren’t already, you could use this to suspend. Bind it to a key combo if you want.


lgtv MyTv off ssl
systemctl suspend

A systemd service should work for resume. It’s late and I’m feeling too lazy to write one right now, maybe tomorrow (assuming you haven’t already got one).

Alternatively use a different network manager. Then this service should work, assuming the other network managers don’t do the same (at least systemd-networkd should hopefully work :crossed_fingers:).

Description=Turn off screen before suspend

ExecStart=/usr/bin/lgtv MyTv off ssl



Here’s a resume service that should work, you may need to tweak the sleep time. I haven’t found a way to only use Before, After etc yet.

Description=Turn on TV after suspend

ExecStartPre=/usr/bin/sleep 5
ExecStart=/usr/bin/lgtv MyTv on ssl


If you change the dependencies (eg WantedBy, and possibly Before, After etc) then you should disable and re-enable the service for the changes to take effect.

1 Like

only putting script in Network manager pre-down work. But it’s a bad workaround for me.


I also create a commad to “cp” the script in pre-down folder when system sleep and “rm” at resume.

The script will move the file but won’t work, also try to launch modrpobe command to activate network, but sleep it’s absolutly prioritary than any others commands…

i am thinking to buy an ir usb adapter to control better TV. :grinning:

Maybe check man systemd-sleep
Which mentions /lib/systemd/system-sleep/ :wink:
(There is no alternative to this directory, like /etc/…)