Skip to main content
Topic: [SOLVED] Restarting a service after suspend (Read 530 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

[SOLVED] Restarting a service after suspend

So here's my issue:

I'm running spotifyd as a dinit user service. When I suspend my machine with loginctl, spotifyd, due to some librespot limitations (according to my research) seems to fail to notice that it crashed, making the service unable to restart itself. So what I'm trying to do is make the service restart when I resume.

I noticed that the "spotifyd-dinit" package on pacman "depends-on" network, which should work since network gets disconnected when suspended, but since I'm running the service as user the script fails.

Here's how the pacman's script looks like:

Code: [Select]
type            = process
command         = /usr/bin/spotifyd --no-daemon
smooth-recovery = true
logfile         = /var/log/dinit/spotifyd.log
depends-on      = network

On systemd the workaround looks like this:

Code: [Select]
[Unit]
Description=Restart spotifyd after resume
After=suspend.target

[Service]
Type=simple
ExecStart=/bin/systemctl --user --no-block restart spotifyd.service

[Install]
WantedBy=suspend.target

How my script currently looks like:

Code: [Select]
type            = process
command         = /usr/bin/spotifyd --no-daemon
smooth-recovery = true

Any clues?
Thanks in advance!


Re: Restarting a service after suspend

Reply #2

Hey! Thanks for the quick response!
So should I just

Code: [Select]
after           = acpid

Wouldn't this interfere with the fact that I'm trying to run the script as user?

EDIT:

Thank you glgl-schemer! I just tried and it seems to be working! Not sure why though, the question remains. Maybe because I used the "after" instead of "depends-on" of the original script?

Re: Restarting a service after suspend

Reply #3
I meant something in the "Define event action" section, so you can restart spotifyd after resume. Acipd should have nothing to do with the sequence of services.


 

Re: Restarting a service after suspend

Reply #5
I meant something in the "Define event action" section, so you can restart spotifyd after resume. Acipd should have nothing to do with the sequence of services.

Oh yeah, forget what I said earlier, the after=acpid did nothing. I was testing with the system resuming only for a few minutes so I had the impression that it worked. Only after a long suspension I realized that it didn't help.


Thanks for reminding me of this!
So here's what I did:
Code: [Select]
/usr/lib/elogind/system-sleep/69-spotifyd-sleep
Code: [Select]
#!/bin/bash
case $1/$2 in
  pre/*)
    ;;
  post/*)
    exec dinitctl restart spotifyd
    ;;
esac

Then chmod +x
Hopefully it works now. Will report later!

Edit: It seems that elogind is not running scripts located on /usr/lib/elogind/ or /usr/lib64/elogind/, but actually on /etc/elogind/, so I symlinked it
Code: [Select]
ln -s /lib/elogind/system-sleep /etc/elogind/system-sleep
Not sure why. I wonder if it's a bug that I should report.

It seems to be working now. Tagging the topic as SOLVED, but if there's a more elegant solution using dinit scripts only please let me know.