HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib64/nagios/plugins/check_a2_httpdconf.shared
#!/bin/bash

# Script to ensure httpd.conf has no errors and can be rebuilt without any failure.
# BFENG-504
# Refactored May 2024 | BFENG-1045

cpversion=$(cat /usr/local/cpanel/version)
httpd_conf="/etc/apache2/conf/httpd-preview.conf"
httpd_conf_rebuild_log="/var/log/httpd_conf_errors.log"

# Excluding httpd.conf rebuild if it's not cPanel
if [ -z "$cpversion" ]; then
  /usr/sbin/apachectl configtest &>/dev/null
  if [ $? -eq 0 ]; then
    echo "httpd.conf has passed syntax check."
    exit 0
  else
    echo "httpd.conf isn't valid."
    exit 2
  fi
else
  temp_output=$(mktemp)
  max_attempts=3
  attempt=1
  retry_delay=5

  while [ $attempt -le $max_attempts ]; do
    /usr/local/cpanel/scripts/rebuildhttpdconf --preview &> "$temp_output"
    if [ $? -eq 0 ]; then
      echo "httpd.conf has passed syntax check and successfully rebuilt."
      exit 0
      rm -f "$temp_output"
      exit 
    elif [ $attempt -lt $max_attempts ]; then
      sleep $retry_delay
    fi
    attempt=$((attempt + 1))
  done

  echo "httpd.conf rebuild failed."
  exit 2
  echo -e "$(date '+%Y-%m-%d %H:%M:%S')\n$(cat "$temp_output")" >> "$httpd_conf_rebuild_log"
  rm -f "$temp_output"
fi