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

scripts.naps-subscription-subscriptionservice-server.sh Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show 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-SubscriptionServer-out.log}
errlog=${errlog:=$logdir/nohup-SubscriptionServer-err.log}
tmpdir=$release_path/${tmpdir:=/tmp}
pidfile=${pidfile:=$tmpdir/SubscriptionServer.pid}

server='net.anotheria.portalkit.services.subscription.generated.SubscriptionServer'

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 SubscriptionServer... '
		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 SubscriptionServer is already running
	fi
}

stop() {
	isServerUp
	running=$?
	if [ $running == 0 ]; then
		echo 'SubscriptionServer is not running'
	else
		echo -n 'Stopping SubscriptionServer... '
		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 'SubscriptionServer is running'
	else
		echo 'SubscriptionServer 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