#!/usr/bin/env bash # commands/proxy.command.sh # # Manages the reverse proxy service. # # Usage: # dx proxy start — start the proxy # dx proxy stop — stop the proxy # dx proxy restart — restart the proxy # dx proxy status — show proxy status # dx proxy logs — tail proxy logs # ============================================ # Lifecycle # ============================================ function cmd::proxy::on_load() { flag::register --debug } # ============================================ # Public entrypoint # ============================================ function cmd::proxy::run() { local subcmd="${1:-help}" shift || true case "$subcmd" in start) cmd::proxy::start "$@" ;; stop) cmd::proxy::stop "$@" ;; restart) cmd::proxy::restart "$@" ;; status) cmd::proxy::status "$@" ;; logs) cmd::proxy::logs "$@" ;; help) cmd::proxy::help ;; *) log::error "Unknown subcommand: '${subcmd}'" cmd::proxy::help return 1 ;; esac } # ============================================ # Help # ============================================ function cmd::proxy::help() { cat < Manages the reverse proxy service (${PROXY_SERVICE}). Subcommands: start Start the proxy stop Stop the proxy restart Restart the proxy status Show proxy status logs Tail proxy logs Examples: dx proxy start dx proxy stop dx proxy restart dx proxy status dx proxy logs EOF } # ============================================ # Subcommands # ============================================ function cmd::proxy::start() { if proxy::running; then log::info "Proxy (${PROXY_SERVICE}) is already running" return 0 fi log::info "Starting proxy (${PROXY_SERVICE})..." proxy::start log::success "Proxy started" } function cmd::proxy::stop() { if ! proxy::running; then log::info "Proxy (${PROXY_SERVICE}) is not running" return 0 fi log::info "Stopping proxy (${PROXY_SERVICE})..." proxy::stop log::success "Proxy stopped" } function cmd::proxy::restart() { log::info "Restarting proxy (${PROXY_SERVICE})..." proxy::restart log::success "Proxy restarted" } function cmd::proxy::status() { printf "\n" printf "%-20s %s\n" "Service:" "${PROXY_SERVICE}" printf "%-20s %s\n" "Network:" "${PROXY_NETWORK}" printf "%-20s %s\n" "Driver:" "$(proxy::driver)" printf "%-20s " "Status:" if proxy::running; then echo "✓ running" else echo "⚠️ stopped" fi printf "\n" } function cmd::proxy::logs() { log::info "Tailing proxy logs (${PROXY_SERVICE})..." proxy::logs }