devstack/lib/zookeeper
Jordan Pittier 04e73e17e8 On Ubuntu: don't start Zookeeper twice
On Ubuntu, if the Zookeeper service is already running, attempting
to start it again fails with non-zero exit code. This patch detects
whether ZK is already started before trying to start it.

Change-Id: If1257152de01fe5fe0351fdbb538bce083edbec0
Closes-Bug: #1513741
2015-11-10 19:01:28 +01:00

92 lines
2.2 KiB
Bash

#!/bin/bash
#
# lib/zookeeper
# Functions to control the installation and configuration of **zookeeper**
# Dependencies:
#
# - ``functions`` file
# ``stack.sh`` calls the entry points in this order:
#
# - is_zookeeper_enabled
# - install_zookeeper
# - configure_zookeeper
# - init_zookeeper
# - start_zookeeper
# - stop_zookeeper
# - cleanup_zookeeper
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
# Defaults
# --------
# <define global variables here that belong to this project>
# Set up default directories
ZOOKEEPER_DATA_DIR=$DEST/data/zookeeper
ZOOKEEPER_CONF_DIR=/etc/zookeeper
# Entry Points
# ------------
# Test if any zookeeper service us enabled
# is_zookeeper_enabled
function is_zookeeper_enabled {
[[ ,${ENABLED_SERVICES}, =~ ,"zookeeper", ]] && return 0
return 1
}
# cleanup_zookeeper() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up
function cleanup_zookeeper {
sudo rm -rf $ZOOKEEPER_DATA_DIR
}
# configure_zookeeper() - Set config files, create data dirs, etc
function configure_zookeeper {
sudo cp $FILES/zookeeper/* $ZOOKEEPER_CONF_DIR
sudo sed -i -e 's|.*dataDir.*|dataDir='$ZOOKEEPER_DATA_DIR'|' $ZOOKEEPER_CONF_DIR/zoo.cfg
}
# init_zookeeper() - Initialize databases, etc.
function init_zookeeper {
# clean up from previous (possibly aborted) runs
# create required data files
sudo rm -rf $ZOOKEEPER_DATA_DIR
sudo mkdir -p $ZOOKEEPER_DATA_DIR
}
# install_zookeeper() - Collect source and prepare
function install_zookeeper {
install_package zookeeperd
}
# start_zookeeper() - Start running processes, including screen
function start_zookeeper {
# Starting twice Zookeeper on Ubuntu exits with error code 1. See LP#1513741
# Match both systemd and sysvinit output
local running="(active \(running\)|start/running)"
if ! is_ubuntu || ! sudo /usr/sbin/service zookeeper status | egrep -q "$running"; then
start_service zookeeper
fi
}
# stop_zookeeper() - Stop running processes (non-screen)
function stop_zookeeper {
stop_service zookeeper
}
# Restore xtrace
$XTRACE
# Tell emacs to use shell-script-mode
## Local variables:
## mode: shell-script
## End: