PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/opennms-assemblies/remote-poller-standalone/src/main/filtered/remote-poller.sh

https://github.com/ajakubo1/opennms
Shell | 142 lines | 108 code | 13 blank | 21 comment | 15 complexity | af2e03156b73fb22014ea8c18f1c9ca1 MD5 | raw file
  1#!/bin/sh -
  2#
  3# Starts the remote poller.
  4# w00t
  5#
  6# Thu Sep 18 08:54:00 EST 2008 - ranger@opennms.org
  7# - updated to use runjava
  8# Mon Jun 16 15:52:00 EST 2008 - ranger@opennms.org
  9# - updated to use the installed location
 10# Tue Dec 12 23:05:42 GMT 2006 - dj@opennms.org
 11
 12if [ -z "$OPENNMS_HOME" ]; then
 13	OPENNMS_HOME="${install.dir}"
 14fi
 15JAVA_CONF="$OPENNMS_HOME/etc/java.conf"
 16
 17MONITOR_JAR="$OPENNMS_HOME/bin/remote-poller.jar"
 18RMI_PORT=1099
 19JVM_ARGS="-Xmx384m"
 20EXTRA_ARGS=""
 21GUI=false
 22
 23if [ -f "$JAVA_CONF" ]; then
 24	JAVA_EXE="`cat $JAVA_CONF`"
 25fi
 26
 27printHelp() {
 28	echo "usage: $0 [-h] [-j java_exe] -u <URI> -l <location> [-g] [-n username] [-p password]"
 29	echo ""
 30	echo "	-h this help"
 31	echo "	-u URI to the remote host"
 32	echo "	   ex: http://opennms-host.com:8980/opennms-remoting"
 33	echo "	   ex: rmi://opennms-host.com/"
 34	echo "	-l location name for this poller"
 35	echo "	-g start the remote poller GUI"
 36	echo "	-j override Java executable"
 37	echo "	-n the userName to connect as"
 38	echo "	-p the Password to connect with"
 39	echo ""
 40}
 41
 42while getopts ":D:u:l:dgj:n:p:" OPT
 43do
 44	case $OPT in
 45		h)
 46			printHelp
 47			exit 1
 48			;;
 49		u)
 50			REMOTE_URI="$OPTARG"
 51			;;
 52		l)
 53			REMOTE_LOCATION="$OPTARG"
 54			;;
 55		g)
 56			GUI=true
 57			EXTRA_ARGS="$EXTRA_ARGS --gui"
 58			;;
 59		j)
 60			JAVA_EXE="$OPTARG"
 61			;;
 62		D)
 63			JVM_ARGS="$JVM_ARGS -D$OPTARG"
 64			;;
 65		d|n|p)
 66			EXTRA_ARGS="$EXTRA_ARGS -$OPT $OPTARG"
 67			;;
 68	esac
 69done
 70
 71if [ "$GUI" = "false" ]; then
 72	JVM_ARGS="$JVM_ARGS -Djava.awt.headless=true"
 73fi
 74
 75# backwards compatibility with when it was RMI_*
 76if [ -z "$REMOTE_LOCATION" ]; then
 77	REMOTE_LOCATION="$RMI_LOCATION"
 78fi
 79if [ -z "$REMOTE_URI" ]; then
 80	REMOTE_URI="$RMI_HOST"
 81fi
 82
 83if [ "$JAVA_EXE" = "" ]; then
 84	if [ "$JAVA_HOME" = "" ] || [ ! -x "$JAVA_HOME/bin/java" ]; then
 85		echo "ERROR: $JAVA_CONF file not found, and \$JAVA_HOME is not set to a valid JDK."
 86		echo "Try running $OPENNMS_HOME/bin/runjava, or set JAVA_HOME."
 87		exit 1
 88	else
 89		JAVA_EXE="$JAVA_HOME/bin/java"
 90	fi
 91fi
 92
 93if [ "$REMOTE_LOCATION" = "" ]; then
 94	echo "Error: you must set the location name."
 95	printHelp
 96	exit 1
 97fi
 98if [ "$REMOTE_URI" = "" ]; then
 99	echo "Error: you must set the remote URI."
100	exit 1
101fi
102
103#log_file="poll.log.`date '+%Y%m%d-%H%M%S'`"
104#log_file="/tmp/poll.log"
105log_file="/dev/null"
106
107if [ -n "$REMOTE_USERNAME" ]; then
108	EXTRA_ARGS="$EXTRA_ARGS -n $REMOTE_USERNAME"
109fi
110if [ -n "$REMOTE_PASSWORD" ]; then
111	EXTRA_ARGS="$EXTRA_ARGS -p $REMOTE_PASSWORD"
112fi
113
114#echo nohup $JAVA_EXE \
115#	$JVM_ARGS \
116#	-Djava.rmi.activation.port="$RMI_PORT" \
117#	-jar "$MONITOR_JAR" \
118#	--url="$REMOTE_URI" \
119#	--location="$REMOTE_LOCATION" \
120#	$EXTRA_ARGS \
121#	"$@"
122
123if [ -n "$PIDFILE" ]; then
124	nohup $JAVA_EXE \
125		$JVM_ARGS \
126		-Djava.rmi.activation.port="$RMI_PORT" \
127		-jar "$MONITOR_JAR" \
128		--url="$REMOTE_URI" \
129		--location="$REMOTE_LOCATION" \
130		$EXTRA_ARGS \
131		> $log_file 2>&1 &
132	echo "$!" > $PIDFILE
133else
134	exec nohup $JAVA_EXE \
135		$JVM_ARGS \
136		-Djava.rmi.activation.port="$RMI_PORT" \
137		-jar "$MONITOR_JAR" \
138		--url="$REMOTE_URI" \
139		--location="$REMOTE_LOCATION" \
140		$EXTRA_ARGS \
141		> $log_file 2>&1 &
142fi