Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattleiphamellis/3255427f93f3217beec0eb8bad4a0989 to your computer and use it in GitHub Desktop.
Save mattleiphamellis/3255427f93f3217beec0eb8bad4a0989 to your computer and use it in GitHub Desktop.
Allow Scrypted for macOS to run at boot as a background service (pre-login) via Launch Daemon

Scrypted for macOS can currently be installed as a Desktop application or background service that runs automatically on login as a user-level Launch Agent. If the system reboots or the user is logged out, however, Scrypted is unavailable until the user logs back in. These instructions allow Scrypted to run at boot without any user logged in.

Prerequisites:

  1. Install Scrypted by following the Mac: Command Line Installation docs
  2. Verify that Scrypted runs automatically at login

Terminal commands to enable launch at boot:

launchctl unload ~/Library/LaunchAgents/app.scrypted.server.plist
sudo cp ~/Library/LaunchAgents/app.scrypted.server.plist /Library/LaunchDaemons/
sudo mv ~/Library/LaunchAgents/app.scrypted.server.plist ~/.Trash/
sudo launchctl load /Library/LaunchDaemons/app.scrypted.server.plist

If you receive a permissions error upon running the last command, correct the file permissions:

sudo chown root:wheel /Library/LaunchDaemons/app.scrypted.server.plist

To test, reboot your Mac and verify that Scrypted server is available prior to logging in.

Security notes: After following these steps, Scrypted runs similarly to Homebridge's hb-service implementation, with node and the scrypted processes running as the local user rather than root.

To verify process ownership pre-login, open the Scrypted Management Console and use its Terminal function to run the following command:

ps -ej

You should find that the Scrypted services are running as the local user you installed them from.

##Updates

Terminal commands to run following Scrypted updates that change the contents of app.scrypted.server.plist:

sudo launchctl unload /Library/LaunchDaemons/app.scrypted.server.plist
sudo mv /Library/LaunchDaemons/app.scrypted.server.plist ~/.Trash/
sudo cp ~/Library/LaunchAgents/app.scrypted.server.plist /Library/LaunchDaemons/
sudo mv ~/Library/LaunchAgents/app.scrypted.server.plist ~/.Trash/
sudo launchctl load /Library/LaunchDaemons/app.scrypted.server.plist

Bonus: While my use of Scrypted does not require access to external storage, you can follow these additional steps to allow for access to the external storage pre-login:

  1. Enable AutomountDisksWithoutUserLogin with the command sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true
  2. Add an entry for node (/opt/homebrew/Cellar/node@16/16.20.2/bin/node) to System Settings > Privacy & Security > Full Disk Access (NOTE: Be sure this path is to the current version of node in use by Scrypted!)

Thanks to the Scrypted developer Koushik Dutta for creating such a useful product and asking about external disk support on the Scrypted Discord, as well as to John Benninghoff for a great summary of the AutomountDisksWithoutUserLogin setting and inspiring me to write this one up. Kudos to @jlg89 for their comment about node paths in the bonus section.

@jlg89
Copy link

jlg89 commented Sep 24, 2024

When implementing that last #2 in the Bonus section, be sure to use the current version of node that Scrypted is using.

@mattleiphamellis
Copy link
Author

When implementing that last #2 in the Bonus section, be sure to use the current version of node that Scrypted is using.

Great catch, thank you! I'll add a note to the gist.

@gh0sti
Copy link

gh0sti commented Nov 10, 2024

@mattleiphamellis just got an m4 mini and installed scrypted via terminal however I keep getting the input/output error. Any thoughts on fixing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment