6

I want to launch a java program (server program) at computer startup. I can run it from the command line perfectly.

I created /Library/Server/startFS.sh. The file is executable by root and contains:

cd /Library/Server/FiloSync
/usr/bin/java -jar /Library/Server/FiloSync/filosync-server-latest.jar -p 7000 -s 7001

I can't get my launchd .plist included here, the formatting is all off.

I can run it fine from the command line: ./startFS.sh, but when I put create the plist (via Lingon), nothing happens.

Now, when run, it outputs a few lines to the console. Might that be problem?

I have tried prepending nohup and appending &, but no combination seems to work.

Jawa
  • 3,679
emd
  • 163
  • 1
  • 4

1 Answers1

6

Save a property list like this as /Library/LaunchAgents/some.label.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>some.label</string>
  <key>ProgramArguments</key>
  <array>
    <string>java</string>
    <string>-jar</string>
    <string>/Library/Server/FiloSync/filosync-server-latest.jar</string>
    <string>-p</string>
    <string>7000</string>
    <string>-s</string>
    <string>7001</string>
  </array>
  <key>RunAtLoad</key>
  <true/> <!-- run the program at login -->
  <key>KeepAlive</key>
  <true/> <!-- run the program again if it terminates -->
  <key>WorkingDirectory</key>
  <string>/Library/Server/FiloSync</string>
</dict>
</plist>

Make sure the file is owned by root. If it is not, it can be loaded without sudo, but it is not loaded automatically at login. Then log out and back in to test if the program was started.

For more information, see man launchd.plist, the Daemons and Agents tech note, or http://osxnotes.net/launchd.html.

Lri
  • 42,502
  • 8
  • 126
  • 159