All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.naps-bounce-bounceservice-server.sh Maven / Gradle / Ivy

The newest version!
#!/bin/bash

#jpdaOpts="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=localhost:8101"

#release_path=
#dist=
#lib=
#etc=
#initialMemory=
#maxMemory=
#configuremeEnvironment=
#user=
#outlog=
#errlog=
#logdir=
#tmpdir=
#pidfile=

if [ -z "$release_path" ]; then
	echo 'release_path environment is not set!'
	exit 1
fi

if [ -z "$dist" ]; then
	echo 'dist environment is not set!'
	exit 1
fi

dist=$release_path/$dist
lib=$release_path/${lib:=lib}
etc=$release_path/${etc:=etc}
initialMemory=${initialMemory:=512M}
maxMemory=${maxMemory:=512M}
configuremeEnvironment=${configuremeEnvironment:=dev}
user=${user:=$USER}
logdir=$release_path/${logdir:=.}
outlog=${outlog:=$logdir/nohup-BounceServer-out.log}
errlog=${errlog:=$logdir/nohup-BounceServer-err.log}
tmpdir=$release_path/${tmpdir:=/tmp}
pidfile=${pidfile:=$tmpdir/BounceServer.pid}

server='net.anotheria.portalkit.services.bounce.generated.BounceServer'

isServerUp() {
	if [ -f "$pidfile" ]; then
		pid=`cat "$pidfile"`
		alive=`ps --no-heading $pid 2>/dev/null | wc -l`
		if [ $alive == 0 ]; then
			rm -f "$pidfile"
			return 0
		else
			return 1
		fi
	else
		return 0
	fi
}

start() {
	isServerUp
	running=$?
	if [ $running == 0 ]; then
		echo -n 'Starting BounceServer... '
		for file in $(ls $lib); do
			CLASSPATH=$CLASSPATH:$lib/$file
			rmicodebase="$rmicodebase file:$lib/$file"
		done
		CLASSPATH=$etc:$dist:$CLASSPATH
		rmicodebase="file:$etc file:$dist $rmicodebase"
		work_dir=`pwd`
		cd "$release_path"
		sudo -u "$user" /bin/bash -c "nohup java $jpdaOpts -Xmx$maxMemory -Xms$initialMemory -classpath $CLASSPATH -Djava.rmi.server.codebase=\"$rmicodebase\" -Dpidfile=\"$pidfile\" -Dconfigureme.defaultEnvironment=$configuremeEnvironment $server 1>>\"$outlog\" 2>>\"$errlog\" &"
		cd "$work_dir"
		#Wait for possible starting error
		sleep 2
		isServerUp
		running=$?
		if [ $running == 1 ]; then
			echo Done
		else
			echo Failed
		fi
	else
		echo BounceServer is already running
	fi
}

stop() {
	isServerUp
	running=$?
	if [ $running == 0 ]; then
		echo 'BounceServer is not running'
	else
		echo -n 'Stopping BounceServer... '
		pid=`cat "$pidfile"`
		kill $pid
		sleep 2
		isServerUp
		running=$?
		if [ $running == 0 ]; then
			echo Done
			rm -f "$pidfile"
		else
			echo Failed
		fi
	fi
}

status() {
	isServerUp
	running=$?
	if [ $running == 1 ]; then
		echo 'BounceServer is running'
	else
		echo 'BounceServer is not running'
	fi
}

case $1 in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	status)
		status
		;;
	*)
	echo $"Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit 0




© 2015 - 2024 Weber Informatics LLC | Privacy Policy