Mac OS X launchd To Keep Ghost Alive


On Mac OS X, the preferred way to start a service and to keep a service alive is launchd. The following steps will show you how to create a launchd script to start ghost when your computer starts up, and relaunch ghost if it crashes.

sudo vi /Library/LaunchDaemons/com.ghost.start.plist

Paste the following into your com.ghost.start.plist launchd (change /Ghost/ to the path to your ghost folder):

<?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>com.ghost.start</string>
            <key>ProgramArguments</key>
            <array>
                <string>/usr/local/bin/npm</string>
                <string>start</string>
                <string>/Ghost/</string>
            </array>
            <key>RunAtLoad</key>
            <true/>
    </dict>
    </plist>

Save your launchd and then load it:

sudo launchctl load -w /Library/LaunchDaemons/com.ghost.start.plist 

If you want to test, run:

sudo ps aux | grep npm | grep -v grep | kill `awk {' print $2 '}`