metal/mtce-compute/src/scripts/e_nova-init

160 lines
4.0 KiB
Bash

#! /bin/bash
#
# Copyright (c) 2015-2017 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
#
### BEGIN INIT INFO
# Provides: nova-init
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Cleanup pmon.d nova linkages
### END INIT INFO
# Platform paths and flags
. /usr/bin/tsconfig
# Linux Standard Base (LSB) Error Codes
SUCCESS=0
GENERIC_ERROR=1
INVALID_ARGS=2
NOVA_INIT_TAG=${NOVA_INIT_TAG:-"NOVA_INIT"}
function log
{
logger -p local1.info -t ${NOVA_INIT_TAG} $@
}
NOVA_RUN="/var/run/nova"
NOVA_INIT_FAILED="${NOVA_RUN}/.nova_init_failed"
NOVA_CLEANUP_DONE_FILE="${NOVA_RUN}/.nova_cleanup_done"
NOVA_COMPUTE_ENABLED="${NOVA_RUN}/.nova_compute_enabled"
NOVA_CLEANUP_PID_FILE="${NOVA_RUN}/nova-cleanup.pid"
NOVA_COMPUTE_PMOND_TARGET="/etc/nova/nova-compute.conf"
NOVA_COMPUTE_PMOND_SYMLINK="/etc/pmon.d/nova-compute.conf"
NOVA_CLEANUP_PMOND_TARGET="/etc/nova/nova-cleanup.conf"
NOVA_CLEANUP_PMOND_SYMLINK="/etc/pmon.d/nova-cleanup.conf"
case "$1" in
start)
log "Start"
mkdir -p ${NOVA_RUN}
chown nova:root ${NOVA_RUN}
# Assume we failed, and clear when we make it to nova-cleanup phase.
touch ${NOVA_INIT_FAILED}
if [ -f ${NOVA_COMPUTE_ENABLED} ]
then
rm ${NOVA_COMPUTE_ENABLED}
fi
if [ -f ${NOVA_CLEANUP_PID_FILE} ]
then
rm ${NOVA_CLEANUP_PID_FILE}
fi
if [ -f ${NOVA_CLEANUP_DONE_FILE} ]
then
rm ${NOVA_CLEANUP_DONE_FILE}
fi
if [ -e ${NOVA_COMPUTE_PMOND_SYMLINK} ]
then
rm ${NOVA_COMPUTE_PMOND_SYMLINK}
fi
# Do not continue if the host has not been configured. We don't
# want to run nova-compute before its config file has been updated.
if [ ! -f ${INITIAL_COMPUTE_CONFIG_COMPLETE} ]
then
log "Initial compute configuration is not complete"
exit ${GENERIC_ERROR}
fi
# Do not continue if the compute services are disabled.
if [ -f ${VOLATILE_DISABLE_COMPUTE_SERVICES} ]
then
log "Compute services are disabled, nothing to do"
rm ${NOVA_INIT_FAILED}
exit ${SUCCESS}
fi
if ! [ -e ${NOVA_CLEANUP_PMOND_SYMLINK} ]
then
ln -s ${NOVA_CLEANUP_PMOND_TARGET} ${NOVA_CLEANUP_PMOND_SYMLINK}
if [ $? -ne 0 ]
then
log "Failed to create nova-cleanup symbolic link"
exit ${GENERIC_ERROR}
fi
fi
# There is interaction and timing between: e_nova-init, nova-startup,
# nova-cleanup, nova-compute, nova-goenabled. It is much simpler to
# let nova-goenabled detect when service is actually enabled.
# Clear the init failure flag prior to nova-cleanup.
rm ${NOVA_INIT_FAILED}
# Do in the background because of the long execution time.
log "Start Nova-Cleanup"
MAX_PID_WAIT=$((SECONDS+45))
timeout --signal KILL 300s /etc/init.d/nova-cleanup start &
while ! [ -f ${NOVA_CLEANUP_PID_FILE} ]
do
log "Waiting for Nova-Cleanup to start"
if [ ${SECONDS} -gt ${MAX_PID_WAIT} ]
then
log "Timeout waiting for Nova-Cleanup pid"
exit ${GENERIC_ERROR}
fi
sleep 1
done
NOVA_CLEANUP_PID=$(cat ${NOVA_CLEANUP_PID_FILE})
log "Nova-Cleanup pid ${NOVA_CLEANUP_PID} started"
log "Finished"
;;
stop)
log "Stop"
# Remove this just in case...
if [ -f ${NOVA_INIT_FAILED} ]
then
rm ${NOVA_INIT_FAILED}
fi
# Stop pmon monitoring of nova-compute
if [ -e ${NOVA_COMPUTE_PMOND_SYMLINK} ]
then
rm ${NOVA_COMPUTE_PMOND_SYMLINK}
fi
# Stop nova-compute
/etc/init.d/nova-compute stop
log "Finished"
;;
*)
echo "Usage: $0 {start|stop}"
exit ${INVALID_ARGS}
;;
esac
exit ${SUCCESS}