#!/bin/sh if [ "$1" = "" ]; then echo "Usage: $0 helma.conf" exit 1 fi # Check for existence of needed config file and source it if [ -r "$1" ]; then . "$1" else echo "Can't read config file $1" exit 6 fi # Check for missing files and directories if [ ! -x $JAVA_BIN ]; then echo "Config error: JAVA_BIN $JAVA_BIN not found or not executable" exit 5 fi if [ ! -r $HELMA_INSTALL/launcher.jar ]; then echo "Config error: $HELMA_INSTALL/launcher.jar not found or not readable" exit 5 fi if [ ! -d $HELMA_HOME ]; then echo "Config error: HELMA_HOME $HELMA_HOME not found" exit 5 fi if [ -f $HELMA_PID ]; then if [ ! -r $HELMA_PID ]; then echo "Pidfile HELMA_PID ${HELMA_PID} not readable." exit 2 fi read pid _junk < ${HELMA_PID} if [ -z "$pid" ]; then echo "Pidfile HELMA_PID ${HELMA_PID} contains no pid." exit 2 fi ps -o pid= $pid > /dev/null if [ $? -eq 0 ]; then echo 1>&2 "${HELMA_SERVICE} already running? (pid=${pid})." exit 2 fi fi touch $HELMA_LOG && chown $HELMA_USER $HELMA_LOG if [ "$?" -ne "0" ]; then echo "Config error: Permission to HELMA_LOG $HELMA_LOG denied" exit 4 fi touch $HELMA_PID && chown $HELMA_USER $HELMA_PID if [ "$?" -ne "0" ]; then echo "Config error: Permission to HELMA_PID $HELMA_PID denied" exit 4 fi args="$JAVA_OPTS -jar $HELMA_INSTALL/launcher.jar -h $HELMA_HOME -f $HELMA_CONFIG/server.properties $HELMA_ARGS" if [ "`whoami`" = "$HELMA_USER" ]; then command="csh -c 'nohup $JAVA_BIN $args >& $HELMA_LOG & echo \$! > $HELMA_PID' > /dev/null" else command="su -m $HELMA_USER -c 'nohup $JAVA_BIN $args >& $HELMA_LOG & echo \$! > $HELMA_PID' > /dev/null" fi echo "Starting ${HELMA_SERVICE}." eval "$command" return=$? if [ "`cat $HELMA_PID`" = "" ]; then rm $HELMA_PID fi if [ $return -ne 0 ]; then exit 1 fi exit 0