Search code examples
macososx-maverickslaunchdgitblitlaunch-daemon

Creating a LaunchDaemon for Gitblit


I want to create a LaunchDaemon on OSX Mavericks for my Gitblit, this is my file (org.gitblit.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>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>org.gitblit.plist</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/java</string>
      <string>--baseFolder</string>
      <string>data</string>
      <string>-jar</string>
      <string>/Applications/gitblit/gitblit.jar</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

It's not working, but when I try java -jar gitblit.jar --baseFolder data on /Applications/gitblit everything works fine. Am I missing something?


Solution

  • The Gitblit GO distribution comes with a shell script gitblit.sh that will work for this purpose. This is the version of the LaunchAgent plist ~/Library/LaunchAgents/org.gitblit.plist I used.

    Note the addition of the WorkingDirectory key, as well as log files in case of errors.

    <?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>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>org.gitblit.plist</string>
        <key>ProgramArguments</key>
        <array>
          <string>/bin/bash</string>
          <string>/Applications/gitblit/gitblit.sh</string>
        </array>
        <key>WorkingDirectory</key>
        <string>/Applications/gitblit/</string>
        <key>RunAtLoad</key>
        <true/>
        <key>StandardOutPath</key>
        <string>/Applications/gitblit/stdout.txt</string>
        <key>StandardErrorPath</key>
        <string>/Applications/gitblit/sterr.txt</string>
      </dict>
    </plist>