Search code examples
macosnode.jsbashlaunchd

Launchd plist running a bash script that calls a node process is exiting with status code 8


Here is my launchd playlist

   <?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.blockjunk.server.plist</string>
        <key>ProgramArguments</key>
        <array>
          <string>/Users/jeff/scripts/nojunkweb/startserver.sh</string>
        </array>
        <key>RunAtLoad</key>
          <true/>
        <key>KeepAlive</key>
          <true/>
    </dict>
    </plist>

And here is startserver.sh that it is calling

#!/bin/bash

echo "Attempting to start node server"
/usr/local/bin/node /Users/jeff/scripts/nojunkweb/server.js "http://dynamic.xkcd.com/random/comic/" "https://www.shortcutfoo.com/app/drills" "https://www.duolingo.com" "http://stackoverflow.com"

launchctl list shows error code 8 for com.blockjunk.server.plist - does anyone know status code 8 means or what I might be doing wrong?

Here's the permissions on startserver.sh -rwxr-xr-x 1 jeff staff 248B Feb 6 10:16 startserver.sh

The plist is in ~/Library/LaunchAgents/


Solution

  • I needed to put the plist in /Library/LaunchDeamons to run it as root because the node process needed root access.