Sunshine icon indicating copy to clipboard operation
Sunshine copied to clipboard

Default systemd doesn't work after reboot, requires manually launch

Open iaomw opened this issue 3 years ago • 15 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your issue described in the documentation?

  • [X] I have read the documentation

Is your issue present in the nightly release?

  • [X] This issue is present in the nightly release

Describe the Bug

I am trying then deb package from github release. It works well except the default systemd config.

/usr/lib/systemd/user/sunshine.service;

It never work after reboot. And I noticed the contents is different from your document. There are many xdg-desktop-autostart.target comparing to your documents.

Expected Behavior

No response

Additional Context

No response

Host Operating System

Linux

Operating System Version

kubuntu 22.04.3 with Kernel 6.2.0

Architecture

64 bit

Sunshine commit or version

0.20.0

Package

Linux - deb

GPU Type

Nvidia

GPU Model

RTX 3070 Ti

GPU Driver/Mesa Version

535.86.05

Capture Method (Linux Only)

No response

Config

I never touch it.

Apps

No response

Relevant log output

not related

iaomw avatar Aug 14 '23 08:08 iaomw

I noticed the contents is different from your document

Does the service listed in the documents work?

ReenigneArcher avatar Sep 02 '23 01:09 ReenigneArcher

I noticed the contents is different from your document

Does the service listed in the documents work?

No, it doesn't work after reboot. The same.

iaomw avatar Sep 07 '23 14:09 iaomw

Doesn't work for me either on Arch Linux using the AUR package. I'm fairly sure it used to work some time ago. I'm using GNOME on Xorg as my desktop.

Either way, IMO a better solution here would be to provide a .desktop file in the packages and let users configure autostart through their DE (or systemd-xdg-autostart-generator). That is what I did as a workaround and it starts fine this way.

xTeixeira avatar Sep 11 '23 12:09 xTeixeira

.desktop file has already been added to nightly releases.

ReenigneArcher avatar Sep 11 '23 12:09 ReenigneArcher

.desktop file has already been added to nightly releases.

Awesome, thanks. :)

To add more context, I believe this problem started after https://github.com/LizardByte/Sunshine/commit/a192c504cda3842eaf90dcf970037b6b23ba0f29 was merged. I don't think xdg-desktop-autostart.target is something that works at all in GNOME. Not sure about other DEs. In fact, in my system, manually starting the sunshine unit makes systemd try to start every dependency of xdg-desktop-autostart.target, which isn't something that normally happens on a gnome-session login.

In short, if we really want a working systemd unit (instead of letting users configure autostart through the .desktop entry), we need a rework on the dependencies of the unit file, removing any usage of xdg-desktop-autostart.target in favor of something that works with any DE or WM. That being said I'm not entirely sure how to achieve that. I might try looking more into that later.

xTeixeira avatar Sep 11 '23 13:09 xTeixeira

.desktop file has already been added to nightly releases.

Awesome, thanks. :)

To add more context, I believe this problem started after a192c50 was merged. I don't think xdg-desktop-autostart.target is something that works at all in GNOME. Not sure about other DEs. In fact, in my system, manually starting the sunshine unit makes systemd try to start every dependency of xdg-desktop-autostart.target, which isn't something that normally happens on a gnome-session login.

In short, if we really want a working systemd unit (instead of letting users configure autostart through the .desktop entry), we need a rework on the dependencies of the unit file, removing any usage of xdg-desktop-autostart.target in favor of something that works with any DE or WM. That being said I'm not entirely sure how to achieve that. I might try looking more into that later.

Indeed, as the original author of that commit I can confirm that relying on xdg-desktop-autostart.target isn't the best option. It seems to work just fine for me on plasma, but I've seen reports that it doesn't reliably work on other DEs. The big issue here is that, unfortunately, there doesn't seem to be any universal target you can use that works across all DEs. Previously, for me, sunshine would sometimes start before the DE (when using wayland), causing a black screen on log in because kwin tried to get exclusive to the framebuffer. I honestly don't know what the best solution here would be, since there doesn't seem to be any universal way to get the systemd service to start after the DE. Maybe it would be best to just drop the systemd service, and rely solely on the .desktop file?

HomerSp avatar Oct 02 '23 13:10 HomerSp

systemd.special(7) says there are only 3 passive user targets: graphical-session-pre.target, graphical-session.target and xdg-desktop-autostart.target.

xdg-desktop-autostart.target exists to help with XDG autostart, but it's part of a separate systemd functionality that not all systems might use. There also doesn't seem to be anything specifying that this target actually runs after the DE is initialized.

Ultimately, graphical-session.target is the last initialization step in the systemd spec. Anything after that is specific to the individual DEs and distributions.

That said, I've had no issues with this unit:

[Unit]
Description=Sunshine is a self-hosted game stream host for Moonlight.
StartLimitIntervalSec=500
StartLimitBurst=5
# delay initialization to after graphical-session.target has been started
After=graphical-session.target

[Service]
ExecStart=/usr/bin/sunshine
# uncomment the line below if your system is reporting session initialization prematurely
# ExecStartPre=/usr/bin/sleep 30 # wait  30s before starting sunshine
Restart=on-failure
RestartSec=5s

[Install]
# activate this unit alongside graphical-session.target
WantedBy=graphical-session.target

The secret is that it leverages systemd's differentiation between weak (WantedBy, Wants) and strong (RequiredBy, Requires) requirements. If a DE is properly configured, it should have all its core services defined as strong requirements and graphical-session.target should receive "started" status only after all of those have started. Meanwhile, the Sunshine unit is defined as a weak requirement and will not keep graphical-session.target from moving to a "started" state, allowing us to initialize Sunshine's after graphical-session.target has finished starting up, even when both are activated at the same time.

The obvious catch is that this relies on DE unit configurations and programs behaving-well. If units report initialization before the actual programs are ready, or if the units have poorly configured requirements, things won't work well. For such cases, I've included a ExecStartPre startup delay that you can use to give your system some additional time to start things up.

rockerbacon avatar Oct 21 '23 19:10 rockerbacon

It seems this issue hasn't had any activity in the past 90 days. If it's still something you'd like addressed, please let us know by leaving a comment. Otherwise, to help keep our backlog tidy, we'll be closing this issue in 10 days. Thanks!

LizardByte-bot avatar Jan 20 '24 10:01 LizardByte-bot

This issue was closed because it has been stalled for 10 days with no activity.

LizardByte-bot avatar Jan 30 '24 10:01 LizardByte-bot

It seems this issue hasn't had any activity in the past 90 days. If it's still something you'd like addressed, please let us know by leaving a comment. Otherwise, to help keep our backlog tidy, we'll be closing this issue in 10 days. Thanks!

im having this issue now too, is there a fix to this? running on default fedora41

kepl3r45 avatar Feb 05 '25 21:02 kepl3r45

Also experiencing this issue on Pop OS 22.04

Josef-Thorne-A avatar Feb 11 '25 01:02 Josef-Thorne-A

Same under Ubuntu 24.04 installed via deb file, following the guide with sudo setcap cap_sys_admin+p $(readlink -f $(which sunshine)) Also in the guide for ubuntu it says

sudo dpkg -i ./sunshine-{distro}-{distro-version}-{arch}.deb But this won't install the dependencies which are not bundled. Easier to intall via apt..

OdinsEntropy avatar Sep 06 '25 12:09 OdinsEntropy

Looking further in this issue and checking the service, I guess the issue is that the service

user@Ubu24:~$ cat /usr/lib/systemd/user/sunshine.service 
[Unit]
Description=Self-hosted game stream host for Moonlight
StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
# Avoid starting Sunshine before the desktop is fully initialized.
ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/sunshine

Restart=on-failure
RestartSec=5s

[Install]
WantedBy=xdg-desktop-autostart.target

but checking xdg-desktop-autostart.target :

user@Ubu24:~$ systemctl --user status xdg-desktop-autostart.target
○ xdg-desktop-autostart.target - Startup of XDG autostart applications
     Loaded: loaded (/usr/lib/systemd/user/xdg-desktop-autostart.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

so changing to graphical-session.target works I guess

user@Ubu24:~$ cat /usr/lib/systemd/user/sunshine.service 
[Unit]
Description=Self-hosted game stream host for Moonlight
StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
# Avoid starting Sunshine before the desktop is fully initialized.
ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/sunshine

Restart=on-failure
RestartSec=5s

[Install]
#WantedBy=xdg-desktop-autostart.target
WantedBy=graphical-session.target

I guess checking with systemctl --user list-units --type=target --all if graphical-session.target is loaded should be checked

OdinsEntropy avatar Sep 06 '25 13:09 OdinsEntropy

Having this issue on mint cinnamon

JacksonKerr avatar Sep 14 '25 00:09 JacksonKerr

graphical-session.target caused my session stop on start (Arch, GNOME Wayland) This unit file worked for me perfectly:

[Unit]
Description=Self-hosted game stream host for Moonlight
StartLimitIntervalSec=500
StartLimitBurst=5
After=graphical-session.target

[Service]
ExecStart=/usr/bin/sunshine
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=default.target

You can override current file by running systemctl --user edit sunshine.service and paste following text to make it work like above unit:

[Unit]
After=graphical-session.target

[Service]
ExecStartPre=

[Install]
WantedBy=
WantedBy=default.target

Nik-mmzd avatar Sep 26 '25 08:09 Nik-mmzd

Simplest solution I was able to do after 1h30 of trial and error:

SOLUTION for Ubuntu/Wayland startup issues:

In Startup Applications, use this command: bash -c "sleep 2 && /usr/bin/sunshine"

This gives Wayland 2 seconds to initialize before Sunshine tries to access the display. No systemd configuration needed - just works.

Tested on Ubuntu 24.04 with Wayland.

CaravelaLabs avatar Feb 15 '26 12:02 CaravelaLabs