dx/dxkit/commands/apache.command.sh

128 lines
No EOL
3 KiB
Bash

#!/usr/bin/env bash
# commands/apache.command.sh
#
# Manages the Apache web server.
#
# Usage:
# dx apache validate — validate vhost configuration
# dx apache reload — graceful reload (picks up vhost changes)
# dx apache restart — full restart
# dx apache vhosts — list all loaded virtual hosts
# dx apache modules — list all loaded Apache modules
# dx apache version — show Apache version
# dx apache logs <type> — tail error or access logs
# ============================================
# Lifecycle
# ============================================
function cmd::apache::on_load() {
load_module apache
flag::register --debug
}
# ============================================
# Public entrypoint
# ============================================
function cmd::apache::run() {
local subcmd="${1:-help}"
shift || true
case "$subcmd" in
validate) cmd::apache::validate ;;
reload) cmd::apache::reload ;;
restart) cmd::apache::restart ;;
vhosts) cmd::apache::vhosts ;;
modules) cmd::apache::modules ;;
version) cmd::apache::version ;;
logs) cmd::apache::logs "$@" ;;
help) cmd::apache::help ;;
*)
log::error "Unknown subcommand: '${subcmd}'"
cmd::apache::help
return 1
;;
esac
}
# ============================================
# Help
# ============================================
function cmd::apache::help() {
cat <<EOF
Usage: dx apache <subcommand>
Manages the Apache web server.
Subcommands:
validate Validate vhost configuration
reload Graceful reload (picks up config changes)
restart Full restart
vhosts List all loaded virtual hosts
modules List all loaded Apache modules
version Show Apache version
logs [type] Tail logs (error | access, default: error)
Examples:
dx apache validate
dx apache reload
dx apache vhosts
dx apache logs access
EOF
}
# ============================================
# Subcommands
# ============================================
function cmd::apache::validate() {
log::info "Validating Apache configuration..."
if apache::validate_config; then
log::success "Configuration is valid"
else
log::error "Configuration has errors"
return 1
fi
}
function cmd::apache::reload() {
log::info "Reloading Apache..."
apache::reload
log::success "Apache reloaded"
}
function cmd::apache::restart() {
log::info "Restarting Apache..."
apache::restart
log::success "Apache restarted"
}
function cmd::apache::vhosts() {
log::info "Loaded virtual hosts:"
apache::list_vhosts
}
function cmd::apache::modules() {
log::info "Loaded Apache modules:"
apache::list_modules
}
function cmd::apache::version() {
apache::version
}
function cmd::apache::logs() {
local type="${1:-error}"
case "$type" in
error) apache::logs::error ;;
access) apache::logs::access ;;
*)
log::error "Unknown log type: '${type}' (must be 'error' or 'access')"
return 1
;;
esac
}