Scripts for running headless on OS X
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Scripts for running headless on OS X
I figured out how to to this last night, so I thought I'd share it with the class 
First, I wanted to be able to run the server under an unprivileged account, but without needing to log in or have the menubar icon appear. At the same time though, I wanted to preserve the ability to run the application directly to more easily tweak the settings.
So, first, I installed UMS to ~/Applications instead of /Applications, and I renamed it to UMS.app. Not having spaces in the name made writing the shell script much easier. I've attached the two files you'll need (remove the txt extenstion when copying them): net.pms.ums.plist goes in /Library/LaunchDaemons and UMS.sh (this isn't the same script as the UMS.sh in the code repo) goes in ~/Applications/UMS.app/Contents/Resources/Java. You could put the shell script somewhere else, but it made sense to keep it with the app.
After putting those two files in their place (using sudo to cp the file to /Library/LaunchDaemons), you'll need to edit both of them and change 'unprivileged' to the name of your user account/user home dir where appropriate. In addition, you'll see the following snippet in the plist file:
You'll need to change 'en0' to whatever your primary NIC is. This is intended for use on servers, so en0 is probably what you want. This bit of bash script ensures that the network interface is loaded, and will wait until it is before starting UMS. Having the wrong thing here will mean UMS will never load.
If this is a fresh UMS install, go ahead and run it directly as your unprivileged user and configure it appropriately. Once that's done, shut down the server. Then run the following command:
This will start your server headless, as well as configure it to load on boot in this fashion. You can use ps to verify that it's running, or you can check ~/Applications/UMS.app/Contents/Resources/Java/debug.log.

First, I wanted to be able to run the server under an unprivileged account, but without needing to log in or have the menubar icon appear. At the same time though, I wanted to preserve the ability to run the application directly to more easily tweak the settings.
So, first, I installed UMS to ~/Applications instead of /Applications, and I renamed it to UMS.app. Not having spaces in the name made writing the shell script much easier. I've attached the two files you'll need (remove the txt extenstion when copying them): net.pms.ums.plist goes in /Library/LaunchDaemons and UMS.sh (this isn't the same script as the UMS.sh in the code repo) goes in ~/Applications/UMS.app/Contents/Resources/Java. You could put the shell script somewhere else, but it made sense to keep it with the app.
After putting those two files in their place (using sudo to cp the file to /Library/LaunchDaemons), you'll need to edit both of them and change 'unprivileged' to the name of your user account/user home dir where appropriate. In addition, you'll see the following snippet in the plist file:
Code: Select all
if [[ `/usr/sbin/scutil -w State:/Network/Interface/en0/IPv4 -t 0` -eq 0 ]]; then exec ...
If this is a fresh UMS install, go ahead and run it directly as your unprivileged user and configure it appropriately. Once that's done, shut down the server. Then run the following command:
Code: Select all
sudo launchctl load -w /Library/LaunchDaemons/net.pms.ums.plist
- Attachments
-
UMS.sh.txt
- bash script to start UMS in headless mode
- (3.41 KiB) Downloaded 435 times
-
net.pms.ums.plist.txt
- launchd property list file
- (765 Bytes) Downloaded 507 times
Re: Scripts for running headless on OS X
One caveat to this is that if you log in on the Mac with your unprivileged account, logging out will shut down UMS. OS X unmounts any drives mounted by a logged-in non-root user and SIGTERMs all their processes after logging out. There used to be a way (pre-Lion) to prevent the drives from being unmounted, and I don't know of any way to prevent it from killing the processes.