Instiki
Launch at Startup (changes)

Showing changes from revision #19 to #20: Added | Removed | Changed

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/sh
#
# instiki     Startup script for the Instiki
#
# chkconfig: - 85 15
# description: Instiki wiki
#
# Source function library . /etc/rc.d/init.d/functions
DIR=/usr/local/instiki USER=instiki GROUP=instiki
PATH="/sbin:/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" export PATH
## For WEBRick, use these PROC="./instiki --daemon" START="runuser $USER -c '$PROC'" STOP="kill `cat /var/run/instiki.pid`" ## For Mongrel, use these #PROC="mongrel_rails start --group $GROUP --user $USER \ # -d -e production -m config/mime_types.yml -p 2500" #START=$PROC #STOP="mongrel_rails stop"
LOCK=/var/lock/subsys/instiki RETVAL=0
start() { # Check if it is already running if [ ! -f $LOCK ]; then echo -n $"Starting Instiki: " cd $DIR $START RETVAL=$? [ $RETVAL -eq 0 ] && touch $LOCK echo `pgrep -f -u $USER $"$PROC"` > /var/run/instiki.pid; echo else echo $"Instiki is already running." fi return $RETVAL }
stop() { echo -n $"Stopping Instiki: " cd $DIR $STOP RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $LOCK echo return $RETVAL }
restart() { stop sleep 5 start }
case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; condrestart) if [ -f $LOCK ]; then restart fi ;; status) status -p /var/run/instiki.pid instiki ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac
exit $RETVAL

Again, As you’ll discussed have in to customize theSecurity notes, this script assumes that Instiki will run as a new, unprivileged, user, ”instiki”. Depending on your situation, you may have to customize the DIR, PATH and USER variables.

Save this script as/etc/init.d/instiki` and

% sudo chkconfig --add instiki

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

% sudo /etc/init.d/instiki stop

and start it with

% sudo /etc/init.d/instiki start