Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch Server as a Service #44

Open
anthonylavado opened this issue Apr 10, 2021 · 2 comments
Open

Launch Server as a Service #44

anthonylavado opened this issue Apr 10, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@anthonylavado
Copy link
Member

Per user request, we should look at how to launch the server as a service on macOS, before login.

In restart/power outage situations, this would allow the server to start back up without user intervention.

It's been a long time since I've tried to look at anything related to launchd, so this is an opportunity to start.

@anthonylavado anthonylavado added the enhancement New feature or request label Apr 10, 2021
@ultratiem
Copy link

ultratiem commented Sep 1, 2023

This still applies: https://superuser.com/questions/930389/how-to-start-a-service-using-mac-osxs-launchctl

Creating a script is rather easy. Just need to make the proper files to toss into launchd's folders. If you want Jellyfin to do more than just launch, you'd then need to compile a daemon alongside it.

Screenshot 2023-08-31 at 5 36 26 PM

Though a user can simply add it to Open at Login to accomplish what the scripts will do. Aside from needing to run the actual app bundle.

Another option entirely is to create a modern binary that plugs into macOS's new "Allow in background".

@vgorloff
Copy link

vgorloff commented Dec 10, 2024

Here is what I did. Seems working OK.

  1. Create file $HOME/Library/LaunchAgents/XYZJellyfin.plist with contents shown below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>XYZJellyfin</string>
   <key>LimitLoadToSessionType</key>
   <array>
      <string>Aqua</string>
      <string>Background</string>
      <string>LoginWindow</string>
      <string>StandardIO</string>
      <string>System</string>
   </array>
   <key>ProgramArguments</key>
   <array>
      <string>/path/to/portable/binary/goes/here/jellyfin</string>
      <string>--datadir</string>
      <string>/opt/xyz/data</string>
      <string>--configdir</string>
      <string>/opt/xyz/config</string>
      <string>--cachedir</string>
      <string>/opt/xyz/cache</string>
      <string>--logdir</string>
      <string>/opt/xyz/logs</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
   <key>EnvironmentVariables</key>
   <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
   </dict>
   <key>WorkingDirectory</key>
   <string>/opt/xyz/Jellyfin</string>
   <key>StandardErrorPath</key>
   <string>/opt/xyz/Jellyfin/stderr.log</string>
   <key>StandardOutPath</key>
   <string>/opt/xyz/Jellyfin/stdout.log</string>
</dict>
</plist>

You may wish to replace XYZ with something useful. But you have to not only rename XYZJellyfin.plist file, but also update Label XML key <string>XYZJellyfin</string>.

  1. Bootstrap macOS service: launchctl bootstrap gui/`id -u` $HOME/Library/LaunchAgents/XYZJellyfin.plist

After this your Jellyfin instance should be reachable (as usual) via http://127.0.0.1:8096.


To stop service: launchctl kill SIGTERM gui/`id -u`/XYZJellyfin

To restart: launchctl kickstart -k -p gui/`id -u`/XYZJellyfin

To disable macOS service: launchctl bootout gui/`id -u`/XYZJellyfin

To print status: launchctl list | grep XYZ or more detail launchctl list XYZJellyfin

To print even more detailed status: launchctl print gui/`id -u`/XYZJellyfin


Using above method you can run multiple instances of Jellyfin (on different HTTP ports). The only issue I see so far: Only one server can have "Client Auto Discovery" feature enabled. Otherwize they will conflict each other. "Client Auto Discovery" feature can be disabled in a network.xml (<AutoDiscovery>false</AutoDiscovery>).

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants