Page 1 of 1

Automatic startup on OS X using launchd

PostPosted: Fri May 01, 2009 5:45 am
by dobson
There have been a couple threads about running subsonic automatically on linux, but no one has mentioned starting subsonic automatically on OS X at boot as a launchd job. I don't know if this is the best way, or even a good way (suggestions encouraged!), but it seems to work fine for me. It's not too fancy, but having not found it in this forum, I figured I'd post it.

create the following text file, name it "com.subsonic.start.plist", and place it in /Library/LaunchDaemons/
Code: Select all
<?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>com.subsonic.start</string>
   <key>ProgramArguments</key>
   <array>
      <string>sudo</string>
      <string>/var/subsonic/standalone/subsonic.sh</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>

PostPosted: Wed May 27, 2009 5:37 am
by rattboi
This actually didn't work for me. I compared to some other .plists in that folder, and none are using sudo, and I'm pretty sure anything run from /Library will be run by the root process anyways, giving it root priviledges. I haven't restarted yet after removing "sudo", but I hope this will fix it.

Also, when I first start subsonic.sh manually, the server starts fine, but when I actually log in and it starts showing album art, I get a new icon in my dock, which says "net.sourceforge.subsonic.booter.Main" when I go over it. Any idea how to hide this?

PostPosted: Wed May 27, 2009 4:02 pm
by dobson
yeah, I wasn't sure if the sudo was necessary, but I was having trouble without it, so I included it and things worked smoothly for me. if it works fine for you without it though, let us know.

I also get the net.sourceforge.subsonic.booter.Main icon in my dock. not sure how to hide it, but would be curious.

PostPosted: Wed Nov 24, 2010 3:48 pm
by Eid
Has anyone had any luck with this?

I downloaded the standalone version and installed it to /var/subsonic
Code: Select all
ls -al /var/subsonic/
total 76272
drwxr-xr-x  20 root  wheel       680 Nov 24 16:39 .
drwxr-xr-x  27 root  wheel       918 Nov 24 14:50 ..
-rw-r--r--@  1 root  wheel      3003 Nov 24 15:23 Getting Started.html
-rw-r--r--@  1 root  wheel     35819 Nov 24 15:23 LICENSE.TXT
-rw-r--r--@  1 root  wheel       540 Nov 24 15:23 README.TXT
drwxr-xr-x   8 root  wheel       272 Nov 24 16:39 db
drwxr-xr-x   3 root  wheel       102 Nov 24 15:28 jetty
drwxr-xr-x   5 root  wheel       170 Nov 24 15:28 lucene
drwxrwxrwx   1 root  wheel        36 Nov 24 15:25 music
drwxrwxrwx   9 root  wheel       306 Nov 24 15:26 playlists
-rw-r--r--@  1 root  wheel  10802845 Nov 24 15:23 subsonic-booter-jar-with-dependencies.jar
-rwxr-xr-x@  1 root  wheel       923 Nov 24 15:23 subsonic.bat
-rw-r--r--   1 root  wheel    188150 Nov 24 16:45 subsonic.log
-rw-r--r--   1 root  wheel       376 Nov 24 16:39 subsonic.properties
-rwxr-xr-x   1 root  wheel      4685 Nov 24 15:27 subsonic.sh
-rw-r--r--@  1 root  wheel  25494593 Nov 24 15:23 subsonic.war
-rw-r--r--   1 root  wheel   2472272 Nov 24 15:30 subsonic12.index
-rw-r--r--   1 root  wheel     19558 Nov 24 16:45 subsonic_sh.log
drwxr-xr-x   6 root  wheel       204 Nov 24 15:36 thumbs
drwxr-xr-x   2 root  wheel        68 Nov 24 15:28 transcode


I then went and made the following:
Code: Select all
cat /Library/LaunchDaemons/com.subsonic.start.plist
<?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>com.subsonic.start</string>
   <key>username</key>
   <string>root</string>
   <key>RootDirectory</key>
   <string>/var/subsonic</string>
   <key>ProgramArguments</key>
   <array>
      <!--<string>sudo</string>-->
      <string>/var/subsonic/subsonic.sh</string>
   </array>
   <key>OnDemand</key>
   <false/>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>


• When I start up then subsonic is not loaded.
• If I go to the command line and execute sudo /var/subsonic/subsonic.sh everything starts fine
• Yes the 1st launchd file I used was a copy of the one in this thread.

Many thanks, Eid

PostPosted: Fri Dec 10, 2010 6:36 pm
by TheGunslinger
I did get this working...to a point. I am running the standalone version on a 10.5.8 PPC. The issue seems to be that launchctl wants to be in control so once the script passes off process it will quit it. Meaning once Java takes over then launchctl has nothing to run so it kills the process.

The LaunchDaemon I have come up with that works looks like this:

Code: Select all

<?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>com.subsonic.serverStart</string>
        <key>WorkingDirectory</key>
        <string>/var/subsonic/standalone/</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/java</string>
                <string>-Xmx100m</string>
                <string>-Dsubsonic.home=/var/subsonic</string>
                <string>-Dsubsonic.host=0.0.0.0</string>
                <string>-Dsubsonic.port=4040</string>
                <string>-Dsubsonic.contextPath=/</string>
                <string>-Dsubsonic.defaultMusicFolder=/var/music</string>
                <string>-Dsubsonic.defaultPodcastFolder=/var/music/Podcast</string>
                <string>-Dsubsonic.defaultPlaylistFolder=/var/playlists</string>
                <string>-jar</string>
                <string>/var/subsonic/standalone/subsonic-booter-jar-with-dependencies.jar</string>
        </array>
        <key>StandardOutPath</key>
        <string>/dev/null</string>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>



The downfall to this is that you have to manually change this file to adjust the amount of memory and all of the other variables that you can set by using the script.

A word of caution, though. If you use this as a LaunchDaemon so that it runs on machine boot rather than a LaunchAgent which will run when a user logs in, most of the album art will not be displayed. This is because an untrusted application is not allowed to run before the Window Server is launched, which happens at login. You will see an error in the system logs similar to this:
<Warning>: 3891612: (connectAndCheck) Untrusted apps are not allowed to connect to or launch Window Server before login.


followed by
[btpool0-15] WARN org.mortbay.log - /coverArt.view: java.io.IOException: Failed to create thumbnail for.....


I haven't found a workaround for that yet other than to have a user auto-login on the server which then launches Subsonic from a LaunchAgent. It kind of defeats the purpose and if you don't care about the cover art then this will work ok for you.

PostPosted: Fri Dec 10, 2010 8:38 pm
by TheGunslinger
I think I have this working now.

Copy the contents below and place in file called com.subsonic.serverStart.plist. Place this file in /Library/LaunchAgents/

Code: Select all
<?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>com.subsonic.serverStart</string>
        <key>WorkingDirectory</key>
        <string>/var/subsonic/standalone/</string>
        <key>LimitLoadToSessionType</key>
        <array>
                <string>StandardIO</string>
                <string>LoginWindow</string>
                <string>Aqua</string>
        </array>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/java</string>
                <string>-Xmx256m</string>
                <string>-Dsubsonic.home=/var/subsonic</string>
                <string>-Dsubsonic.host=0.0.0.0</string>
                <string>-Dsubsonic.port=4040</string>
                <string>-Dsubsonic.contextPath=/</string>
                <string>-Dsubsonic.defaultMusicFolder=/var/music</string>
                <string>-Dsubsonic.defaultPodcastFolder=/var/music/Podcast</string>
                <string>-Dsubsonic.defaultPlaylistFolder=/var/playlists</string>
                <string>-jar</string>
                <string>/var/subsonic/standalone/subsonic-booter-jar-with-dependencies.jar</string>
        </array>
        <key>StandardOutPath</key>
        <string>/dev/null</string>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>


In my limited testing, using it this way will allow the Java Applet to interact with the window server at the loginwindow level, the console level and when a user logs in. The downside that I can see is that in theory, when you change session types, the server will stop itself and then reload in the appropriate session. In my case this is fine as there aren't that many people using my system so they most likely notice that the server resets unless they are asked to log back in.

Not perfect, but better than nothing!

Approach wrong

PostPosted: Mon Jan 03, 2011 3:30 pm
by thatdudesnotright
I think your approaching this wrong.

From what I understand you need to put this stuff in

/Library/StartupItems

Upon boot rc.boot will check this folder and run the scripts in it.

You should be able to put a script that launches the app and poof. Will test tonight.

you should be able to just drop the entire app in that folder and it should start up on boot. But it will run as root, so you need to make sure the folders are owned by root etc.

PostPosted: Tue Apr 26, 2011 6:42 am
by joelbrave
The easy way: download lingon 1.2.1 (the last free version) and create a runAtLoad User Daemon. For Standalone on OS X 10.4, I used:
Lable: Subsonic

and
/var/subsonic/./subsonic.sh as the program arguments

I couldn't get any of the other suggestions in this thread to work on my system... Don't know if this will work on later versions of OS X, but probably would require the pay version of Lingon...

- Joel