I'm trying to set up YouTrack on OS X Lion Server and have it launch at boot using launchd
. I have downloaded the YouTrack jar file which I can successfully run from the command line using java -Xmx512m -jar youtrack.jar 8080
. I have also wrapped said run command in a shell script similar to this which basically lets me interact with the active instance using youtrack start
and youtrack stop
. It stores the process id of the java
process in a file and the exits in order to be able to stop a running instance, allowing only one instance etc.
In order to run this command at boot time I have created a simple launchd plist and placed it in /Library/LaunchDaemons, as per the instructions given in man launchd.plist
. The principal keys used are ProgramArguments
(youtrack start
) and RunAtLoad
(true). The problem is, when run form the command line youtrack start
will create a file containing the pid of the java
process, and I can see this process in top
or ps ax
. But when the command is being run by lanuchd (sudo launchctl load /Library/LaunchDaemons/org.example.youtrack.plist
) the resulting pid will not match that of any running processes, and the YouTrack web server wont start. It's almost as if the java process started by launchd will also terminate once launchd has finished.
However, if I instead simply put the java command directly in the launchd plist it will work fine. I would simply like to understand why this is - I thought the while idea of launchd was to start daemons. But does that mean that the daemon must run inside launchd for its entire lifetime? Is there an alternate way of starting daemons with (or without) launchd, that would allow me simply to run a command once at boot? Basically what we used to do using @roboot
in cron
in earlier versions of OS X.