#!/bin/bash # # Copyright (c) 2013-2019 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # # # chkconfig: 2345 80 80 # ### BEGIN INIT INFO # Provides: worker_config # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Worker node config agent ### END INIT INFO . /usr/bin/tsconfig . /etc/platform/platform.conf PLATFORM_DIR=/opt/platform CONFIG_DIR=$CONFIG_PATH VOLATILE_CONFIG_PASS="/var/run/.config_pass" VOLATILE_CONFIG_FAIL="/var/run/.config_fail" LOGFILE="/var/log/worker_config.log" IMA_POLICY=/etc/ima.policy # Copy of /opt/platform required for worker_services VOLATILE_PLATFORM_PATH=$VOLATILE_PATH/cpe_upgrade_opt_platform DELAY_SEC=600 # If we're on a controller, increase DELAY_SEC to a large value # to allow for active services to recover from a reboot or DOR if [ "$nodetype" = "controller" ] then DELAY_SEC=900 fi fatal_error() { cat < ${IMA_LOAD_PATH} [ $? -eq 0 ] || logger -t $0 -p warn "IMA Policy could not be loaded, see audit.log" else # the securityfs mount should have been # created had the IMA module loaded properly. # This is therefore a fatal error fatal_error "${IMA_LOAD_PATH} not available. Aborting." fi fi HOST=$(hostname) if [ -z "$HOST" -o "$HOST" = "localhost" ] then fatal_error "Host undefined. Unable to perform config" fi date "+%FT%T.%3N" > $LOGFILE IPADDR=$(get_ip $HOST) if [ -z "$IPADDR" ] then fatal_error "Unable to get IP from host: $HOST" fi # wait for controller services to be ready if it is an AIO system # since ping the loopback interface always returns ok if [ -e "${PLATFORM_SIMPLEX_FLAG}" ] then echo "Wait for the controller services" wait_for_controller_services if [ $? -ne 0 ] then fatal_error "Controller services are not ready" fi else /usr/local/bin/connectivity_test -t ${DELAY_SEC} -i ${IPADDR} controller-platform-nfs if [ $? -ne 0 ] then # 'controller-platform-nfs' is not available from management address fatal_error "Unable to contact active controller (controller-platform-nfs) from management address" fi fi # Write the hostname to file so it's persistent echo $HOST > /etc/hostname if ! [ -e "${PLATFORM_SIMPLEX_FLAG}" ] then # Mount the platform filesystem (if necessary - could be auto-mounted by now) mkdir -p $PLATFORM_DIR if [ ! -f $CONFIG_DIR/hosts ] then nfs-mount controller-platform-nfs:$PLATFORM_DIR $PLATFORM_DIR > /dev/null 2>&1 RC=$? if [ $RC -ne 0 ] then fatal_error "Unable to mount $PLATFORM_DIR (RC:$RC)" fi fi # Copy over external_ceph config files if [ -e $CONFIG_DIR/ceph-config ] then cp $CONFIG_DIR/ceph-config/*.conf /etc/ceph/ if [ $? -ne 0 ] then fatal_error "Unable to copy ceph-external config files" fi fi fi if [ "$nodetype" = "worker" ] then # Check whether our installed load matches the active controller CONTROLLER_UUID=`curl -sf http://controller:${http_port}/feed/rel-${SW_VERSION}/install_uuid` if [ $? -ne 0 ] then fatal_error "Unable to retrieve installation uuid from active controller" fi if [ "$INSTALL_UUID" != "$CONTROLLER_UUID" ] then fatal_error "This node is running a different load than the active controller and must be reinstalled" fi mkdir -p /etc/docker/certs.d/registry.local:9001/ chmod 700 /etc/docker/certs.d/registry.local:9001/ cp $CONFIG_DIR/registry-cert.crt /etc/docker/certs.d/registry.local:9001/registry-cert.crt if [ $? -ne 0 ] then fatal_error "Unable to copy $CONFIG_DIR/registry-cert.crt to docker dir" fi fi if [ -e $CONFIG_DIR/registry.central/registry-cert.crt ] then mkdir -p /etc/docker/certs.d/registry.central:9001/ chmod 700 /etc/docker/certs.d/registry.central:9001/ cp $CONFIG_DIR/registry.central/registry-cert.crt /etc/docker/certs.d/registry.central:9001/registry-cert.crt if [ $? -ne 0 ] then fatal_error "Unable to copy $CONFIG_DIR/registry-cert.crt to docker dir for central registry" fi fi # Copy over k8s-coredump-handler token if [ -e $CONFIG_DIR/k8s-coredump-conf.json ] then cp $CONFIG_DIR/k8s-coredump-conf.json /etc/k8s-coredump-conf.json if [ $? -ne 0 ] then fatal_error "Unable to copy k8s-coredump-handler token config file" else chmod 600 /etc/k8s-coredump-conf.json fi fi # banner customization always returns 0, success: /usr/sbin/install_banner_customization cp $CONFIG_DIR/hosts /etc/hosts if [ $? -ne 0 ] then fatal_error "Unable to copy $CONFIG_DIR/hosts" fi if [ "$nodetype" = "controller" -a "$HOST" = "controller-1" ] then # In a small system restore, there may be instance data that we want to # restore. Copy it and delete it. MATE_INSTANCES_DIR="$CONFIG_DIR/controller-1_nova_instances" if [ -d "$MATE_INSTANCES_DIR" ] then echo "Restoring instance data from mate controller" cp -Rp $MATE_INSTANCES_DIR/* /etc/nova/instances/ rm -rf $MATE_INSTANCES_DIR fi fi # Apply the puppet manifest HOST_HIERA=${PUPPET_PATH}/hieradata/${IPADDR}.yaml if [ -f ${HOST_HIERA} ]; then echo "$0: Running puppet manifest apply" puppet-manifest-apply.sh ${PUPPET_PATH}/hieradata ${IPADDR} worker RC=$? if [ $RC -ne 0 ]; then fatal_error "Failed to run the puppet manifest (RC:$RC)" fi else fatal_error "Host configuration not yet available for this node ($(hostname)=${IPADDR}); aborting configuration." fi # Load Network Block Device modprobe nbd if [ $? -ne 0 ] then echo "WARNING: Unable to load kernel module: nbd." logger "WARNING: Unable to load kernel module: nbd." fi #Run mount command to mount any NFS filesystems that required network access /bin/mount -a -t nfs RC=$? if [ $RC -ne 0 ] then fatal_error "Unable to mount NFS filesystems (RC:$RC)" fi touch $VOLATILE_CONFIG_PASS } stop () { # Nothing to do return } case "$1" in start) start ;; stop) stop ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac exit 0