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:
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:
[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:
type = process
command = /usr/bin/spotifyd --no-daemon
smooth-recovery = true
Any clues?
Thanks in advance!
https://wiki.archlinux.org/title/acpid
Hey! Thanks for the quick response!
So should I just
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?
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.
I would try to take a look at elogind stuff.
https://forum.artixlinux.org/index.php/topic,834.msg6475.html
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:
/usr/lib/elogind/system-sleep/69-spotifyd-sleep
#!/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
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.