jellyfin / jellyfin-server-windows

The Windows tray app and installer for Jellyfin Server on Windows.
https://jellyfin.org
MIT License
72 stars 26 forks source link

Jellyfin delayed autostart #137

Open ThomasPGH opened 2 weeks ago

ThomasPGH commented 2 weeks ago

By default and when running as a Windows service Jellyfin is very slow to start after its hosting machine is restarted.

The culprit is this line in the installer: ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer Start SERVICE_DELAYED_AUTO_START' $0

This should be: ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer Start SERVICE_AUTO_START' $0

The value SERVICE_DELAYED_AUTO_START instead of SERVICE_AUTO_START delays its service start until all other services have started, and then enters nssm's service entry routine ServiceMain () with a value of THREAD_PRIORITY_LOWEST. See https://learn.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_delayed_auto_start_info for details.

My asumption is that the SERVICE_DELAYED_AUTO_START flag got in there by accident, as I cannot imagine that someone who runs Jellyfin as a Windows service considers anything more important than starting up Jellyfin first. I reckon that just like me most users with a setup like this have a dedicated machine for Jellyfin.

ThomasPGH commented 1 week ago

This is not required on Windows. Windows doesn't mount network attached storage. A network resource is either accessed via its UNC name (\host\share) or mapped to a drive letter.

The latter wouldn't make sense for a Windows service as this mapping is only valid for the user who created the mapping. If the software runs as a service it won't see the drive letter because the account the service runs as hasn't got it, independent on how long the service start is delayed.

A UNC share is connected to the moment it is opened. Windows might have to start other (system) services first for this to happen but that's the system's responsibility within the opening API call, for instance CreateFile (). This process is entirely hidden from an application.

Microsoft gives the reason for using SERVICE_DELAYED_AUTO_START as "The service control manager (SCM) supports delayed auto-start services to improve system performance at boot time without affecting the user experience."

This reason doesn't hold up for users running Jellyfin as a Windows service, because if it did, they'd run the software as a tray application. For whoever runs Jellyfin via nssm there's nothing more important than firing both up as soon and as quickly as possible.