Instiki
Launch at Startup

If you have an active public wiki, you might want to ensure that Instiki launches at startup.

MacOSX

Under MacOSX 10.4 and later, the launchd dæmon is the preferred method for starting and stopping dæmon processes, such as this one. Here’s a script, which you should save as /Library/LaunchDaemons/instiki.plist .

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
     <key>Label</key>
     <string>org.instiki</string>
     <key>UserName</key>
     <string>instiki</string>
     <key>OnDemand</key>
     <false/>
     <key>RunAtLoad</key>
     <true/>
     <key>ProgramArguments</key>
     <array>
           <string>/path/to/Instiki/directory/instiki</string>
     </array>
     <key>EnvironmentVariables</key>
     <dict>
          <key>PATH</key>
          <string>/sw/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
     </dict>
     <key>ServiceDescription</key>
     <string>Instiki Wiki</string>
</dict>
</plist>

Note, as discussed in the Security notes, I created a special, unprivileged, user, ”instiki” under which to run Instiki. Adjust this, and the full path to the instiki executable, accordingly. Also, I’ve assumed that you’re using the version of ruby from Fink. If not, you’ll have to adjust the PATH environment variable, accordingly.

Instiki will now automatically launch on startup. You can explictly stop Instiki with

  % sudo launchctl unload /Library/LaunchDaemons/instiki.plist

and restart it with

  % sudo launchctl load /Library/LaunchDaemons/instiki.plist

If, instead of WEBRick, you want to run Mongrel as your webserver, only a few details of the launchd script change.

Linux

Dæmons are started by scripts in /etc/init.d . Here’s a suitable script for Instiki.

#!/bin/bash
. /etc/rc.d/init.d/functions

PROC=/path/to/Instiki/directory/instiki
USER=instiki

PATH="/sbin:/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
export PATH
LOCK=/var/lock/subsys/instiki
RETVAL=0

[ -x $PROC ] || exit 0

start() {
        # Check if it is already running
        if [ ! -f $LOCK ]; then
            echo -n $"Starting Instiki: "
            daemon --user=$USER $PROC --daemon
            RETVAL=$?
            [ $RETVAL -eq 0 ] && touch $LOCK
            echo
        fi
        return $RETVAL
}

stop() {
        echo -n $"Stopping Instiki: "
        pkill -f -u $USER $"ruby $PROC --daemon"
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f $LOCK
        echo
        return $RETVAL
}

restart() {
        stop
        start
}       

case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        restart
        ;;
condrestart)
        if [ -f $LOCK ]; then
            restart
        fi
        ;;
status)
        pgrep -f -u $USER $"ruby $PROC --daemon" | status -p - instiki
        ;;
*)
        echo $"Usage: $0 {start|stop|status|restart|condrestart}"
        exit 1
esac

exit $RETVAL

Again, you’ll have to customize the PATH and USER variables.