[OGo-Developer] sysv init script

Henrik Holmboe developer@opengroupware.org
Wed, 16 Jul 2003 15:55:28 +0200


--lkTb+7nhmha7W+c3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

 I have put together a simple init script that might be of use to
 others. It should handle being used on both Linux and FreeBSD (I know
 BSD doesnt use sysv init). I have only tested it on Debian sarge.

note: Im not on developers@, since Im a fake coder :)

-- 
Henrik Holmboe, Stockholm Sweden
<http://elements.hack.se/contact/>

--lkTb+7nhmha7W+c3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=opengroupware

#!/bin/sh
#
# Startup script for OpenGroupware on UNIX systems.

# NOTE: This script currently needs to have an environment that
# automatically sources ~/OpenGroupware.sh. This is achievable with
# this command:
#
# echo "source /OpenGroupware.sh" >> ~/.bash_profile

# chkconfig: 2345 75 25
# description: OpenGroupware is a groupware server

# Configuration section

OGO_DIR=/usr/lib/opengroupware.org
OGO_BIN=$OGO_DIR/WOApps/OpenGroupware.woa/ix86/linux-gnu/gnu-fd-nil/OpenGroupware
OGO_ARGS="-WOPort 20000 -WOHttpAllowHost localhost -OGoMinimumActiveSessionCount 0"
PID_FILE=/var/run/ogo.pid
LOG=/var/log/ogo.log

# end configuration section


# Source function library.
# Use the funtions provided by Red Hat or use our own
if [ -f /etc/rc.d/init.d/functions ]
then
	. /etc/rc.d/init.d/functions
else
	function action {
		echo "$1"
		shift
		$@
	}
	function success {
		echo -n "Success"
	}
	function failure {
		echo -n "Failed"
	}
fi


[ -x $OGO_BIN ] || exit 0

case "$1" in
	start)
		echo -n  "Starting OpenGroupware: "
		pushd $OGO_DIR > /dev/null

		# log separator
		echo "----------------------------------------------------------------------" >> $LOG

		# run as a user 'opengroupware':
		if [ "`uname -s`" = "Linux" ]; then
		    env -i su - opengroupware -c "$OGO_BIN $OGO_ARGS" >> $LOG 2>&1 &
		elif [ "`uname -s`" = "FreeBSD" ]; then
		    env -i su -l opengroupware -c "$OGO_BIN $OGO_ARGS" >> $LOG 2>&1 &
		fi

		echo $! > $PID_FILE
		popd > /dev/null
		success "Starting OpenGroupware"
		echo
		;;

	stop)
		echo -n "Shutting down OpenGroupware: "
		if test -f "$PID_FILE" ; then
			PID=`cat $PID_FILE`
			if kill $PID >> $LOG 2>&1 ; then
				/bin/rm $PID_FILE
				success "Shutting down OpenGroupware"
			else
				echo ""
				echo "Could not kill process $PID named in $PID_FILE. Check tail of $LOG."
				failure "Shutting down OpenGroupware"
			fi
		else
			echo ""
			echo "No OpenGroupware pid file found. Looked for $PID_FILE."
			failure "No OpenGroupware pid file found. Looked for $PID_FILE."
		fi
		echo
		;;

	restart)
		$0 stop
		$0 start
		;;

	*)
		echo "Usage: opengroupware {start|stop|restart}"
		exit 1

esac

exit 0

--lkTb+7nhmha7W+c3--