Instiki
How to run Instiki app as a service on Mac OS X

This was developed by John Duksta

Link to his site

After getting tired of starting Instiki by hand all the time, I finally sat down and figured out how to write launchd configs this morning. Launchd is the new way to start daemons, cron jobs and inetd style services in OS X Tiger. You’ll need to create an unpriviledged user for Instiki and give them read/write access to the storage directory. Without further ado, here is the config file.

NOTE: Note the first element of the ProgramArguments array must be the path to the program. This is because this array represents the ARGV array for C programs, where the first argument, ARGV[0], is the name of the program. If this is not done, the port information will be treated as the name.


<!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.instiki</string>
        <key>OnDemand</key>
        <false/>
        <key>Program</key>
        <string>/usr/bin/instiki</string>
        <key>ProgramArguments</key>
        <array>
               <string>/usr/bin/instiki</string>
               <string>--port=2500</string>
                <string>--storage=/Library/WebServer/Instiki</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ServiceDescription</key>
        <string>The Instiki Wiki</string>
        <key>StandardErrorPath</key>
        <string>/Library/Logs/Instiki-error.log</string>
        <key>StandardOutPath</key>
        <string>/Library/Logs/Instiki.log</string>
        <key>UserName</key>
        <string>instiki</string>
        <key>WorkingDirectory</key>
        <string>/Library/WebServer/Instiki</string>
</dict>
</plist>

There used to be some instructions on how to set it up for OS X.x where x<4>

I’ve been working on getting this rolling on Mac OS X Server 10.3.9 for some time. Prior to 10.4, OS X uses items in the /System/Library/StartupItems/ folder to start various services. Using the existing startup scripts and this article as a base, I did this:

  1. Made a directory in /System/Library/StartupItems/ called INSTIKI
  2. Inside that directory I copied an existing StartupParameters.plist and edited it slightly. You can specify service dependencies in this file, for example, if you require Apache to be started before starting Instiki.
  3. I copied a startup script from the Apache service and edited as shown below:

#!/bin/sh

##
# Instiki wiki software
##

. /etc/rc.common

StartService ()
{
    if [ "${INSTIKI:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting Instiki ..." 
        ruby /Library/WebServer/Documents/instiki-0.10.2/instiki.rb --daemon --port 2500 --storage /Library/WebServer/Documents/instiki-0.10.2/storage
        else
        NoService
        fi
}

StopService ()
{
        ConsoleMessage "The Instiki developers have not implemented auto-stopping Instiki: it cannot be killed automatically." 
        ConsoleMessage "To kill it manually, run 'top' and look for the ruby process. Find the PID number and run 'kill -2 PIDNUMBER'" 
}

RestartService ()
{
    if [ "${INSTIKI:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Reloading Instiki..." 
        StopService
        StartService
    else
        StopService
        NoService
        fi
}

NoService ()
{
        ConsoleMessage "Service is disabled in /etc/hostconfig

        Unable to start
        " 
}

RunService "$1" 

My problem is in the startup line (ruby /Library/WebServer/Documents/instiki-0.10.2/instiki.rb --daemon --port 2500 --storage /Library/WebServer/Documents/instiki-0.10.2/storage) that works fine from the command line buts fails when I run the script, with this output:


$ sudo SystemStarter start INSTIKI 
Welcome to Macintosh.
Starting Instiki ...
/Library/WebServer/Documents/instiki-0.10.2/script/server:3:in `require': No such file to load -- webrick (LoadError)
        from /Library/WebServer/Documents/instiki-0.10.2/script/server:3
        from /Library/WebServer/Documents/instiki-0.10.2/instiki.rb:3:in `load'
        from /Library/WebServer/Documents/instiki-0.10.2/instiki.rb:3
INSTIKI (8933) did not complete successfully.
The following StartupItems failed to properly start:
        /System/Library/StartupItems/INSTIKI - execution of Startup script failed
Startup complete.
Hangup

Thoughts anyone? Seems weird that it can’t find such files when run from a script but is A-OK from the command line…

Once I get that working, you have to remember to add the line INSTIKI=-YES- to your /etc/hostconfig file so the system knows to start Instiki at boot time. If you want to not start Instiki, you can simply change -YES- to -NO-

I am not sure, but is this because the /path/to/ruby is not in the $PATH of the shell executing the script? ruby is in /usr/bin, so try editing the startup script with the full pathname of ruby – ie /usr/bin/ruby

You may be able to simplify the setup by using an app called Lingon