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

scripts.oda-transporter-transporterservice-server.sh Maven / Gradle / Ivy

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

server='org.distributeme.agents.transporter.generated.TransporterServer'

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

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