Page 1 of 1
HOWTO: Using launchd on mac to start the server

Posted:
Sun Jan 24, 2010 4:21 pm
by ken
This assumes that Serviio is installed under /Applications
Save the following piece of code in a file named org.serviio.server.plist
- Code:
<?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>org.serviio.server</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Serviio.app/Contents/MacOS/JavaApplicationStub</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
and copy the file to where it will be launched on system start
- Code:
# sudo cp org.serviio.server.plist /Library/LaunchDaemons/
and to start it right away
- Code:
# sudo launchctl load /Library/LaunchDaemons/org.serviio.server.plist
and to stop it
- Code:
# sudo launchctl unload /Library/LaunchDaemons/org.serviio.server.plist
Update:
Media library update fails unless you are logged in with the GUI due to the java image library tries to connect to a window server. By adding the following property to the Info.plist found in Serviio.app/Contents the java image library works without connecting to a window server.
- Code:
<key>java.awt.headless</key>
<string>true</string>
Re: HOWTO: Using launchd on mac to start the server

Posted:
Sun Jan 24, 2010 4:30 pm
by zip
Brilliant, thanks a lot. I've added link to this thread to FAQ.
Re: HOWTO: Using launchd on mac to start the server

Posted:
Wed Mar 24, 2010 2:05 pm
by sea
Heya,
I tried this tip, and after a few warnings about it skipping due to 'spurious ownership' which I fixed with chown and chgrp, I get the following:
> sudo launchctl load /Library/LaunchDaemons/org.serviio.server.plist
launchctl: propertyList is NULL
launchctl: no plist was returned for: /Library/LaunchDaemons/org.serviio.server.plist
launchctl: no plist was returned for: /Library/LaunchDaemons/org.serviio.server.plist
nothing found to load
I'm on 10.5.8, has launchctl changed substantially for, say, snow leopard? Serviio is in /Applications, and I've coped the file exactly as it is in the original post.
Any help appreciated!
sea
Re: HOWTO: Using launchd on mac to start the server

Posted:
Wed Mar 24, 2010 3:35 pm
by ken
Hi,
I'm running snow leopard but I think it should be valid for Leopard as well, there's a tool you can try which checks the syntax of the plist, try this:
> plutil -lint /Library/LaunchDaemons/org.serviio.server.plist
which for me returns:
/Library/LaunchDaemons/org.serviio.server.plist: OK
Re: HOWTO: Using launchd on mac to start the server

Posted:
Thu Mar 25, 2010 1:53 pm
by sea
*facepalm*
noticed the scrollbar on the code window in the original post... was missing the closing 'plist' tag. what a silly mistake.
thanks for the speedy reply!
Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon May 30, 2011 12:34 pm
by unmyke
ken wrote:Update:
Media library update fails unless you are logged in with the GUI due to the java image library tries to connect to a window server. By adding the following property to the Info.plist found in Serviio.app/Contents the java image library works without connecting to a window server.
- Code:
<key>java.awt.headless</key>
<string>true</string>
Hi, thanks for awesome tip. I have little question: in what place on info.plist paste property "java.awt.headless" (in the root of info.plist or in the subsection "Java")?

Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon May 30, 2011 5:01 pm
by ken
I put it in the "Java>properties" sub section just after serviio.home
Re: HOWTO: Using launchd on mac to start the server

Posted:
Sun Nov 20, 2011 1:15 am
by fredblogs
If you cut and paste the code from above then you
MAY get an non-printing character in the plist file and it will fail. Check your plist using
- Code:
plutil /Library/LaunchDaemons/org.serviio.server.plist
The non-printing character is
USUALLY in the blank spaces in the indentation ... just delete the spaces and then re-indent.
Re: HOWTO: Using launchd on mac to start the server

Posted:
Sat Dec 31, 2011 7:47 pm
by Tony_tea
I'm new to DLNA but reasonably techie minded....
I got serviio running from user accounts (although it sometimes needs several passes at some directories, ESP. Music files).
So I can start it and manage it as a logged on user. Now my wife wants to use it when I'm not around (on a Sony Bravia) so I've followed the steps in this posting (including every gotcha described therein!). However it still doesn't work until I log-in and often not even then. The program seems to be running but it's not visible on any of my devices.
If I remove the .plist file it reverts to normal behaviour (I.e. requires a user to lo be logged in and run Serviio.app)
I notice that when I start either Serviio or the console I'm asked to agree to receive incoming network messages. Obviously it's not possible to do this on a background account. Might this be my problem?
I'm running OS X Lion on a 24" dual core iMac
Thanks for any advice...
Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon May 28, 2012 10:30 am
by Manuel Martensen
zip wrote:Brilliant, thanks a lot. I've added link to this thread to FAQ.
Couldn’t this be implemented to be the default kind of installation? If one (I suppose at least 99 of 100 users) installs a DLNA server he wants it running all the time, no?
Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon May 28, 2012 5:56 pm
by zip
Manuel Martensen wrote:zip wrote:Brilliant, thanks a lot. I've added link to this thread to FAQ.
Couldn’t this be implemented to be the default kind of installation? If one (I suppose at least 99 of 100 users) installs a DLNA server he wants it running all the time, no?
I am not so sure.
Re: HOWTO: Using launchd on mac to start the server

Posted:
Tue Jun 05, 2012 4:33 pm
by Deej
I followed the instructions in this thread... and I'm running into issues. The only thing I did not do was edit the Info.plist file with the headless setting, as I see it already in there.
- Code:
<key>VMOptions</key>
<string>-Xmx384m -Xms20M -XX:+UseParNewGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20</string>
<key>Properties</key>
<dict>
<key>java.awt.headless</key>
<string>true</string>
<key>serviio.home</key>
<string>$JAVAROOT</string>
<key>derby.system.home</key>
<string>$JAVAROOT/library</string>
<key>file.encoding</key>
<string>UTF-8</string>
<key>java.net.preferIPv4Stack</key>
<string>true</string>
</dict>
My symptoms: I can see the serviio server on all devices after a reboot without logging in. After waiting for movie lists to load (I have a very large digital library - it takes a while), I can see all the movies listed. However, for at least the Samsung and the Sony devices, I get an "unsupported file type" error when trying to play the movies. I can log into the Mac server, and restart Serviio services, and after a waiting period for things to start, the same movies will play on those devices without any issues. It's like the transcoder does not work when not logged in (or at least that's my understanding of how it works, and I could be wrong in terminology).
The only thing I see in the system.log file that may be related (don't really know what I'm looking for) is:
- Code:
Jun 5 10:08:59 SiFiMac com.apple.mdworker.pool.0[403]: I/O error : encoder error
Jun 5 10:12:51 SiFiMac com.apple.mdworker.pool.0[403]: I/O error : encoder error
Jun 5 10:14:03: --- last message repeated 3 times ---
My configuration is a iMac running Mac OS X 10.7.4. All devices run on the wireless network.
I have tried other DLNA servers, including TVMobli and the beta of Plex... and these 2 devices (Samsung and Sony) do have transcoding issues with my .m4v movie files (.mp4 format, with .m4v extensions - for AppleTV and other IOS devices). Serviio is the only DLNA server I've tried that supports all the devices in my house without any special tweaking, and it would be great if I can get this to run at boot with no user logged in.
Any help is appreciated. Thank you!
Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon Jul 30, 2012 11:01 pm
by jaydisc
This is awesome. Thank you very much.
BUT THIS IS ALSO DANGEROUS! You are running Serviio as root!
I recommend adding a username key to the plist. I have an underprivileged user on my system named Anyone that has access to the media folders, so my key looks like this
<key>UserName</key>
<string>Anyone</string>
In place, that looks like this:
- Code:
<?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>org.serviio.server</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Serviio.app/Contents/MacOS/JavaApplicationStub</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>anyone</string>
</dict>
</plist>
Re: HOWTO: Using launchd on mac to start the server

Posted:
Thu Aug 30, 2012 10:26 am
by TwelveMonkeys
Hi,
one thing I've stumbled across: If you start Serviio as a service, then log in to your mac as a user and log out again, Serviio stops. After some testing I found this quick and dirty workaround:
- wrote a script "serviio.sh":
------------------snip---------------
# check if Serviio.app is running
# since the "grep" - command returns one line for itself, the number of hits is "2" if Serviio.app is running.
if [ "`ps -ef | grep -c Serviio.app`" -ne 2 ]
then
# it happend once that launchctl reported that org.serviio.server.plist was already loaded, even though Serviio.app didn't show up
# in the process list. So it's safer to unload the plist first, then load it.
launchctl unload /Library/LaunchDaemons/org.serviio.server.plist 2>/tmp/serviio.err 3>&2
launchctl load /Library/LaunchDaemons/org.serviio.server.plist 2>/tmp/serviio.err 3>&2
fi
------------------------------------.
- created file "org.mw.serviio.plist" in the /Library/LaunchDaemons
-----------------snip---------------
<?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>org.mw.serviio</string>
<key>ProgramArguments</key>
<array>
<string>/Users/admin/serviio.sh</string>
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>10</integer>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/serviio.err</string>
<key>StandardOutPath</key>
<string>/tmp/servio.out</string>
</dict>
</plist>
--------------------------------------
This calls the shell script every 10 seconds, thus creating a watchdog that restarts the Serviio service.
Be aware that all that stuff is run as root, so check the file permissions.
Test the shell script with " sh -xv servo.sh" first to see if all is working.
Now I'm looking for a way to force a file refresh via shell script, since the update doesn't seem to work all the time...
Cheers, Mal
Re: HOWTO: Using launchd on mac to start the server

Posted:
Tue Oct 02, 2012 12:05 am
by torpidlittle
Thank you all for this great tip !!! Very appreciated !
It also solved my issue with Serviio not closing when rebooting my iMac
Torpidlittle
Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon Jan 28, 2013 1:36 pm
by chris0071
Hi,
I am a nube when it comes to coding. I tried to make a .plist file out of xcode, then I entering the code with TextEdit and saved it, I renamed the file properly and put it in the right folder, Then I executed the sudo comand to start the server on startup, but it says that it cant find the file and that the folder is empty. I am running Mac OS 10.6.8 if that is of any help.
It would be greatly appreciated if somebody could give me a hand with this.
Chris
Re: HOWTO: Using launchd on mac to start the server

Posted:
Tue Apr 02, 2013 12:18 am
by awb
I can't get the service to load automatically on boot. The .plist file is in the LaunchDaemons folder and the "RunAtLoad" flag is set to true. I can load it manually using launchctl, but it won't start on its own. Anyone have any idea why it might work manually but not automatically? I'm on Mountain Lion 10.8.3.
For the time being, I am using an AppleScript that runs the launchctl command, and I have set it to a login item. But that may not always suit my purposes. In the future, I may want to run the service as root on a system with multiple users so that it will stay open when someone logs out. How do I do this?
-----------------------------------------------------------
@chris0071 - TextEdit may be set to save in Rich Text Format. When interpreted as Unicode text (notice "UTF-8" in line 1 of the .plist file), the text will be interpreted incorrectly and may not be recognized as a legitimate .plist file. You can tell whether this is the case if, when opened in TextEdit, formatting toolbars appear at the top of the window (rtf allows for the inclusion of text formatting instructions). Another giveaway of this would be if TextEdit requires that the "rtf" extension be used when saving.
To be sure, use the aforementioned "plutil" command:
plutil /Library/LaunchDaemons/org.serviio.server.plist
It will probably say something like "unexpected character" and will most likely get tripped up on a "{" in line 1 that denotes formatting instructions and isn't visible to you in the text window.
If this is your problem, then there should be an option somewhere in the TextEdit menus (probably under an "Edit" or "Formatting" menu or something) that allows you to convert to plain text. Hit that and resave (default extension should now be "txt"). Rename the extension to .plist.
Now when you run the "plutil" command, the file should be reported as "OK"
-----------------------------------------------------------
SOLVED:
It was an ownership issue. The .plist file must be owned by root to be launched from the LaunchDaemons folder on boot. Changing ownership of a file can be done using "chown" as root. However, following @ken's original instructions will set the proper ownership, namely this line:
"sudo cp org.serviio.server.plist /Library/LaunchDaemons/"
(I dragged my file into the LaunchDaemons folder and authorized the move when prompted, which does not change the owner from my user to root.)
@TwelveMonkeys - I am not sure why you are having your logout issue unless the owner of the file is not root. I just tested mine after fixing ownership. Everything works as it should. It loads on startup as the user I designated in the file, and after logging out, the server is still running. Are you sure you're looking for the right process name? It won't show up as "Serviio", it will show up as "JavaApplicationStub".
Re: HOWTO: Using launchd on mac to start the server

Posted:
Wed Oct 02, 2013 7:22 pm
by energee
Hello,
I'm getting this when try to run the file:
nothing found to load
Any ideas?
This is my .plist file. I have the serviio app under /serviio/ dir, but i don't think it makes a difference:
<?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>org.serviio.server</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Serviio/Serviio.app/Contents/MacOS/JavaApplicationStub</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Re: HOWTO: Using launchd on mac to start the server

Posted:
Sat Jun 14, 2014 8:54 pm
by perrocallao
zip wrote:Manuel Martensen wrote:zip wrote:Brilliant, thanks a lot. I've added link to this thread to FAQ.
Couldn’t this be implemented to be the default kind of installation? If one (I suppose at least 99 of 100 users) installs a DLNA server he wants it running all the time, no?
I am not so sure.
This is awesome, we need this by default.
Re: HOWTO: Using launchd on mac to start the server

Posted:
Mon Nov 24, 2014 5:28 pm
by PaulsServiio
Hi Guys,
I've got a Sharp smart tv and just called Sharp cause my Home Network was saying Failed to connect to server, and to please check server settings.
I was told I needed my DLNA to work by installing Serviio which I did and know I'm not sure where to go from here to get my Home Network to start working.
Hopefully someone can help me out with this.
Thanks guys,
Paul