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,619
  • 13
  • 31
  • 36
emd
  • 163
  • 1
  • 4
  • Have you tried making a script of some sort that automatically launches said java program on startup? – Ben Franchuk Oct 28 '13 at 03:00
  • Don't Mac OS allows you to launch program at start up? (At user login to be exact) - System Preferences - Users & Groups - Click on your name, and on the right hand side, click on "Login Items" tab, and you can add your startFS.sh in there. – Darius Oct 28 '13 at 04:41

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
  • 40,894
  • 7
  • 119
  • 157
  • I will check what my plist file looks like (I'm at work and don't have access to home machine) but I think it looks like that (created from Lingon X). – emd Oct 28 '13 at 15:20