config/sysinv/sysinv-agent/sysinv-agent
Dean Troyer 9b95aa0a35 StarlingX open source release updates
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2018-05-31 07:35:52 -07:00

226 lines
6.1 KiB
Bash
Executable File

#! /bin/sh
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
#
# chkconfig: 2345 75 25
#
### BEGIN INIT INFO
# Provides: sysinv-agent
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Maintenance daemon
### END INIT INFO
. /etc/init.d/functions
. /etc/build.info
PLATFORM_CONF="/etc/platform/platform.conf"
NODETYPE=""
DAEMON_NAME="sysinv-agent"
SYSINVAGENT="/usr/bin/${DAEMON_NAME}"
SYSINV_CONF_DIR="/etc/sysinv"
SYSINV_CONF_FILE="${SYSINV_CONF_DIR}/sysinv.conf"
SYSINV_CONF_DEFAULT_FILE="/opt/platform/sysinv/${SW_VERSION}/sysinv.conf.default"
SYSINV_READY_FLAG=/var/run/.sysinv_ready
DELAY_SEC=20
daemon_pidfile="/var/run/${DAEMON_NAME}.pid"
if [ -f ${PLATFORM_CONF} ] ; then
NODETYPE=`cat ${PLATFORM_CONF} | grep nodetype | cut -f2 -d'='`
else
logger "$0: ${PLATFORM_CONF} is missing"
exit 1
fi
if [ ! -e "${SYSINVAGENT}" ] ; then
logger "$0: ${SYSINVAGENT} is missing"
exit 1
fi
RETVAL=0
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
export PATH
function mount_and_copy_config_file()
{
echo "Mount /opt/platform"
logger "$0: Info: nfs-mount controller:/opt/platform/sysinv/${SW_VERSION} /mnt/sysinv"
mkdir /mnt/sysinv
timeout 10s nfs-mount controller:/opt/platform/sysinv/${SW_VERSION} /mnt/sysinv &> /dev/null
RETVAL=$?
# 0 = true
if [ ${RETVAL} -ne 0 ] ; then
logger "$0: Warn: nfs-mount controller:/opt/platform/sysinv/${SW_VERSION} /mnt/sysinv"
else
mkdir -p $SYSINV_CONF_DIR
cp /mnt/sysinv/sysinv.conf.default ${SYSINV_CONF_FILE}
RETVAL=$?
if [ $? -ne 0 ] ; then
logger "$0: Warn: cp /mnt/sysinv/sysinv.conf.default ${SYSINV_CONF_FILE}"
fi
timeout 5s umount /mnt/sysinv
rmdir /mnt/sysinv
fi
return ${RETVAL}
}
case "$1" in
start)
# Check for installation failure
if [ -f /etc/platform/installation_failed ] ; then
logger "$0: /etc/platform/installation_failed flag is set. Aborting."
exit 1
fi
# if [ "$NODETYPE" = "compute" ] ; then
# if [ "$NODETYPE" = "compute" ] || [ "$NODETYPE" = "controller" ] ; then
echo -n "Setting up config for sysinv-agent: "
if [ -e ${SYSINV_READY_FLAG} ] ; then
# clear it on every restart, so agent can update it
rm -f ${SYSINV_READY_FLAG}
fi
if [ -f ${SYSINV_CONF_FILE} ] ; then
logger "$0: ${SYSINV_CONF_FILE} already exists"
RETVAL=0
else
# Avoid self-mount due to potential nfs issues
echo "Checking for controller-platform-nfs "
# try for DELAY_SEC seconds to reach controller-platform-nfs
START=`date +%s`
FOUND=0
while [ $(date +%s) -lt $(( ${START} + ${DELAY_SEC} )) ]
do
ping -c 1 controller-platform-nfs > /dev/null 2>&1 || ping6 -c 1 controller-platform-nfs > /dev/null 2>&1
if [ $? -eq 0 ]
then
FOUND=1
break
fi
sleep 1
done
CONF_COPIED=0
if [ ${FOUND} -eq 0 ]
then
# 'controller-platform-nfs' is not available; continue other setup
echo "controller-platform-nfs is not available"
else
# Only required if conf file does not already exist
if [ -f ${SYSINV_CONF_DEFAULT_FILE} ]
then
echo "Copying self sysinv.conf without mount"
mkdir -p $SYSINV_CONF_DIR
cp ${SYSINV_CONF_DEFAULT_FILE} ${SYSINV_CONF_FILE}
RETVAL=$?
if [ $? -ne 0 ] ; then
logger "$0: Warn: cp /mnt/sysinv/sysinv.conf.default ${SYSINV_CONF_FILE} failed. Try mount."
else
CONF_COPIED=1
fi
fi
if [ ${CONF_COPIED} -eq 0 ]
then
CONF_COPY_COUNT=0
while [ $CONF_COPY_COUNT -lt 3 ]; do
if mount_and_copy_config_file ;
then
logger "$0: Info: Mount and copy config file PASSED. Attempt: ${CONF_COPY_COUNT}"
break
fi
let CONF_COPY_COUNT=CONF_COPY_COUNT+1
logger "$0: Warn: Mount and copy config file failed. Attempt: ${CONF_COPY_COUNT}"
done
fi
fi
fi
echo -n "Installing virtio_net driver: "
timeout 5s modprobe virtio_net
RETVAL=$?
if [ ${RETVAL} -eq 0 ] ; then
echo "OK"
else
echo "FAIL"
fi
if [ -e ${daemon_pidfile} ] ; then
echo "Killing existing process before starting new"
pid=`cat ${daemon_pidfile}`
kill -TERM $pid
rm -f ${daemon_pidfile}
fi
echo -n "Starting sysinv-agent: "
/bin/sh -c "${SYSINVAGENT}"' >> /dev/null 2>&1 & echo $!' > ${daemon_pidfile}
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
echo "OK"
touch /var/lock/subsys/${DAEMON_NAME}
else
echo "FAIL"
fi
# fi
;;
stop)
# if [ "$NODETYPE" = "compute" ] ; then
# if [ "$NODETYPE" = "compute" ] || [ "$NODETYPE" = "controller" ] ; then
echo -n "Stopping sysinv-agent: "
if [ -e ${daemon_pidfile} ] ; then
pid=`cat ${daemon_pidfile}`
kill -TERM $pid
rm -f ${daemon_pidfile}
rm -f /var/lock/subsys/${DAEMON_NAME}
echo "OK"
else
echo "FAIL"
fi
# fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
if [ -e ${daemon_pidfile} ] ; then
pid=`cat ${daemon_pidfile}`
ps -p $pid | grep -v "PID TTY" >> /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "sysinv-agent is running"
RETVAL=0
else
echo "sysinv-agent is not running"
RETVAL=1
fi
else
echo "sysinv-agent is not running ; no pidfile"
RETVAL=1
fi
;;
condrestart)
[ -f /var/lock/subsys/$DAEMON_NAME ] && $0 restart
;;
*)
echo "usage: $0 { start | stop | status | restart | condrestart | status }"
;;
esac
exit $RETVAL