Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added RHQ specs + source files, RHQ is now installed instead JOPR

  • Loading branch information...
commit ab33c28ff9780022d83a7b2c3e943281e12ad4d5 1 parent 2176e72
@goldmann goldmann authored
View
4 appliances/cirras/cirras.appl
@@ -1,5 +1,7 @@
name: cirras
summary: Appliance template for CirrAS appliances
+os:
+ version: 12
hardware:
memory: 256
partitions:
@@ -10,7 +12,7 @@ appliances:
packages:
includes:
- cirras-management
- - jopr-agent
+ - rhq-agent
- which
- sudo
- ruby-devel
View
2  appliances/cirras/management.appl
@@ -11,7 +11,7 @@ packages:
includes:
- dhcp
- java-1.6.0-openjdk-devel
- - jopr
+ - rhq
- postgresql-server
post:
base:
2  lib/boxgrinder-build
@@ -1 +1 @@
-Subproject commit 17d05765d18c30e12519b452e2a70246671045a7
+Subproject commit c41880738eb6be9d3db570e88a50be2ba36d91b0
View
56 specs/rhq-agent.spec
@@ -0,0 +1,56 @@
+%define agent_name rhq-enterprise-agent
+%define rhq_version 1.4.0.B01
+
+Summary: RHQ Agent
+Name: rhq-agent
+Version: %{rhq_version}
+Release: 1
+License: LGPL
+BuildArch: noarch
+Source0: rhq-agent.init
+Source1: rhq-agent-install.sh
+Group: Applications/System
+Requires: java-1.6.0-openjdk
+Requires(post): /sbin/chkconfig
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+%define runuser %{name}
+
+%description
+The RHQ project is an abstraction and plug-in based systems management suite that provides extensible and integrated systems management for multiple products and platforms across a set of core features. The project is designed with layered modules that provide a flexible architecture for deployment. It delivers a core user interface that delivers audited and historical management across an entire enterprise. A Server/Agent architecture provides remote management and plugins implement all specific support for managed products. RHQ is an open source project licensed under the GPL, with some pieces individually licensed under a dual GPL/LGPL license to facilitate the integration with extended packages such as Jopr and Embedded Jopr.
+
+%install
+install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
+
+echo "RHQ_AGENT_VERSION=%{version}" > $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+
+install -d -m 755 $RPM_BUILD_ROOT%{_initrddir}
+install -m 755 %{SOURCE0} $RPM_BUILD_ROOT%{_initrddir}/%{name}
+
+install -d -m 755 $RPM_BUILD_ROOT/usr/share/%{name}
+install -m 755 %{SOURCE1} $RPM_BUILD_ROOT/usr/share/%{name}/rhq-agent-install.sh
+
+%clean
+rm -Rf $RPM_BUILD_ROOT
+
+%pre
+/usr/sbin/groupadd -r %{name} 2>/dev/null || :
+/usr/sbin/useradd -c "%{name}" -r -s /bin/bash -d /opt/%{name} -g %{name} %{name} 2>/dev/null || :
+
+%post
+/sbin/chkconfig --add %{name}
+/sbin/chkconfig %{name} on
+
+%files
+%defattr(-,root,root)
+/
+
+%changelog
+* Tue Dec 24 2009 Marek Goldmann 1.4.0.B01
+- Upgrade to version 1.4.0.B01
+
+* Thu Sep 24 2009 Marek Goldmann 1.3.1
+- Upgrade to version 1.3.1
+
+* Sat Jul 25 2009 Marek Goldmann 1.2.1
+- Initial packaging
View
72 specs/rhq.spec
@@ -0,0 +1,72 @@
+Summary: RHQ server
+Name: rhq
+Version: 1.4.0.B01
+Release: 1
+License: LGPL
+BuildArch: noarch
+Group: Applications/System
+Source0: http://downloads.sourceforge.net/project/rhq/rhq/rhq-1.4.0.b01/rhq-server-%{version}.zip
+Source1: preconfigure-rhq-agent.sh
+Source2: agent-configuration.xml
+Source3: rhq.init
+Source4: preconfigure-rhq.sh
+Source5: rhq-server.properties
+Requires: shadow-utils
+Requires: java-1.6.0-openjdk
+Requires: unzip
+Requires: urw-fonts
+Requires(pre): postgresql
+Requires(post): /sbin/chkconfig
+Requires(post): /bin/sed
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+AutoReqProv: 0
+AutoReq: 0
+
+%define runuser %{name}
+%define __jar_repack %{nil}
+
+%description
+The RHQ project is an abstraction and plug-in based systems management suite that provides extensible and integrated systems management for multiple products and platforms across a set of core features. The project is designed with layered modules that provide a flexible architecture for deployment. It delivers a core user interface that delivers audited and historical management across an entire enterprise. A Server/Agent architecture provides remote management and plugins implement all specific support for managed products. RHQ is an open source project licensed under the GPL, with some pieces individually licensed under a dual GPL/LGPL license to facilitate the integration with extended packages such as Jopr and Embedded Jopr.
+
+%prep
+echo RPM_BUILD_DIR
+rm -rf $RPM_BUILD_DIR
+unzip -q %{SOURCE0} -d $RPM_BUILD_DIR
+
+%install
+install -d -m 755 $RPM_BUILD_ROOT/opt/%{name}
+cp -R . $RPM_BUILD_ROOT/opt/%{name}
+
+install -d -m 755 $RPM_BUILD_ROOT/usr/share/%{name}
+#install -m 755 %{SOURCE1} $RPM_BUILD_ROOT/usr/share/%{name}/preconfigure-rhq-agent.sh
+install -m 644 %{SOURCE2} $RPM_BUILD_ROOT/usr/share/%{name}/agent-configuration.xml
+install -m 755 %{SOURCE4} $RPM_BUILD_ROOT/usr/share/%{name}/preconfigure-rhq.sh
+install -m 644 %{SOURCE5} $RPM_BUILD_ROOT/usr/share/%{name}/rhq-server.properties
+
+install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
+
+echo "RHQ_VERSION=%{version}" > $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+echo "RHQ_HOME=/opt/%{name}" >> $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+
+
+install -d -m 755 $RPM_BUILD_ROOT%{_initrddir}
+install -m 755 %{SOURCE3} $RPM_BUILD_ROOT%{_initrddir}/%{name}
+
+%clean
+rm -Rf $RPM_BUILD_ROOT
+
+%pre
+/usr/sbin/groupadd -r %{name} 2>/dev/null || :
+/usr/sbin/useradd -c "%{name}" -r -s /bin/bash -d /opt/%{name} -g %{name} %{name} 2>/dev/null || :
+
+%post
+/sbin/chkconfig --add %{name}
+/sbin/chkconfig %{name} on
+
+%files
+%defattr(-,%{name},%{name})
+/
+
+%changelog
+* Tue Dec 24 2009 Marek Goldmann 1.4.0.B01
+- Initial packaging
View
25 src/preconfigure-rhq-agent.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+[ -f /etc/sysconfig/rhq ] && . /etc/sysconfig/rhq
+
+RHQ_AGENT_NAME=rhq-enterprise-agent
+RHQ_AGENT_VERSION=1.3.1
+RHQ_CONFIG=/usr/share/rhq/agent-configuration.xml
+RHQ_TMP_DIR=/tmp/rhq-$RHQ_VERSION
+
+IP_ADDRESS=`ip addr list eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1`
+
+rm -rf $RHQ_TMP_DIR
+mkdir -p $RHQ_TMP_DIR
+
+cd $RHQ_TMP_DIR
+jar xvf $RHQ_HOME/jbossas/server/default/deploy/rhq.ear.rej/rhq-downloads/rhq-agent/$RHQ_AGENT_NAME-$RHQ_AGENT_VERSION.jar $RHQ_AGENT_NAME-$RHQ_AGENT_VERSION.zip
+unzip -q $RHQ_AGENT_NAME-$RHQ_AGENT_VERSION.zip -d $RHQ_TMP_DIR
+
+## ADD HERE CHANGES TO agent-configuration.xml
+sed s/#BIND_ADDRESS#/$IP_ADDRESS/g $RHQ_CONFIG > rhq-agent/conf/agent-configuration.xml
+
+jar uvf $RHQ_AGENT_NAME-$RHQ_AGENT_VERSION.zip rhq-agent/conf/agent-configuration.xml
+jar uvf $RHQ_HOME/jbossas/server/default/deploy/rhq.ear.rej/rhq-downloads/rhq-agent/$RHQ_AGENT_NAME-$RHQ_AGENT_VERSION.jar $RHQ_AGENT_NAME-$RHQ_AGENT_VERSION.zip
+
+chown rhq:rhq /opt/rhq/ -R
View
41 src/preconfigure-rhq.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+[ -f /etc/sysconfig/boxgrinder ] && . /etc/sysconfig/boxgrinder
+[ -f /etc/sysconfig/rhq ] && . /etc/sysconfig/rhq
+
+DATABASE_NAME=rhq
+DATABASE_USER=rhq
+DATABASE_NAME=rhq
+DATABASE_PASSWORD=`head -c10 /dev/urandom | md5sum | head -c30`
+
+IP_ADDRESS=`ip addr list eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1`
+
+status_code=`curl -o /dev/null -s -m 5 -w '%{http_code}' http://169.254.169.254/latest/meta-data/local-ipv4`
+
+if [ $status_code -eq "200" ]
+then
+ LOCAL_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
+ PUBLIC_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
+else
+ LOCAL_IP=$IP_ADDRESS
+ # this is intentional
+ PUBLIC_IP=$IP_ADDRESS
+fi
+
+USER_CREATED=`/bin/su postgres -c "/bin/echo '\du' | /usr/bin/psql -tA" &>/dev/null | awk -F\| '{ print $1 }' | grep $DATABASE_USER | wc -l`
+DATABASE_CREATED=`/bin/su postgres -c "/usr/bin/psql -tAl" &>/dev/null | awk -F\| '{ print $1 }' | grep $DATABASE_NAME | wc -l`
+
+if [ $USER_CREATED -eq "0" ]
+then
+ /bin/su postgres -c "/usr/bin/createuser -SDR $DATABASE_USER &>/dev/null"
+ echo "ALTER USER $DATABASE_USER WITH PASSWORD '$DATABASE_PASSWORD'" | /bin/su postgres -c /usr/bin/psql &>/dev/null
+fi
+
+if [ $DATABASE_CREATED -eq "0" ]
+then
+ /bin/su postgres -c "/usr/bin/createdb -O $DATABASE_USER $DATABASE_NAME &>/dev/null"
+fi
+
+sed s/#LOCAL_IP#/$LOCAL_IP/g /usr/share/rhq/rhq-server.properties | sed s/#PUBLIC_IP#/$PUBLIC_IP/g | sed s/#DATABASE_USER#/$DATABASE_USER/g | sed s/#DATABASE_PASSWORD#/$DATABASE_PASSWORD/g | sed s/#DATABASE_NAME#/$DATABASE_NAME/g > $RHQ_HOME/bin/rhq-server.properties
+
+chown rhq:rhq /opt/rhq/ -R
View
35 src/rhq-agent-install.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+[ -f /etc/sysconfig/boxgrinder ] && . /etc/sysconfig/boxgrinder
+
+RHQ_AGENT_HOME=/opt/rhq-agent
+
+[ -f /etc/sysconfig/rhq-agent ] && . /etc/sysconfig/rhq-agent
+
+[ "x$RHQ_SERVER_IP" = "x" ] && exit 0
+
+RHQ_AGENT_JAR_LOCATION=http://$RHQ_SERVER_IP:7080/agentupdate/download
+
+rm -rf $RHQ_AGENT_HOME
+mkdir -p $RHQ_AGENT_HOME
+
+sleep=0
+downloaded=0
+while [ "$downloaded" = "0" ]; do
+ sleep 5
+ sleep=`expr $sleep + 5`
+
+ http_code=`curl -o /dev/null -s -m 5 -w '%{http_code}' $RHQ_AGENT_JAR_LOCATION`
+
+ if [ $http_code -eq "200" ]
+ then
+ wget $RHQ_AGENT_JAR_LOCATION -O $RHQ_AGENT_HOME/rhq-agent.jar
+ downloaded=1
+ fi
+done
+
+cd $RHQ_AGENT_HOME
+
+java -jar rhq-agent.jar --install
+
+sed -i s/#AGENT_NAME#/$APPLIANCE_NAME-$HOSTNAME/g $RHQ_AGENT_HOME/rhq-agent/conf/agent-configuration.xml
View
313 src/rhq-agent.init
@@ -0,0 +1,313 @@
+#!/bin/sh
+
+# chkconfig: 2345 93 25
+# description: Starts and stops the RHQ agent
+#
+# processname: java
+# pidfile: /var/run/rhq-agent.pid
+
+# =============================================================================
+# RHQ Agent UNIX Boot Script
+#
+# This file is used to execute the RHQ Agent on a UNIX platform as part of
+# the platform's bootup sequence.
+# Run this script without any command line options for the syntax help.
+#
+# This script is customizable by setting certain environment variables, which
+# are described in comments in rhq-agent-env.sh found in the same directory
+# as this script. The variables can also be set via that rhq-agent-env.sh file,
+# which is sourced by this script.
+#
+# Note that if this script is to be used as an init.d script, you must ensure
+# this script has the RHQ_AGENT_HOME set so it knows where to find the
+# agent installation.
+# =============================================================================
+
+export RHQ_AGENT_JAVA_EXE_FILE_PATH=/usr/lib/jvm/jre-1.6.0/bin/java
+export RHQ_AGENT_HOME=/opt/rhq-agent/rhq-agent
+
+[ -f /etc/sysconfig/rhq-agent ] && . /etc/sysconfig/rhq-agent
+
+# if RHQ server ip isn't injected, don't start the agent
+if [ "x$RHQ_SERVER_IP" = "x" ]; then
+ # No RHQ_SERVER_IP specified...
+ exit 0
+fi
+
+[ ! -d $RHQ_AGENT_HOME ] && /usr/share/rhq-agent/rhq-agent-install.sh
+
+# ----------------------------------------------------------------------
+# Function that simply dumps a message iff debug mode is enabled
+# ----------------------------------------------------------------------
+
+debug_wrapper_msg ()
+{
+ # if debug variable is set, it is assumed to be on, unless its value is false
+ if [ "x$RHQ_AGENT_DEBUG" != "x" ]; then
+ if [ "$RHQ_AGENT_DEBUG" != "false" ]; then
+ echo "rhq-agent-wrapper.sh: $1"
+ fi
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Function that sets _STATUS, _RUNNING and _PID based on the status of
+# the RHQ Agent process as found in the pidfile
+# ----------------------------------------------------------------------
+
+check_status ()
+{
+ if [ -f "${_PIDFILE}" ]; then
+ _PID=`cat "${_PIDFILE}"`
+ check_status_of_pid $_PID
+ else
+ _STATUS="RHQ Agent (no pidfile) is NOT running"
+ _RUNNING=0
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Function that sets _STATUS and _RUNNING based on the status of
+# the given pid number
+# ----------------------------------------------------------------------
+
+check_status_of_pid ()
+{
+ if [ "x$1" != "x" ] && kill -0 $1 2>/dev/null ; then
+ _STATUS="RHQ Agent (pid $1) is running"
+ _RUNNING=1
+ else
+ _STATUS="RHQ Agent (pid $1) is NOT running"
+ _RUNNING=0
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Function that ensures that the pidfile no longer exists
+# ----------------------------------------------------------------------
+
+remove_pid_file ()
+{
+ if [ -f "${_PIDFILE}" ]; then
+ debug_wrapper_msg "Removing existing pidfile"
+ rm "${_PIDFILE}"
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Function that prepares the location where the pidfile will live
+# ----------------------------------------------------------------------
+
+prepare_pid_dir ()
+{
+ mkdir -p "$RHQ_AGENT_PIDFILE_DIR"
+ if [ "$?" != "0" ]; then
+ echo "Cannot create the directory where the pidfile will go: ${RHQ_AGENT_PIDFILE_DIR}"
+ exit 1
+ fi
+}
+
+# -------------------------------
+# Get the location of this script.
+# Make sure we take into account the possibility $0
+# is a symlink to the real agent installation script.
+
+_DOLLARZERO=`readlink "$0" || echo "$0"`
+RHQ_AGENT_WRAPPER_BIN_DIR_PATH=`dirname "$_DOLLARZERO"`
+debug_wrapper_msg "RHQ_AGENT_WRAPPER_BIN_DIR_PATH=$RHQ_AGENT_WRAPPER_BIN_DIR_PATH"
+
+# -------------------------------
+# Read in the rhq-agent-env.sh file so we get the configured agent environment
+
+if [ -f "${RHQ_AGENT_WRAPPER_BIN_DIR_PATH}/rhq-agent-env.sh" ]; then
+ debug_wrapper_msg "Loading environment script: ${RHQ_AGENT_WRAPPER_BIN_DIR_PATH}/rhq-agent-env.sh"
+ . "${RHQ_AGENT_WRAPPER_BIN_DIR_PATH}/rhq-agent-env.sh" $*
+fi
+
+# -------------------------------
+# The --daemon argument is required
+
+if [ "x$RHQ_AGENT_CMDLINE_OPTS" = "x" ]; then
+ RHQ_AGENT_CMDLINE_OPTS=--daemon
+fi
+export RHQ_AGENT_CMDLINE_OPTS
+
+# -------------------------------
+# Determine where this script is, and change to its directory
+
+cd "$RHQ_AGENT_WRAPPER_BIN_DIR_PATH"
+_THIS_SCRIPT_DIR=`pwd`
+_THIS_SCRIPT="${_THIS_SCRIPT_DIR}"/`basename "$_DOLLARZERO"`
+
+# -------------------------------
+# Figure out where the RHQ Agent's home directory is and cd to it.
+# If RHQ_AGENT_HOME is not defined, we will assume we are running
+# directly from the agent installation's bin directory
+
+if [ "x$RHQ_AGENT_HOME" = "x" ]; then
+ cd ..
+ RHQ_AGENT_HOME=`pwd`
+else
+ cd "${RHQ_AGENT_HOME}" || {
+ echo "Cannot go to the RHQ_AGENT_HOME directory: ${RHQ_AGENT_HOME}"
+ exit 1
+ }
+fi
+
+# -------------------------------
+# create the logs directory
+
+if [ ! -d "${RHQ_AGENT_HOME}/logs" ]; then
+ mkdir "${RHQ_AGENT_HOME}/logs"
+fi
+
+# -------------------------------
+# Find out where to put the pidfile and prepare its directory
+
+if [ "x$RHQ_AGENT_PIDFILE_DIR" = "x" ]; then
+ RHQ_AGENT_PIDFILE_DIR="${RHQ_AGENT_HOME}/bin"
+fi
+_PIDFILE="${RHQ_AGENT_PIDFILE_DIR}/rhq-agent.pid"
+debug_wrapper_msg "pidfile will be located at ${_PIDFILE}"
+
+# -------------------------------
+# Main processing starts here
+
+check_status
+
+case "$1" in
+'start')
+ prepare_pid_dir
+
+ if [ "$_RUNNING" = "1" ]; then
+ echo $_STATUS
+ exit 0
+ fi
+
+ echo Starting RHQ Agent...
+
+ RHQ_AGENT_IN_BACKGROUND="${_PIDFILE}"
+ export RHQ_AGENT_IN_BACKGROUND
+
+ # Determine the command to execute when starting the agent
+ if [ "x$RHQ_AGENT_START_COMMAND" = "x" ]; then
+ # Find out where the agent start script is located
+ _START_SCRIPT="${RHQ_AGENT_HOME}/bin/rhq-agent.sh"
+
+ if [ ! -f "$_START_SCRIPT" ]; then
+ echo "ERROR! Cannot find the RHQ Agent start script"
+ echo "Not found: $_START_SCRIPT"
+ exit 1
+ fi
+ debug_wrapper_msg "Start script found here: $_START_SCRIPT"
+
+ RHQ_AGENT_START_COMMAND="'${_START_SCRIPT}'"
+ fi
+
+ # If a password prompt needs to be shown, do it now
+ if [ "x$RHQ_AGENT_PASSWORD_PROMPT" != "x" ]; then
+ if [ "$RHQ_AGENT_PASSWORD_PROMPT" = "true" ]; then
+ RHQ_AGENT_PASSWORD_PROMPT="Enter password to start the agent"
+ fi
+ echo $RHQ_AGENT_PASSWORD_PROMPT
+ fi
+
+ # start the agent now!
+ if [ "x$RHQ_AGENT_DEBUG" != "x" ] && [ "$RHQ_AGENT_DEBUG" != "false" ]; then
+ debug_wrapper_msg "Executing agent with command: ${RHQ_AGENT_START_COMMAND}"
+ eval $RHQ_AGENT_START_COMMAND
+ else
+ eval "$RHQ_AGENT_START_COMMAND > \"${RHQ_AGENT_HOME}/logs/rhq-agent-wrapper.log\" 2>&1"
+ fi
+
+ sleep 5
+ check_status
+ echo $_STATUS
+
+ if [ "$_RUNNING" = "1" ]; then
+ exit 0
+ else
+ echo Failed to start - make sure the RHQ Agent is fully configured properly
+ exit 1
+ fi
+ ;;
+
+'stop')
+ prepare_pid_dir
+
+ if [ "$_RUNNING" = "0" ]; then
+ echo $_STATUS
+ remove_pid_file
+ exit 0
+ fi
+
+ echo Stopping RHQ Agent...
+
+ _PID_TO_KILL=$_PID;
+
+ echo "RHQ Agent (pid=${_PID_TO_KILL}) is stopping..."
+ kill -TERM $_PID_TO_KILL
+
+ sleep 5
+ check_status_of_pid $_PID_TO_KILL
+ if [ "$_RUNNING" = "1" ]; then
+ debug_wrapper_msg "Agent did not die yet, trying to kill it again"
+ kill -TERM $_PID_TO_KILL
+ fi
+
+ while [ "$_RUNNING" = "1" ]; do
+ sleep 2
+ check_status_of_pid $_PID_TO_KILL
+ done
+
+ remove_pid_file
+ echo "RHQ Agent has stopped."
+ exit 0
+ ;;
+
+'kill')
+ prepare_pid_dir
+
+ if [ "$_RUNNING" = "0" ]; then
+ echo $_STATUS
+ remove_pid_file
+ exit 0
+ fi
+
+ echo Killing RHQ Agent...
+
+ _PID_TO_KILL=$_PID;
+
+ # do not try to gracefully kill, use a hard -KILL/-9
+ echo "RHQ Agent (pid=${_PID_TO_KILL}) is being killed..."
+ kill -9 $_PID_TO_KILL
+
+ while [ "$_RUNNING" = "1" ]; do
+ sleep 2
+ check_status_of_pid $_PID_TO_KILL
+ done
+
+ remove_pid_file
+ echo "RHQ Agent has been killed."
+ exit 0
+ ;;
+
+'status')
+ echo $_STATUS
+ if [ "$_RUNNING" = "0" ]; then
+ exit 1
+ fi
+ exit 0
+ ;;
+
+'restart')
+ "${_THIS_SCRIPT}" stop
+ "${_THIS_SCRIPT}" start
+ exit $?
+ ;;
+
+*)
+ echo "Usage: $0 { start | stop | kill | restart | status }"
+ exit 1
+ ;;
+esac
View
454 src/rhq.init
@@ -0,0 +1,454 @@
+#!/bin/sh
+
+# chkconfig: 2345 92 26
+# description: Starts and stops the RHQ server
+#
+# processname: java
+
+# =============================================================================
+# RHQ Server UNIX Startup Script
+#
+# This file is used to execute the RHQ Server on a UNIX platform as part of
+# the platform's bootup sequence or as a foreground console process.
+# Run this script without any command line options for the syntax help.
+#
+# This script is customizable by setting the following environment variables:
+#
+# Note that if this script is to be used as an init.d script, you must set
+# RHQ_SERVER_HOME so this script knows where to find the server installation.
+#
+# RHQ_SERVER_DEBUG - If this is defined, the script will emit debug
+# messages. If this is not defined or set to "false"
+# debug messages are not emitted.
+#
+# RHQ_SERVER_HOME - Defines where the server's home install directory is.
+# If not defined, it will be assumed to be the parent
+# directory of the directory where this script lives.
+#
+# RHQ_SERVER_JAVA_HOME - The location of the JRE that the server will
+# use. This will be ignored if
+# RHQ_SERVER_JAVA_EXE_FILE_PATH is set.
+# If this and RHQ_SERVER_JAVA_EXE_FILE_PATH are
+# not set, the server's embedded JRE will be used.
+#
+# RHQ_SERVER_JAVA_EXE_FILE_PATH - Defines the full path to the Java
+# executable to use. If this is set,
+# RHQ_SERVER_JAVA_HOME is ignored.
+# If this is not set, then
+# $RHQ_SERVER_JAVA_HOME/bin/java
+# is used. If this and
+# RHQ_SERVER_JAVA_HOME are not set, the
+# server's embedded JRE will be used.
+#
+# RHQ_SERVER_JAVA_OPTS - Java VM command line options to be
+# passed into the server's VM. If this is not defined
+# this script will pass in a default set of options.
+# If this is set, it completely overrides the
+# server's defaults. If you only want to add options
+# to the server's defaults, then you will want to
+# use RHQ_SERVER_ADDITIONAL_JAVA_OPTS instead.
+#
+# RHQ_SERVER_ADDITIONAL_JAVA_OPTS - additional Java VM command line options
+# to be passed into the server's VM. This
+# is added to RHQ_SERVER_JAVA_OPTS; it
+# is mainly used to augment the server's
+# default set of options. This can be
+# left unset if it is not needed.
+#
+# RHQ_SERVER_CMDLINE_OPTS - If this is defined, these are the command line
+# arguments that will be passed to the RHQ Server.
+#
+# RHQ_SERVER_PIDFILE_DIR - a full path to a writable directory where this
+# script can write its pidfile to.
+# If not defined, this defaults to the server's
+# bin directory.
+#
+# If the embedded JRE is to be used but is not available, the fallback
+# JRE to be used will be determined by the JAVA_HOME environment variable.
+#
+# This script calls run.sh when starting the underlying JBossAS server.
+# =============================================================================
+
+# ----------------------------------------------------------------------
+# Environment variables you can set to customize the launch of the RHQ Server.
+# ----------------------------------------------------------------------
+
+# RHQ_SERVER_HOME=/path/to/server/home
+# RHQ_SERVER_DEBUG=true
+# JAVA_HOME=/path/to/java/installation
+# RHQ_SERVER_JAVA_EXE_FILE_PATH=/path/directly/to/java/executable
+# RHQ_SERVER_JAVA_OPTS=VM options
+# RHQ_SERVER_ADDITIONAL_JAVA_OPTS=additional VM options
+# RHQ_SERVER_CMDLINE_OPTS=additional run.sh options
+
+[ -f /etc/sysconfig/rhq ] && . /etc/sysconfig/rhq
+
+RHQ_SERVER_HOME=$RHQ_HOME
+RHQ_SERVER_JAVA_HOME=/usr/lib/jvm/java-1.6.0/
+
+POSTGRESQL_PACKAGES=`rpm -qa | grep postgresql | wc -l`
+
+# exit if there is no postgresql installed
+[ $POSTGRESQL_PACKAGES -eq "0" ] && exit
+
+# Configure RHQ so we don't need to use web configuration wizard
+/usr/share/rhq/preconfigure-rhq.sh > /opt/rhq/preconfigure.log
+
+# preconfigure RHQ Agent
+[ -d $RHQ_SERVER_HOME/jbossas/server/default/deploy/rhq.ear.rej ] && /usr/share/rhq/preconfigure-rhq-agent.sh > /opt/rhq/agent-preconfigure.log
+
+# ----------------------------------------------------------------------
+# Make sure we unset any lingering JBossAS environment variables that
+# were set in the user's environment. This might happen if the user
+# has an external JBossAS configured.
+# ----------------------------------------------------------------------
+
+unset JBOSS_HOME
+unset RUN_CONF
+unset JAVAC_JAR
+unset JBOSS_CLASSPATH
+
+# ----------------------------------------------------------------------
+# Dumps a message iff debug mode is enabled
+# ----------------------------------------------------------------------
+
+debug_msg ()
+{
+ # if debug variable is set, it is assumed to be on, unless its value is false
+ if [ "x$RHQ_SERVER_DEBUG" != "x" ]; then
+ if [ "$RHQ_SERVER_DEBUG" != "false" ]; then
+ echo $1
+ fi
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Sets _SERVER_STATUS, _SERVER_RUNNING and _SERVER_PID based on the
+# status of the RHQ Server VM start script (run.sh).
+# Also sets _JVM_STATUS, _JVM_RUNNING and _JVM_PID based on the
+# status of the JBossAS Java Virtual Machine.
+# ----------------------------------------------------------------------
+
+check_status ()
+{
+ if [ -f "$_SERVER_PIDFILE" ]; then
+ _SERVER_PID=`cat "$_SERVER_PIDFILE"`
+ if [ -n "$_SERVER_PID" ] && kill -0 $_SERVER_PID 2>/dev/null ; then
+ _SERVER_STATUS="RHQ Server (pid $_SERVER_PID) is $1"
+ _SERVER_RUNNING=1
+ else
+ _SERVER_STATUS="RHQ Server (pid $_SERVER_PID) is NOT running"
+ _SERVER_RUNNING=0
+ fi
+ else
+ _SERVER_STATUS="RHQ Server (no pid file) is NOT running"
+ _SERVER_RUNNING=0
+ fi
+
+ if [ -f "$_JVM_PIDFILE" ]; then
+ _JVM_PID=`cat "$_JVM_PIDFILE"`
+ if [ -n "$_JVM_PID" ] && kill -0 $_JVM_PID 2>/dev/null ; then
+ _JVM_STATUS="JBossAS Java VM child process (pid $_JVM_PID) is $1"
+ _JVM_RUNNING=1
+ else
+ _JVM_STATUS="JBossAS Java VM child process (pid $_JVM_PID) is NOT running"
+ _JVM_RUNNING=0
+ fi
+ else
+ _JVM_STATUS="JBossAS Java VM child process (no pid file) is NOT running"
+ _JVM_RUNNING=0
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Ensures that the PID files no longer exist
+# ----------------------------------------------------------------------
+
+remove_pid_files ()
+{
+ if [ -f "$_SERVER_PIDFILE" ]; then
+ rm "$_SERVER_PIDFILE"
+ fi
+ if [ -f "$_JVM_PIDFILE" ]; then
+ rm "$_JVM_PIDFILE"
+ fi
+}
+
+# ----------------------------------------------------------------------
+# Determine what specific platform we are running on.
+# Set some platform-specific variables.
+# ----------------------------------------------------------------------
+
+case "`uname`" in
+ CYGWIN*) _CYGWIN=true
+ ;;
+ Darwin*) _DARWIN=true
+ ;;
+ SunOS*) _SOLARIS=true
+ ;;
+esac
+
+# ----------------------------------------------------------------------
+# Determine the RHQ Server installation directory.
+# If RHQ_SERVER_HOME is not defined, we will assume we are running
+# directly from the server installation's bin directory.
+# ----------------------------------------------------------------------
+
+if [ -z "$RHQ_SERVER_HOME" ]; then
+ _DOLLARZERO=`readlink "$0" 2>/dev/null || echo "$0"`
+ RHQ_SERVER_HOME=`dirname "$_DOLLARZERO"`/..
+else
+ if [ ! -d "$RHQ_SERVER_HOME" ]; then
+ echo "ERROR! RHQ_SERVER_HOME is not pointing to a valid directory"
+ echo "RHQ_SERVER_HOME: $RHQ_SERVER_HOME"
+ exit 1
+ fi
+fi
+
+cd "$RHQ_SERVER_HOME"
+RHQ_SERVER_HOME=`pwd`
+
+debug_msg "RHQ_SERVER_HOME: $RHQ_SERVER_HOME"
+
+if [ ! -f "${RHQ_SERVER_HOME}/jbossas/bin/run.jar" ]; then
+ echo "ERROR! RHQ_SERVER_HOME is not pointing to a valid RHQ Server"
+ echo "Missing ${RHQ_SERVER_HOME}/jbossas/bin/run.jar"
+ exit 1
+fi
+
+# ----------------------------------------------------------------------
+# if we are on a Mac and JAVA_HOME is not set, then set it to /usr
+# as this is the default location.
+# ----------------------------------------------------------------------
+if [ -z "$JAVA_HOME" ]; then
+ if [ -n "$_DARWIN" ]; then
+ debug_msg "Running on Mac OS X, setting JAVA_HOME to /usr"
+ JAVA_HOME=/usr
+ fi
+fi
+
+# create the logs directory
+_LOG_DIR_PATH="${RHQ_SERVER_HOME}/logs"
+if [ -n "$_CYGWIN" ]; then
+ _LOG_DIR_PATH=`cygpath --windows --path "$_LOG_DIR_PATH"`
+fi
+if [ ! -d "${_LOG_DIR_PATH}" ]; then
+ mkdir "${_LOG_DIR_PATH}"
+fi
+
+# ----------------------------------------------------------------------
+# Find the Java executable and verify we have a VM available
+# ----------------------------------------------------------------------
+
+if [ -z "$RHQ_SERVER_JAVA_EXE_FILE_PATH" ]; then
+ if [ -z "$RHQ_SERVER_JAVA_HOME" ]; then
+ RHQ_SERVER_JAVA_HOME="${RHQ_SERVER_HOME}/jre"
+ debug_msg "Using the embedded JRE"
+ if [ ! -d "$RHQ_SERVER_JAVA_HOME" ]; then
+ debug_msg "No embedded JRE found - will try to use JAVA_HOME: $JAVA_HOME"
+ RHQ_SERVER_JAVA_HOME="$JAVA_HOME"
+ fi
+ fi
+ debug_msg "RHQ_SERVER_JAVA_HOME: $RHQ_SERVER_JAVA_HOME"
+ RHQ_SERVER_JAVA_EXE_FILE_PATH="${RHQ_SERVER_JAVA_HOME}/bin/java"
+fi
+debug_msg "RHQ_SERVER_JAVA_EXE_FILE_PATH: $RHQ_SERVER_JAVA_EXE_FILE_PATH"
+
+if [ ! -f "$RHQ_SERVER_JAVA_EXE_FILE_PATH" ]; then
+ echo "There is no JVM available."
+ echo "Please set RHQ_SERVER_JAVA_HOME or RHQ_SERVER_JAVA_EXE_FILE_PATH appropriately."
+ exit 1
+fi
+
+# run.sh will use JAVA as the full java command
+JAVA="$RHQ_SERVER_JAVA_EXE_FILE_PATH"
+export JAVA
+
+# ----------------------------------------------------------------------
+# Prepare the VM command line options to be passed in
+# ----------------------------------------------------------------------
+
+if [ -z "$RHQ_SERVER_JAVA_OPTS" ]; then
+ RHQ_SERVER_JAVA_OPTS="-Xms1024M -Xmx1024M -XX:PermSize=256M -XX:MaxPermSize=256M -Djava.net.preferIPv4Stack=true -Djboss.server.log.dir=${_LOG_DIR_PATH}"
+fi
+RHQ_SERVER_JAVA_OPTS="-Dapp.name=rhq-server $RHQ_SERVER_JAVA_OPTS -Djava.awt.headless=true -Djboss.platform.mbeanserver -Dsun.lang.ClassLoader.allowArraySyntax=true"
+debug_msg "RHQ_SERVER_JAVA_OPTS: $RHQ_SERVER_JAVA_OPTS"
+debug_msg "RHQ_SERVER_ADDITIONAL_JAVA_OPTS: $RHQ_SERVER_ADDITIONAL_JAVA_OPTS"
+
+# run.sh wants the options to be in the JAVA_OPTS variable
+JAVA_OPTS="$RHQ_SERVER_JAVA_OPTS $RHQ_SERVER_ADDITIONAL_JAVA_OPTS"
+export JAVA_OPTS
+
+# ----------------------------------------------------------------------
+# Prepare the command line arguments passed to the RHQ Server
+# ----------------------------------------------------------------------
+
+if [ -z "$RHQ_SERVER_CMDLINE_OPTS" ]; then
+
+ _PROPS_FILE_PATH="${RHQ_SERVER_HOME}/bin/rhq-server.properties"
+
+ # convert paths if we are on Windows
+ if [ -n "$_CYGWIN" ]; then
+ _PROPS_FILE_PATH=`cygpath --windows --path "$_PROPS_FILE_PATH"`
+ fi
+
+ RHQ_SERVER_CMDLINE_OPTS="-P ${_PROPS_FILE_PATH}"
+fi
+debug_msg "RHQ_SERVER_CMDLINE_OPTS: $RHQ_SERVER_CMDLINE_OPTS"
+
+# ----------------------------------------------------------------------
+# Now find the JBoss run.sh script
+# ----------------------------------------------------------------------
+
+_JBOSS_RUN_SCRIPT="${RHQ_SERVER_HOME}/jbossas/bin/run.sh"
+
+if [ ! -f "$_JBOSS_RUN_SCRIPT" ]; then
+ echo "ERROR! Cannot find the JBossAS run script"
+ echo "Not found: $_JBOSS_RUN_SCRIPT"
+ exit 1
+fi
+debug_msg "_JBOSS_RUN_SCRIPT: $_JBOSS_RUN_SCRIPT"
+
+# ----------------------------------------------------------------------
+# Define where we want to write the pidfiles - let user override the dir
+# Note that we actually have two pidfiles - one is for the script
+# that starts the JBossAS Java virtual machine and the second is the
+# actual server's Java virtual machine process itself.
+# ----------------------------------------------------------------------
+
+if [ -z "$RHQ_SERVER_PIDFILE_DIR" ]; then
+ RHQ_SERVER_PIDFILE_DIR="${RHQ_SERVER_HOME}/bin"
+fi
+mkdir -p "$RHQ_SERVER_PIDFILE_DIR"
+
+_SERVER_PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-server.pid"
+_JVM_PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-jvm.pid"
+
+# ----------------------------------------------------------------------
+# Execute the command that the user wants us to do
+# ----------------------------------------------------------------------
+
+check_status "running"
+
+case "$1" in
+'console')
+ if [ "$_SERVER_RUNNING" = "1" ]; then
+ echo "$_SERVER_STATUS"
+ exit 0
+ fi
+
+ echo "Starting RHQ Server in console..."
+
+ # we are running in foreground, make both pids show the same process
+ echo "$$" > "$_SERVER_PIDFILE"
+ echo "$$" > "$_JVM_PIDFILE"
+
+ # start the server, making sure its working directory is the JBossAS bin directory
+ cd "${RHQ_SERVER_HOME}/jbossas/bin"
+ "$_JBOSS_RUN_SCRIPT" $RHQ_SERVER_CMDLINE_OPTS
+
+ _JBOSS_STATUS=$?
+
+ rm "$_SERVER_PIDFILE"
+ rm "$_JVM_PIDFILE"
+
+ exit $_JBOSS_STATUS
+ ;;
+
+'start')
+ if [ "$_SERVER_RUNNING" = "1" ]; then
+ echo "$_SERVER_STATUS"
+ exit 0
+ fi
+
+ echo "Trying to start the RHQ Server..."
+
+ LAUNCH_JBOSS_IN_BACKGROUND="$_JVM_PIDFILE"
+ export LAUNCH_JBOSS_IN_BACKGROUND
+
+ # start the server, making sure its working directory is the JBossAS bin directory
+ cd "${RHQ_SERVER_HOME}/jbossas/bin"
+ if [ "x$RHQ_SERVER_DEBUG" != "x" ] && [ "$RHQ_SERVER_DEBUG" != "false" ]; then
+ "$_JBOSS_RUN_SCRIPT" $RHQ_SERVER_CMDLINE_OPTS &
+ else
+ "$_JBOSS_RUN_SCRIPT" $RHQ_SERVER_CMDLINE_OPTS > /dev/null 2>&1 &
+ fi
+
+ echo "$!" > "$_SERVER_PIDFILE"
+
+ sleep 5
+ check_status "starting"
+ echo "$_SERVER_STATUS"
+
+ if [ "$_SERVER_RUNNING" = "1" ]; then
+ exit 0
+ else
+ echo "Failed to start - make sure the RHQ Server is fully configured properly"
+ exit 1
+ fi
+ ;;
+
+'stop')
+ if [ "$_SERVER_RUNNING" = "0" ]; then
+ echo "$_SERVER_STATUS"
+ remove_pid_files
+ exit 0
+ fi
+
+ echo "Trying to stop the RHQ Server..."
+
+ echo "RHQ Server (pid=${_SERVER_PID}) is stopping..."
+
+ while [ "$_SERVER_RUNNING" = "1" ]; do
+ kill -TERM $_SERVER_PID
+ sleep 2
+ check_status "stopping..."
+ done
+
+ remove_pid_files
+ echo "RHQ Server has stopped."
+ exit 0
+ ;;
+
+'kill')
+ if [ "$_SERVER_RUNNING" = "0" ]; then
+ echo "$_SERVER_STATUS"
+ fi
+ if [ "$_JVM_RUNNING" = "0" ]; then
+ echo "$_JVM_STATUS"
+ remove_pid_files
+ exit 0
+ fi
+
+ echo "Trying to kill the RHQ Server..."
+
+ echo "RHQ Server parent process (pid=${_SERVER_PID}) is being killed..."
+ while [ "$_SERVER_RUNNING" = "1" ]; do
+ kill -9 $_SERVER_PID
+ sleep 2
+ check_status "killing..."
+ done
+
+ echo "Java Virtual Machine child process (pid=${_JVM_PID}) is being killed..."
+ while [ "$_JVM_RUNNING" = "1" ]; do
+ kill -9 $_JVM_PID
+ sleep 2
+ check_status "killing..."
+ done
+
+ remove_pid_files
+ echo "RHQ Server has been killed."
+ exit 0
+ ;;
+
+'status')
+ echo "$_SERVER_STATUS"
+ echo "$_JVM_STATUS"
+ exit 0
+ ;;
+
+*)
+ echo "Usage: $0 { start | stop | kill | status | console }"
+ exit 1
+ ;;
+esac

0 comments on commit ab33c28

Please sign in to comment.
Something went wrong with that request. Please try again.