[Solved] Run command upon resume

Hi there,
I was wondering if there is a way to configure what script / command to run when waking up from standby or hibernate?
I do run manjaro off a usb pen and don't use the host system's hdd at all. Hence, I send it with hd-idle to sleep upon start. However, I don't find a way to put it to sleep again after wakeup/resume. Hence, I always have to open a terminal window and do it manually.
Looking forward to reading your advice.

You can write a systemd unit file to launch whatever command or script you wish to run after resuming.

Here is one example:

If you search the forum you will find other posts where this is used as a method to launch commands pre/post suspend.

1 Like

Ah, if I would have known this, that the Bluetooth/Wifi-control is related, I would have looked for that, because this is another topic which bugs me on my macbook pro - I need to suspend/wakeup after boot in order to have wifi running...
Hence, I was looking for something related to the terms in the header I chose and wasn't successful in finding in the forum.
Anyway, thanks for the hint which I'm happy to investigate in further. :+1:

1 Like

Here is another example of the most recent systemd unit file I have written. It is involvolving ethernet, but the principles are all the same regardless.

If you use the systemd service method and it works for you, please post your working solution. Every new solution posted on the forum brings a better understanding of how to resolve many suspend/resume problems that arise.

Wow, this was so easy! Thanks a million for your advice!
I have followed the example of No Ethernet Network Connection after Resume; very recent problem and created a systemd service and used following configuration on

sudo nano /etc/systemd/system/hddidle.service

added these contents

Description=Send host hdd sda to sleep after resuming

ExecStartPre=/bin/sleep 15s
ExecStart=/usr/bin/hd-idle -t sda

sudo chown root:root /etc/systemd/system/hddidle.service
sudo chmod+x /etc/systemd/system/hddidle.service
sudo systemctl enable hddidle.service

After this, I have closed the lid of my laptop, waited for the suspend to finish.
Then, with opening the lid again, the hdd woke up, and it was sent back to sleep after 15 seconds.

I might play around with some settings on it, or just leave as is. Other idea would be to identify the location of the wakeup command for the host hdd and disable this.
Thanks again for giving me directions. I am happy to share my solution.

1 Like

Yes it is very easy once you know how to do it. There is a bit of a learning curve when you don't have a clue how to accomplish what you want though. The systemd manpages are far from clear on how to make this work. It's kind of like reading Greek when you first start researching its usage. Once you find some working examples online it becomes much easier.

I originally started writing scripts to be called from the systemd unit which was way more complicated than it needed to be. I simply was used to scripting so thought that was necessary. After a while I realized simple tasks did not require the use of external scripts.

I'm trying to familiarize people on the forum with this method as it can solve many different problems. This method is not widely used and it deserves more exposure.

I'm so glad I could help and that this solved your problem. Thank you for posting the unit file you created, much appreciated.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by