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:
- Install Scrypted by following the Mac: Command Line Installation docs
- 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:
- Enable
AutomountDisksWithoutUserLogin
with the commandsudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true
- 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.
When implementing that last #2 in the Bonus section, be sure to use the current version of node that Scrypted is using.