diff --git a/AWSutils.sh b/AWSutils.sh index 7f6beb2..6d499e6 100755 --- a/AWSutils.sh +++ b/AWSutils.sh @@ -351,8 +351,11 @@ function InstallCfnBootstrap { err_exit "Failed making cfn-hup service executable" err_exit "Using alternatives to configure cfn-hup symlink and initscript..." NONE - chroot "${CHROOTMNT}" alternatives --verbose --install /opt/aws/bin/cfn-hup cfn-hup /usr/local/bin/cfn-hup 1 --initscript cfn-hup || \ - err_exit "Failed configuring cfn-hup symlink and initscript" + chroot "${CHROOTMNT}" alternatives --verbose --install /opt/aws/bin/cfn-hup cfn-hup /usr/local/bin/cfn-hup 1 || \ + err_exit "Failed configuring cfn-hup symlink" + + # Install systemd-supporting content + InstallCfnBootstrap_systemd err_exit "Cleaning up install files..." NONE rm -rf "${CHROOTMNT}${TMPDIR}" || \ @@ -360,6 +363,66 @@ function InstallCfnBootstrap { fi } +# Install systemd bits +function InstallCfnBootstrap_systemd { + local SVC_NAME="cfn-hup" + local ETC_DIR="${CHROOTMNT}/etc/systemd/system" + local SVC_FILE="${ETC_DIR}/${SVC_NAME}.service" + local OS_VERSION + + SVC_NAME="cfn-hup" + ETC_DIR="${CHROOTMNT}/etc/systemd/system" + SVC_FILE="${ETC_DIR}/${SVC_NAME}.service" + OS_VERSION="$( + awk -F "=" '/^VERSION=/{ print $2 }' /etc/os-release | \ + sed -e 's/"//g' | \ + cut -d '.' -f 1 + )" + + if [[ ${OS_VERSION} -ge 9 ]] + then + err_exit "EL 9+ distros want systemd units..." NONE + + if [[ ! -d ${ETC_DIR} ]] + then + err_exit "Creating ${ETC_DIR}" NONE + install -dDm 0755 "${ETC_DIR}" || \ + err_exit "Failed creating ${ETC_DIR}" + fi + + if [[ ! -f ${SVC_FILE} ]] + then + err_exit "Installing systemd unit-file for ${SVC_NAME}..." NONE + install -bDm 0644 <( + echo "[Unit]" + echo "Description=cfn-hup Service" + echo "After=network.target" + echo "" + echo "[Service]" + echo "ExecStart=/usr/local/bin/cfn-hup" + echo "Type=forking" + echo "PIDFile=/run/cfn-hup.pid" + echo "" + echo "[Install]" + echo "WantedBy=multi-user.target" + ) "${SVC_FILE}" || \ + err_exit "Failed installing systemd unit-file for ${SVC_NAME}" + fi + + if [[ ! -d ${CHROOTMNT}/etc/cfn ]] + then + err_exit "Creating /etc/cfn directory" NONE + install -Z "system_u:object_r:etc_t:s0" -dDm 0755 -o root \ + -g root /etc/cfn || err_exit "Failed creating /etc/cfn directory" NONE + fi + + chroot "${CHROOTMNT}" /usr/bin/systemctl disable "${SVC_NAME}.service" || \ + err_exit "FAILED" + fi + + return +} + # shellcheck disable=SC2016,SC1003 function ProfileSetupAwsCli { install -bDm 0644 -o root -g root <( diff --git a/PostBuild.sh b/PostBuild.sh index f40dd46..af24ca2 100755 --- a/PostBuild.sh +++ b/PostBuild.sh @@ -278,6 +278,32 @@ function ConfigureNetworking { chroot "${CHROOTMNT}" systemctl enable NetworkManager } +# EL9 is more annoying about SysV-isms +function ConfigureRcLocalGenerator { + local GENERATOR_DIR="${CHROOTMNT}/etc/systemd/system-generators" + local GENERATOR_FIL="${GENERATOR_DIR}/systemd-rc-local-generator" + + # Ensure systemd file is present + if [[ ! -f ${GENERATOR_FIL} ]] + then + printf "Creating %s... " "${GENERATOR_DIR}" + install -Z "system_u:object_r:etc_t:s0" -dDm 0755 -o root -g root \ + "${GENERATOR_DIR}" || err_exit "Failed creating ${GENERATOR_DIR}" + echo "Success!" + + printf "Creating %s... " "${GENERATOR_FIL}" + install -bDm 0600 -o root -g root /dev/null "${GENERATOR_FIL}" || \ + err_exit "Failed creating ${GENERATOR_FIL}" + echo "Success!" + + printf "Setting SELinux label on %s... " "${GENERATOR_FIL}" + chcon -u system_u -r object_r -t etc_t "${GENERATOR_FIL}" || \ + err_exit "Failed creating ${GENERATOR_FIL}" + echo "Success!" + fi +} + + # Firewalld config function FirewalldSetup { err_exit "Setting up baseline firewall rules..." NONE @@ -661,6 +687,9 @@ CreateFstab # Set /tmp as a tmpfs SetupTmpfs +# Ensure no systemd-rc-local-generator log-spamming +ConfigureRcLocalGenerator + # Configure logging ConfigureLogging