Alon Bar-Lev has uploaded a new change for review. Change subject: notifier: move to the new service infrastructure ......................................................................
notifier: move to the new service infrastructure rename service to ovirt-engine-notifier to match other services. Change-Id: I2aadeca8b3017dad4107939c7c624ef020347b94 Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M .gitignore M Makefile D packaging/bin/engine-notifier-service.sh D packaging/bin/engine-notifier.sh R packaging/conf/notifier.conf.defaults.in M packaging/fedora/setup/basedefs.py M packaging/fedora/setup/common_utils.py M packaging/fedora/setup/engine-cleanup.py M packaging/fedora/setup/engine-upgrade.py M packaging/fedora/spec/ovirt-engine.spec.in M packaging/services/config.py.in A packaging/services/ovirt-engine-notifier.py A packaging/services/ovirt-engine-notifier.systemd.in A packaging/services/ovirt-engine-notifier.sysv.in 14 files changed, 424 insertions(+), 426 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/14378/1 diff --git a/.gitignore b/.gitignore index e2293b7..a3f07ff 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,6 @@ packaging/etc/engine-manage-domains/log4j.xml packaging/etc/notifier/log4j.xml packaging/services/config.py -packaging/services/ovirt-engine.systemd -packaging/services/ovirt-engine.sysv +packaging/services/*.systemd +packaging/services/*.sysv packaging/fedora/spec/ovirt-engine.spec diff --git a/Makefile b/Makefile index 9710221..969c66d 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,8 @@ sed \ -e "s|@ENGINE_DEFAULTS@|$(DATA_DIR)/conf/engine.conf.defaults|g" \ -e "s|@ENGINE_VARS@|$(PKG_SYSCONF_DIR)/engine.conf|g" \ + -e "s|@ENGINE_NOTIFIER_DEFAULTS@|$(DATA_DIR)/conf/notifier.conf.defaults|g" \ + -e "s|@ENGINE_NOTIFIER_VARS@|$(PKG_SYSCONF_DIR)/notifier/notifier.conf|g" \ -e "s|@ENGINE_USER@|$(PKG_USER)|g" \ -e "s|@ENGINE_GROUP@|$(PKG_GROUP)|g" \ -e "s|@ENGINE_ETC@|$(PKG_SYSCONF_DIR)|g" \ @@ -134,12 +136,15 @@ GENERATED = \ packaging/bin/engine-prolog.sh \ packaging/conf/engine.conf.defaults \ + packaging/conf/notifier.conf.defaults \ packaging/etc/engine-config/log4j.xml \ packaging/etc/engine-manage-domains/log4j.xml \ packaging/etc/notifier/log4j.xml \ packaging/services/config.py \ packaging/services/ovirt-engine.systemd \ packaging/services/ovirt-engine.sysv \ + packaging/services/ovirt-engine-notifier.systemd \ + packaging/services/ovirt-engine-notifier.sysv \ packaging/fedora/spec/ovirt-engine.spec \ $(NULL) @@ -180,7 +185,6 @@ install_artifacts \ install_config \ install_sysprep \ - install_notification_service \ install_db_scripts \ install_setup \ install_misc \ @@ -188,6 +192,7 @@ install_aio_plugin \ install_jboss_modules \ install_service \ + install_notification_service \ $(NULL) packaging/fedora/spec/ovirt-engine.spec: version.mak @@ -379,14 +384,12 @@ install -dm 755 $(DESTDIR)$(PKG_SYSCONF_DIR)/notifier - # Configuration files: install -m 644 packaging/etc/notifier/log4j.xml $(DESTDIR)$(PKG_SYSCONF_DIR)/notifier/log4j.xml install -d -m 755 $(DESTDIR)$(PKG_SYSCONF_DIR)/notifier/notifier.conf.d - install -m 640 packaging/conf/notifier.conf.defaults $(DESTDIR)$(DATA_DIR)/conf/notifier.conf.defaults - - # Main program: - install -m 755 packaging/bin/engine-notifier.sh $(DESTDIR)$(DATA_DIR)/bin/engine-notifier.sh - install -m 755 packaging/bin/engine-notifier-service.sh $(DESTDIR)$(SYSCONF_DIR)/rc.d/init.d/engine-notifierd + install -m 644 packaging/conf/notifier.conf.defaults $(DESTDIR)$(DATA_DIR)/conf/notifier.conf.defaults + install -m 755 packaging/services/ovirt-engine-notifier.py $(DESTDIR)$(DATA_DIR)/services + install -m 755 packaging/services/ovirt-engine-notifier.systemd $(DESTDIR)$(DATA_DIR)/services + install -m 755 packaging/services/ovirt-engine-notifier.sysv $(DESTDIR)$(DATA_DIR)/services install_db_scripts: @echo "*** Deploying Database scripts" @@ -410,6 +413,12 @@ install -m 755 packaging/resources/ovirtlogrot.sh ${DESTDIR}$(DATA_DIR)/scripts/ install -m 755 packaging/resources/ovirt-cron ${DESTDIR}$(SYSCONF_DIR)/cron.daily/ + # Service common + install -dm 755 $(DESTDIR)$(DATA_DIR)/services + install -m 644 packaging/services/__init__.py $(DESTDIR)$(DATA_DIR)/services + install -m 644 packaging/services/config.py $(DESTDIR)$(DATA_DIR)/services + install -m 644 packaging/services/service.py $(DESTDIR)$(DATA_DIR)/services + # USB filter: install -m 644 packaging/etc/usbfilter.txt $(DESTDIR)$(PKG_SYSCONF_DIR) @@ -427,10 +436,6 @@ @echo "*** Deploying service" # Install the files: - install -dm 755 $(DESTDIR)$(DATA_DIR)/services - install -m 644 packaging/services/__init__.py $(DESTDIR)$(DATA_DIR)/services - install -m 644 packaging/services/config.py $(DESTDIR)$(DATA_DIR)/services - install -m 644 packaging/services/service.py $(DESTDIR)$(DATA_DIR)/services install -m 644 packaging/services/ovirt-engine.xml.in $(DESTDIR)$(DATA_DIR)/services install -m 644 packaging/services/ovirt-engine-logging.properties.in $(DESTDIR)$(DATA_DIR)/services install -m 755 packaging/services/ovirt-engine.py $(DESTDIR)$(DATA_DIR)/services diff --git a/packaging/bin/engine-notifier-service.sh b/packaging/bin/engine-notifier-service.sh deleted file mode 100755 index 2f72b88..0000000 --- a/packaging/bin/engine-notifier-service.sh +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/sh -# -# This shell script takes care of starting and stopping oVirt event notification service -# -# chkconfig: - 80 20 -# description: The oVirt event notification service -# processname: notifierd -# pidfile: /var/run/ovirt-engine/notifier/engine-notifier.pid -# config: /etc/ovirt-engine/notifier/notifier.conf -# - -# Source function library. -. /etc/init.d/functions - -prog=engine-notifier -RETVAL=0 -PID_FOLDER=/var/run/ovirt-engine/notifier -ENGINE_USER="ovirt" - -[ -r /etc/java/java.conf ] && . /etc/java/java.conf -export JAVA_HOME - -# Path to the engine-notifier launch script -NOTIFIER_SCRIPT=/usr/share/ovirt-engine/bin/engine-notifier.sh - -startup_dir="$(getent passwd $ENGINE_USER | cut -d: -f6)" -if [ -d "$startup_dir" ]; then - cd "$startup_dir" -else - cd / -fi - -if [ -z "$SHUTDOWN_WAIT" ]; then - SHUTDOWN_WAIT=10 -fi - -if [ -z "$NOTIFIER_PID" ]; then - mkdir -p $PID_FOLDER - if [ $? -ne 0 ]; then - echo "Error: Please check permissions, can not create PID folder: $PID_FOLDER. " - exit 5 - fi - NOTIFIER_PID=$PID_FOLDER/$prog.pid -fi - -lock_file=/var/lock/subsys/$prog - -start() { - if [ -f $lock_file ] ; then - if [ -f $NOTIFIER_PID ]; then - read kpid < $NOTIFIER_PID - if checkpid $kpid 2>&1; then - echo "$prog process (pid $kpid) is already running" - return 0 - else - echo "lock file found but no process is running for pid $kpid, continuing" - fi - fi - fi - echo -n $"Starting $prog: at $(date)" - - daemon --user $ENGINE_USER NOTIFIER_PID=$NOTIFIER_PID $NOTIFIER_SCRIPT - RETVAL=$? - [ $RETVAL = 0 ] && touch $lock_file && success || failure - echo - return $RETVAL -} - -stop() { - - if [ -f $lock_file ] ; then - echo -n $"Stopping $prog: " - killproc -p $NOTIFIER_PID -d $SHUTDOWN_WAIT - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - rm -f $lock_file $NOTIFIER_PID - fi - fi -} - -status() { - RETVAL="1" - STOPPED="0" - if [ -f "$NOTIFIER_PID" ]; then - read kpid < $NOTIFIER_PID - if checkpid $kpid 2>&1; then - echo "$0 is running (${kpid})" - RETVAL="0" - else - echo "Notifier service is not running for pid $kpid" - rm -f $lock_file $NOTIFIER_PID - fi - else - pid="$(pgrep -fu $ENGINE_USER org\.ovirt\.engine\.core\.notifier\.Notifier)" - if [ -n "$pid" ]; then - echo "Notifier service $0 running (${pid}) but no PID file exists" - RETVAL="0" - else - echo "$0 is stopped" - rm -f $lock_file - fi - fi - return $RETVAL -} - - -# See how we were called. -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status - ;; - restart) - stop - sleep 2 - start - ;; - condrestart) - if [ -f $NOTIFIER_PID ] ; then - stop - start - fi - ;; - *) - echo "Usage: $0 {start|stop|status|restart|condrestart}" - RETVAL=3 -esac - -exit $RETVAL - -# -# -# end diff --git a/packaging/bin/engine-notifier.sh b/packaging/bin/engine-notifier.sh deleted file mode 100755 index 06b5bda..0000000 --- a/packaging/bin/engine-notifier.sh +++ /dev/null @@ -1,232 +0,0 @@ -#!/bin/sh -# -# This script is designed to run the oVirt Event Notification service. -# The script assumes all RPM dependencies were installed, so jar -# files can be found under /usr/share/java. The service's configuration -# should be under the /etc directory by default. -# - -# Load the prolog: -. "$(dirname "$(readlink -f "$0")")"/engine-prolog.sh - -usage () { - printf "engine-notifier: oVirt Event Notification Service\n" - printf "USAGE:\n" - printf "\tengine-notifier [configuration file]\n" - return 0 -} - -die_no_propset() { - # exit when property defined but not set then exit - die "Error: $1 if defined can not be empty, please check for this in configuration file $CONF_FILE\n" 6 -} - -check_email_format() { - #exit with a message if the property is not in user@domain format - if [[ ${!1} != *?@?* ]] ; then - die "Error: $1 must be of the form user@domain" - fi -} - -check_port_number(){ - #exit with a message if the property is not a valid port number - if ! [[ "${!1}" =~ ^-?[0-9]+$ ]] ; then - die "Error: $1 must be a valid port number" - elif [ ${!1} -lt 1 ] || [ ${!1} -gt 65536 ] ; then - die "Error: $1 must be a number between 0 and 65536" - fi - - -} - -check_boolean(){ - #exit with a message if the property is not true or false - if ! [[ ${!1} == "true" ]] || [[ ${!1} == "false" ]] ; then - die "Error: $1 must be true or false" - fi - -} - -if [ "$1" == "--help" -o "$1" == "-h" ]; then - usage - exit 0 -fi - -if [ "$#" -gt 1 ]; then - usage - die "Error: wrong argument number: $#.\n" 2 -fi - -if [ "$#" -eq 1 ]; then - if [ ! -r "$1" ]; then - die "Error: configuration file does not exist or has no read permission: $1.\n" 6 - fi - CONF_FILE="$1" -else - CONF_FILE="${ENGINE_ETC}/notifier/notifier.conf" -fi - -# Import configurations safely -old_IFS=$IFS -IFS=$'\n' -for line in `sed -e 's/[ \t]*#.*//' -e '/^[ \t]*$/d' $CONF_FILE`: -do - declare "$line" -done -IFS=$old_IFS - -# Do basic checking of properties in configuration file to ensure -# a) properties are defined -# b) when properties are defined and reference a file system resource, that the resource exists. - -# MAIL_SERVER is required! -if [ -z "$MAIL_SERVER" ]; then - die "Error: \$MAIL_SERVER is not defined, please check for this in configuration file $CONF_FILE\n" 6 -fi - -# Remove possible : at the end of the MAIL_SERVER address -MAIL_SERVER=`echo $MAIL_SERVER | cut -d ':' -f 1` -nslookup $MAIL_SERVER &>/dev/null -if [ $? -ne 0 ] ; then - die "Error: \$MAIL_SERVER ($MAIL_SERVER) must contain resolvable address" -fi - - -# Now check for properties that if defined, can not be empty -# INTERVAL_IN_SECONDS if defined can not be empty -if [ "${INTERVAL_IN_SECONDS+x}" ]; then - if [ -z "$INTERVAL_IN_SECONDS" ]; then - die_no_propset \$INTERVAL_IN_SECONDS - fi -fi - -# MAIL_PORT if defined can not be empty -if [ "${MAIL_PORT+x}" ]; then - if [ -z "$MAIL_PORT" ]; then - die_no_propset \$MAIL_PORT - fi - check_port_number "MAIL_PORT" -fi - -# MAIL_USER if defined can not be empty -if [ "${MAIL_USER+x}" ]; then - if [ -z "$MAIL_USER" ]; then - die_no_propset \$MAIL_USER - fi - check_email_format "MAIL_USER" -fi - -# MAIL_PASSWORD if defined can not be empty -if [ "${MAIL_PASSWORD+x}" ]; then - if [ -z "$MAIL_PASSWORD" ]; then - die_no_propset \$MAIL_PASSWORD - fi -fi - -# MAIL_ENABLE_SSL if defined can not be empty -if [ "${MAIL_ENABLE_SSL+x}" ]; then - if [ -z "$MAIL_ENABLE_SSL" ]; then - die_no_propset \$MAIL_ENABLE_SSL - else - # MAIL_USER if can not be empty for SSL - if [ -z "${MAIL_USER}" ]; then - die "Error: \$MAIL_USER is not defined for SSL MAIL, please check for this in configuration file $CONF_FILE\n" 6 - fi - # MAIL_PASSWORD can not be empty for SSL - if [ -z "${MAIL_PASSWORD}" ]; then - die "Error: \$MAIL_PASSWORD is not defined for SSL MAIL, please check for this in configuration file $CONF_FILE\n" 6 - fi - fi -fi - -# HTML_MESSAGE_FORMAT if defined can not be empty -if [ "${HTML_MESSAGE_FORMAT+x}" ]; then - if [ -z "$HTML_MESSAGE_FORMAT" ]; then - die_no_propset \$HTML_MESSAGE_FORMAT - fi - check_boolean "HTML_MESSAGE_FORMAT" -fi - -# MAIL_FROM if defined can not be empty -if [ "${MAIL_FROM+x}" ]; then - if [ -z "$MAIL_FROM" ]; then - die_no_propset \$MAIL_FROM - fi - check_email_format "MAIL_FROM" -fi - -# MAIL_REPLY_TO if defined can not be empty -if [ "${MAIL_REPLY_TO+x}" ]; then - if [ -z "$MAIL_REPLY_TO" ]; then - die_no_propset \$MAIL_REPLY_TO - fi -fi - -# DAYS_TO_KEEP_HISTORY if defined can not be empty -if [ "${DAYS_TO_KEEP_HISTORY+x}" ]; then - if [ -z "$DAYS_TO_KEEP_HISTORY" ]; then - die_no_propset \$DAYS_TO_KEEP_HISTORY - fi -fi - -# ENGINE_INTERVAL_IN_SECONDS if defined can not be empty -if [ "${ENGINE_INTERVAL_IN_SECONDS+x}" ]; then - if [ -z "$ENGINE_INTERVAL_IN_SECONDS" ]; then - die_no_propset \$ENGINE_INTERVAL_IN_SECONDS - fi -fi - -# ENGINE_MONITOR_RETRIES if defined can not be empty -if [ "${ENGINE_MONITOR_RETRIES+x}" ]; then - if [ -z "$ENGINE_MONITOR_RETRIES" ]; then - die_no_propset \$ENGINE_MONITOR_RETRIES - fi -fi - -# ENGINE_TIMEOUT_IN_SECONDS if defined can not be empty -if [ "${ENGINE_TIMEOUT_IN_SECONDS+x}" ]; then - if [ -z "$ENGINE_TIMEOUT_IN_SECONDS" ]; then - die_no_propset \$ENGINE_TIMEOUT_IN_SECONDS - fi -fi - -# IS_HTTPS_PROTOCOL if defined can not be empty -if [ "${IS_HTTPS_PROTOCOL+x}" ]; then - if [ -z "$IS_HTTPS_PROTOCOL" ]; then - die_no_propset \$IS_HTTPS_PROTOCOL - fi -fi - -# IS_NONREPEATED_NOTIFICATION if defined can not be empty -if [ "${IS_NONREPEATED_NOTIFICATION+x}" ]; then - if [ -z "$IS_NONREPEATED_NOTIFICATION" ]; then - die_no_propset \$IS_NONREPEATED_NOTIFICATION - fi -fi - -if [ -z "$NOTIFIER_PID" ] -then - NOTIFIER_PID=/dev/null -fi - -# -# Add this option to the java command line to enable remote debugging in -# all IP addresses and port 8787: -# -# -Xrunjdwp:transport=dt_socket,address=0.0.0.0:8787,server=y,suspend=y -# -# Note that the "suspend=y" options is needed to suspend the execution -# of the JVM till you connect with the debugger, otherwise it is -# not possible to debug the execution of the main method. -# - -NOTIFIER_VARS="${CONF_FILE}" -"${JAVA_HOME}/bin/java" \ - -Dlog4j.configuration="file:${ENGINE_ETC}/notifier/log4j.xml" \ - -Djboss.modules.write-indexes=false \ - -jar "${JBOSS_HOME}/jboss-modules.jar" \ - -dependencies org.ovirt.engine.core.tools \ - -class org.ovirt.engine.core.notifier.Notifier \ - 2>/dev/null & - -echo $! >$NOTIFIER_PID diff --git a/packaging/conf/notifier.conf.defaults b/packaging/conf/notifier.conf.defaults.in similarity index 87% rename from packaging/conf/notifier.conf.defaults rename to packaging/conf/notifier.conf.defaults.in index fee57bb..d79dac7 100644 --- a/packaging/conf/notifier.conf.defaults +++ b/packaging/conf/notifier.conf.defaults.in @@ -3,6 +3,29 @@ # The daemon consists of two major services: notification service and engine monitoring. # +# +# The location of the Java virtual machine used by the engine: +# +JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64 + +# +# The location of the application server used by the engine: +# +JBOSS_HOME=/usr/share/jboss-as + +# +# Important directories used by the engine: +# +ENGINE_ETC="@ENGINE_ETC@" +ENGINE_LOG="@ENGINE_LOG@" +ENGINE_USR="@ENGINE_USR@" + +# +# Service timeouts +# +NOTIFIER_STOP_TIME=30 +NOTIFIER_STOP_INTERVAL=1 + #-------------------------------------# # Notification Service Configuration: # #-------------------------------------# diff --git a/packaging/fedora/setup/basedefs.py b/packaging/fedora/setup/basedefs.py index ebb8b5b..c600900 100644 --- a/packaging/fedora/setup/basedefs.py +++ b/packaging/fedora/setup/basedefs.py @@ -19,7 +19,8 @@ ENGINE_GROUP_NAME="ovirt" HTTPD_SERVICE_NAME="httpd" HTTP_PORT_POLICY="http_port_t" -NOTIFIER_SERVICE_NAME = "engine-notifierd" +NOTIFIER_SERVICE_NAME = "ovirt-engine-notifier" +NOTIFIER_SERVICE_OLD_NAME = "engine-notifierd" ETL_SERVICE_NAME = "ovirt-engine-dwhd" FREEIPA_RPM = "freeipa-server" IPA_RPM = "ipa-server" @@ -134,6 +135,8 @@ # Files containing the local configuration of the engine: FILE_ENGINE_CONF="/etc/ovirt-engine/engine.conf" DIR_ENGINE_CONF="%s.d" % FILE_ENGINE_CONF +FILE_ENGINE_NOTIFIER_CONF="/etc/ovirt-engine/notifier/notifier.conf" +DIR_ENGINE_NOTIFIER_CONF="%s.d" % FILE_ENGINE_NOTIFIER_CONF # File containing the setup generated database configuration of the engine: FILE_ENGINE_CONF_DATABASE="%s/50-setup-database.conf" % DIR_ENGINE_CONF @@ -143,6 +146,7 @@ # File containing the setup generated java configuration of the engine: FILE_ENGINE_CONF_JAVA="%s/50-setup-java.conf" % DIR_ENGINE_CONF +FILE_ENGINE_NOTIFIER_CONF_JAVA="%s/50-setup-java.conf" % DIR_ENGINE_NOTIFIER_CONF # File containing the setup generated java configuration of the engine: FILE_ENGINE_CONF_PKI="%s/50-setup-pki.conf" % DIR_ENGINE_CONF diff --git a/packaging/fedora/setup/common_utils.py b/packaging/fedora/setup/common_utils.py index 00fba20..51ca5a0 100755 --- a/packaging/fedora/setup/common_utils.py +++ b/packaging/fedora/setup/common_utils.py @@ -1232,17 +1232,12 @@ handler.close() def editEngineSysconfigJava(javaHome): - # Load the file: - logging.debug("Loading text file handler") - handler = TextConfigFileHandler(basedefs.FILE_ENGINE_CONF_JAVA, readExisting=False) - handler.open() - - # Save the Java home: - handler.editParam("JAVA_HOME", javaHome) - - # Save and close the file: - logging.debug("Engine has been configured") - handler.close() + for f in (basedefs.FILE_ENGINE_CONF_JAVA, basedefs.FILE_ENGINE_NOTIFIER_CONF_JAVA): + handler = TextConfigFileHandler(f, readExisting=False) + handler.open() + handler.editParam("JAVA_HOME", javaHome) + logging.debug("Engine has been configured") + handler.close() def editEngineSysconfigPKI( pkidir, diff --git a/packaging/fedora/setup/engine-cleanup.py b/packaging/fedora/setup/engine-cleanup.py index a5cf081..69ac48f 100755 --- a/packaging/fedora/setup/engine-cleanup.py +++ b/packaging/fedora/setup/engine-cleanup.py @@ -48,7 +48,7 @@ MSG_INFO_DONE = "DONE" MSG_INFO_ERROR = "ERROR" MSG_INFO_STOP_ENGINE = "Stopping %s service" % basedefs.ENGINE_SERVICE_NAME -MSG_INFO_STOP_NOTIFIERD = "Stopping engine-notifierd service" +MSG_INFO_STOP_NOTIFIERD = "Stopping engine notifier service" MSG_INFO_BACKUP_DB = "Backing Up Database" MSG_INFO_REMOVE_DB = "Removing Database" MSG_INFO_REMOVE_CA = "Removing CA" @@ -420,11 +420,12 @@ raise OSError(MSG_ERR_FAILED_ENGINE_SERVICE_STILL_RUN) def stopNotifier(): - logging.debug("stoping engine-notifierd service.") + logging.debug("stoping engine notifier service.") - notifier = utils.Service(basedefs.NOTIFIER_SERVICE_NAME) - if notifier.isServiceAvailable(): - notifier.stop(True) + for s in (basedefs.NOTIFIER_SERVICE_NAME, basedefs.NOTIFIER_SERVICE_OLD_NAME): + notifier = utils.Service(s) + if notifier.isServiceAvailable(): + notifier.stop(True) def runFunc(funcs, dispString): sys.stdout.write("%s..." % dispString) diff --git a/packaging/fedora/setup/engine-upgrade.py b/packaging/fedora/setup/engine-upgrade.py index 5673901..67b133d 100755 --- a/packaging/fedora/setup/engine-upgrade.py +++ b/packaging/fedora/setup/engine-upgrade.py @@ -639,7 +639,7 @@ messages.append(MSG_INFO_REPORTS) -def stopDbRelatedServices(etlService, notificationService): +def stopDbRelatedServices(etlService, notificationServices): """ shut down etl and notifier services in order to disconnect any open sessions to the db @@ -654,18 +654,19 @@ messages.append(MSG_ERR_FAILED_STOP_SERVICE % etlService.name) # If the ovirt-engine-notifierd service is up, then try and stop it. - if notificationService.isServiceAvailable(): - try: - (status, rc) = notificationService.status() - if utils.verifyStringFormat(status, ".*running.*"): - logging.debug("stopping %s service.", notificationService.name) - notificationService.stop() - except: - logging.warn("Failed to stop %s service", notificationService.name) - logging.warn(traceback.format_exc()) - messages.append(MSG_ERR_FAILED_STOP_SERVICE % notificationService.name) + for s in notificationServices: + if s.isServiceAvailable(): + try: + (status, rc) = s.status() + if utils.verifyStringFormat(status, ".*running.*"): + logging.debug("stopping %s service.", s.name) + s.stop() + except: + logging.warn("Failed to stop %s service", s.name) + logging.warn(traceback.format_exc()) + messages.append(MSG_ERR_FAILED_STOP_SERVICE % s.name) -def startDbRelatedServices(etlService, notificationService): +def startDbRelatedServices(etlService, notificationServices): """ bring back any service we stopped we won't start services that are down @@ -677,11 +678,13 @@ logging.warn("Failed to start %s", etlService.name) messages.append(MSG_ERR_FAILED_START_SERVICE % etlService.name) - if notificationService.isServiceAvailable(): - (output, rc) = notificationService.conditionalStart() - if rc != 0: - logging.warn("Failed to start %s: exit code %d", notificationService.name, rc) - messages.append(MSG_ERR_FAILED_START_SERVICE % notificationService.name) + for s in notificationServices: + if s.isServiceAvailable(): + (output, rc) = s.conditionalStart() + if rc != 0: + logging.warn("Failed to start %s: exit code %d", s.name, rc) + messages.append(MSG_ERR_FAILED_START_SERVICE % s.name) + break def unsupportedVersionsPresent(oldversion=UNSUPPORTED_VERSION, dbName=basedefs.DB_NAME): """ Check whether there are UNSUPPORTED_VERSION @@ -1146,7 +1149,10 @@ engineService = basedefs.ENGINE_SERVICE_NAME # define db connections services etlService = utils.Service(basedefs.ETL_SERVICE_NAME) - notificationService = utils.Service(basedefs.NOTIFIER_SERVICE_NAME) + notificationServices = ( + utils.Service(basedefs.NOTIFIER_SERVICE_NAME), + utils.Service(basedefs.NOTIFIER_SERVICE_OLD_NAME), + ) # Check for the available free space in required locations: # 1. DB backups location @@ -1221,7 +1227,7 @@ # Stopping engine runFunc(stopEngineService, MSG_INFO_STOP_ENGINE % engineService) if updateRelatedToDB: - runFunc([[stopDbRelatedServices, etlService, notificationService]], MSG_INFO_STOP_DB) + runFunc([[stopDbRelatedServices, etlService, notificationServices]], MSG_INFO_STOP_DB) if not options.ignore_tasks: # Check that there are no running tasks/compensations @@ -1233,7 +1239,7 @@ checkRunningTasks() # If something went wrong, restart DB services and the engine except: - runFunc([[startDbRelatedServices, etlService, notificationService]], MSG_INFO_START_DB) + runFunc([[startDbRelatedServices, etlService, notificationServices]], MSG_INFO_START_DB) runFunc(startEngineService, MSG_INFO_START_ENGINE % engineService) raise else: @@ -1267,7 +1273,7 @@ runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB) # Bring up any services we shut down before db upgrade - startDbRelatedServices(etlService, notificationService) + startDbRelatedServices(etlService, notificationServices) # CA restore runFunc([ca.prepare], MSG_INFO_PKI_PREPARE) diff --git a/packaging/fedora/spec/ovirt-engine.spec.in b/packaging/fedora/spec/ovirt-engine.spec.in index ea5805e..6909b75 100644 --- a/packaging/fedora/spec/ovirt-engine.spec.in +++ b/packaging/fedora/spec/ovirt-engine.spec.in @@ -274,10 +274,31 @@ Summary: %{product_name_short} Tools Group: Virtualization/Management Requires: %{name} = %{version}-%{release} +Requires: java + +%if %{install_systemd} +Requires(post): systemd +Requires(preun): systemd +Requires(postun): systemd +%endif %description tools %{product_name_short} Tools +%post tools +%if %{install_systemd} +%systemd_post ovirt-engine-notifier.service +%endif + +%postun tools +%if %{install_systemd} +%systemd_postun ovirt-engine-notifier.service +%endif + +%preun tools +%if %{install_systemd} +%systemd_preun ovirt-engine-notifier.service +%endif %package setup-plugin-allinone Summary: All-in-one plugin for %{product_name_short}'s setup @@ -377,12 +398,14 @@ %if %{install_systemd} install -dm 755 "%{buildroot}%{_unitdir}" cp "%{buildroot}%{engine_data}/services/ovirt-engine.systemd" "%{buildroot}%{_unitdir}/ovirt-engine.service" +cp "%{buildroot}%{engine_data}/services/ovirt-engine-notifier.systemd" "%{buildroot}%{_unitdir}/ovirt-engine-notifier.service" %endif # Install System V init scripts: %if %{install_systemv} install -dm 755 "%{buildroot}%{_initddir}" cp "%{buildroot}%{engine_data}/services/ovirt-engine.sysv" "%{buildroot}%{_initddir}/ovirt-engine" +cp "%{buildroot}%{engine_data}/services/ovirt-engine-notifier.sysv" "%{buildroot}%{_initddir}/ovirt-engine-notifier" %endif # backward compatibly (pre-3.3.0) @@ -476,6 +499,11 @@ %config(noreplace) %{engine_etc}/engine.conf %dir %{engine_etc}/engine.conf.d +# Services common +%{engine_data}/services/__init__.py +%{engine_data}/services/config.py +%{engine_data}/services/service.py + # Jar files used by all the components: %dir %{engine_java} %{engine_java}/common.jar @@ -508,7 +536,7 @@ %dir %{engine_data}/ui-plugins # Files needed by the service: -%{engine_data}/services +%{engine_data}/services/ovirt-engine.* %if %{install_systemd} %{_unitdir}/ovirt-engine.service %endif @@ -629,6 +657,14 @@ %{_mandir}/man8/engine-setup.* %{_mandir}/man8/engine-upgrade.* +# Configuration files +%{engine_data}/conf/iptables.default +%{engine_data}/conf/engine-config-install.properties +%{engine_data}/conf/nfs.sysconfig +%{engine_data}/conf/ovirt-engine-proxy.conf.in +%{engine_data}/conf/ovirt-engine-root-redirect.conf.in +%{engine_data}/conf/version + # Plugins directory: %dir %{engine_data}/scripts/plugins %{engine_data}/scripts/plugins/example_plugin_000.py* @@ -681,9 +717,7 @@ %{engine_data}/bin/engine-config.sh %{engine_data}/bin/engine-encrypt-passwd.sh %{engine_data}/bin/engine-manage-domains.sh -%{engine_data}/bin/engine-notifier.sh %{engine_data}/bin/engine-prolog.sh -%{_initddir}/engine-notifierd # Links to the scripts: %{_bindir}/engine-config @@ -706,10 +740,15 @@ # Configuration files for the notifier: %dir %{engine_etc}/notifier %dir %{engine_etc}/notifier/notifier.conf.d -%{engine_etc}/notifier/log4j.xml +%config %{engine_etc}/notifier/log4j.xml +%{engine_data}/services/ovirt-engine-notifier.* # Jar files: %{engine_java}/tools.jar + +# Config files: +%{engine_data}/conf/jaas.conf +%{engine_data}/conf/notifier.conf.defaults # POM files: %if %{install_poms} @@ -721,6 +760,14 @@ %dir %attr(-, %{engine_user}, %{engine_group}) %{engine_log}/notifier %dir %attr(-, %{engine_user}, %{engine_group}) %{engine_run}/notifier +# Files needed by the service: +%{engine_data}/services +%if %{install_systemd} +%{_unitdir}/ovirt-engine-notifier.service +%endif +%if %{install_systemv} +%{_initddir}/ovirt-engine-notifier +%endif %changelog * Thu Jan 17 2013 Juan Hernandez <juan.hernan...@redhat.com> - 3.3.0-1 diff --git a/packaging/services/config.py.in b/packaging/services/config.py.in index 45df68b..fe9a873 100644 --- a/packaging/services/config.py.in +++ b/packaging/services/config.py.in @@ -15,6 +15,8 @@ ENGINE_DEFAULT_FILE = '@ENGINE_DEFAULTS@' ENGINE_VARS = '@ENGINE_VARS@' +ENGINE_NOTIFIER_DEFAULT_FILE = '@ENGINE_NOTIFIER_DEFAULTS@' +ENGINE_NOTIFIER_VARS = '@ENGINE_NOTIFIER_VARS@' # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/services/ovirt-engine-notifier.py b/packaging/services/ovirt-engine-notifier.py new file mode 100755 index 0000000..824542c --- /dev/null +++ b/packaging/services/ovirt-engine-notifier.py @@ -0,0 +1,197 @@ +#!/usr/bin/python + +# Copyright 2012 Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import gettext +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine') + + +import config +import service + + +class Daemon(service.Daemon): + + def __init__(self): + super(Daemon, self).__init__() + + def _checkInstallation( + self, + pidfile, + jbossModulesJar, + java, + ): + # Check that the Java home directory exists and that it contais at + # least the java executable: + self.check( + name=self._config.getString('JAVA_HOME'), + directory=True, + ) + self.check( + name=java, + executable=True, + ) + + # Check the required JBoss directories and files: + self.check( + name=self._config.getString('JBOSS_HOME'), + directory=True, + ) + self.check( + name=jbossModulesJar, + ) + + # Check the required engine directories and files: + self.check( + os.path.join( + self._config.getString('ENGINE_USR'), + 'services', + ), + directory=True, + ) + self.check( + os.path.join( + self._config.getString('ENGINE_LOG'), + 'notifier', + ), + directory=True, + writable=True, + ) + for log in ('notifier.log', 'console.log'): + self.check( + name=os.path.join( + self._config.getString("ENGINE_LOG"), + 'notifier', + log, + ), + mustExist=False, + writable=True, + ) + if pidfile is not None: + self.check( + name=pidfile, + writable=True, + mustExist=False, + ) + + def daemonSetup(self): + + if os.geteuid() == 0: + raise RuntimeError( + _('This service cannot be executed as root') + ) + + if not os.path.exists(config.ENGINE_NOTIFIER_DEFAULT_FILE): + raise RuntimeError( + _( + "The configuration defaults file '{file}' " + "required but missing" + ).format( + file=config.ENGINE_NOTIFIER_DEFAULT_FILE, + ) + ) + + self._config = service.ConfigFile( + ( + config.ENGINE_NOTIFIER_DEFAULT_FILE, + config.ENGINE_NOTIFIER_VARS, + ), + ) + + jbossModulesJar = os.path.join( + self._config.getString('JBOSS_HOME'), + 'jboss-modules.jar', + ) + java = os.path.join( + self._config.getString('JAVA_HOME'), + 'bin', + 'java', + ) + + self._checkInstallation( + pidfile=self.pidfile, + jbossModulesJar=jbossModulesJar, + java=java, + ) + + self._executable = java + + self._engineArgs = [ + 'ovirt-engine-notifier', + '-Dlog4j.configuration=file://%s/notifier/log4j.xml' % ( + self._config.getString('ENGINE_ETC'), + ), + '-Djboss.modules.write-indexes=false', + '-jar', jbossModulesJar, + '-dependencies', 'org.ovirt.engine.core.tools', + '-class', 'org.ovirt.engine.core.notifier.Notifier', + ] + + self._engineEnv = os.environ.copy() + self._engineEnv.update({ + 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin', + 'LANG': 'en_US.UTF-8', + 'LC_ALL': 'en_US.UTF-8', + 'CLASSPATH': '', + 'JAVA_MODULEPATH': ':'.join([ + os.path.join( + self._config.getString('ENGINE_USR'), + 'modules', + ), + os.path.join( + self._config.getString('JBOSS_HOME'), + 'modules', + ), + ]), + 'ENGINE_DEFAULTS': config.ENGINE_DEFAULT_FILE, + 'ENGINE_VARS': config.ENGINE_VARS, + 'ENGINE_NOTIFIER_DEFAULTS': config.ENGINE_NOTIFIER_DEFAULT_FILE, + 'ENGINE_NOTIFIER_VARS': config.ENGINE_NOTIFIER_VARS, + }) + + def daemonStdHandles(self): + consoleLog = open( + os.path.join( + self._config.getString('ENGINE_LOG'), + 'notifier', + 'console.log' + ), + 'w+', + ) + return (consoleLog, consoleLog) + + def daemonContext(self): + self.daemonAsExternalProcess( + executable=self._executable, + args=self._engineArgs, + env=self._engineEnv, + stopTime=self._config.getInteger( + 'NOTIFIER_STOP_TIME' + ), + stopInterval=self._config.getInteger( + 'NOTIFIER_STOP_INTERVAL' + ), + ) + + +if __name__ == '__main__': + service.setupLogger() + d = Daemon() + d.run() + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/services/ovirt-engine-notifier.systemd.in b/packaging/services/ovirt-engine-notifier.systemd.in new file mode 100644 index 0000000..eeaa2bb --- /dev/null +++ b/packaging/services/ovirt-engine-notifier.systemd.in @@ -0,0 +1,13 @@ +[Unit] +Description=oVirt Engine Notifier +After=network.service postgresql.service + +[Service] +Type=simple +User=@ENGINE_USER@ +Group=@ENGINE_GROUP@ +ExecStart=@ENGINE_USR@/services/ovirt-engine-notifier.py $EXTRA_ARGS start +EnvironmentFile=-/etc/sysconfig/ovirt-engine-notifier + +[Install] +WantedBy=multi-user.target diff --git a/packaging/services/ovirt-engine-notifier.sysv.in b/packaging/services/ovirt-engine-notifier.sysv.in new file mode 100644 index 0000000..a400e03 --- /dev/null +++ b/packaging/services/ovirt-engine-notifier.sysv.in @@ -0,0 +1,76 @@ +#! /bin/sh +# +# Start/stop oVirt Engine +# +# chkconfig: - 65 34 +# description: oVirt Engine +# pidfile: /var/run/ovirt-engine.pid + +### BEGIN INIT INFO +# Provides: ovirt-engine +# Short-Description: oVirt Engine +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +NAME="ovirt-engine-notifier" +PROG="oVirt Engine Notifier" + +[ -f "/etc/sysconfig/${NAME}" ] && . "/etc/sysconfig/${NAME}" + +RETVAL=0 +LOCKFILE="/var/lock/subsys/${NAME}" +PIDFILE="${PIDFILE:-/var/run/${NAME}.pid}" +USER="@ENGINE_USER@" + +# See how we were called. +case "$1" in + start) + if [ `id -u` -ne 0 ]; then + echo $"Insufficient privilege" 1>&2 + exit 4 + fi + echo -n $"Starting $PROG: " + ulimit -n ${FILENO:-65535} + touch "${PIDFILE}" + chown "${USER}" "${PIDFILE}" + daemon --user "${USER}" --pidfile="${PIDFILE}" \ + "${ENGINE_USR}/services/${NAME}.py" \ + --pidfile="${PIDFILE}" \ + --background \ + ${EXTRA_ARGS} \ + start + RETVAL=$? + echo + if [ $RETVAL -eq 0 ]; then + touch "${LOCKFILE}" + else + if [ -f "${LOCKFILE}" ]; then + RETVAL=0 + fi + fi + ;; + stop) + echo -n $"Stopping $PROG: " + killproc -p "${PIDFILE}" -d 60 + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f "${LOCKFILE}" + ;; + status) + status -p "${PIDFILE}" + RETVAL=$? + ;; + restart) + $0 stop + $0 start + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart}" + exit 2 + ;; +esac + +exit $RETVAL -- To view, visit http://gerrit.ovirt.org/14378 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2aadeca8b3017dad4107939c7c624ef020347b94 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches