You are not logged in.

#1 2022-12-04 12:55:33

boina
Member
From: Barcelona - Spain
Registered: 2011-06-05
Posts: 46

[SOLVED] User service doesn't restart after suspend

I have written a user service to restart spotifyd after suspend as suggested by @christo-auer in github.

[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

If I enable this unit with the --user flag I get this output:

systemctl --user enable restartSpotifyd
Unit .config/systemd/user/restartSpotifyd.service is added as a dependency to a non-existent unit suspend.target.

The service is never restarted after suspend.

If I enable this service as root the service tries to restart when I check the status after suspend but I have this error:

dic 04 13:11:02 jamming systemctl[57893]: Failed to connect to bus: No se ha encontrado el medio
dic 04 13:11:02 jamming systemd[1]: restartSpotifyd.service: Main process exited, code=exited, status=1/FAILURE
dic 04 13:11:02 jamming systemd[1]: restartSpotifyd.service: Failed with result 'exit-code'.

The bottom line is that I can´t figure out how to restart a user service after suspend. I image it can´t be complicated but I just can´t find the solution.

Thanks!

Last edited by boina (2022-12-04 20:57:03)

Offline

#2 2022-12-04 17:35:43

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,132

Re: [SOLVED] User service doesn't restart after suspend


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2022-12-04 17:40:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] User service doesn't restart after suspend

Those aren't actually user services though and they don't run in the context of the user session.  Those are just regular system units that drop root privileges when they change to the specified user.  (Not to mention the assumption that DISPLAY would be :0).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2022-12-04 20:56:12

boina
Member
From: Barcelona - Spain
Registered: 2011-06-05
Posts: 46

Re: [SOLVED] User service doesn't restart after suspend

I have learned more about systemd trying to solve this. I have now realized that a user service can't reach system services and that was my problem.
I have followed Daniel Garajau's instructions (https://garajau.com.br/2022/08/systemd- … user-level). I had to create 2 new services to proxy suspend.target to the user level.
Thanks for your suggestions.

Offline

Board footer

Powered by FluxBB