Files
proxmox/scripts/utils/service-utils.sh.bak

69 lines
1.9 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# Service Utility Functions
# Consolidated functions from small service-related scripts
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/service-utils.sh"
set -euo pipefail
# Load shared modules
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
source "$SCRIPT_DIR/../lib/ip-config.sh" 2>/dev/null || true
source "$SCRIPT_DIR/../lib/logging.sh" 2>/dev/null || true
source "$SCRIPT_DIR/../lib/ssh-helpers.sh" 2>/dev/null || true
# Check service status
service_status() {
local service="$1"
local vmid="${2:-}"
local host="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
if [ -n "$vmid" ]; then
ssh_container "$host" "$vmid" "systemctl is-active $service" >/dev/null 2>&1
else
systemctl is-active "$service" >/dev/null 2>&1
fi
}
# Start service
service_start() {
local service="$1"
local vmid="${2:-}"
local host="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
log_info "Starting service: $service${vmid:+ on VMID $vmid}"
if [ -n "$vmid" ]; then
ssh_container "$host" "$vmid" "systemctl start $service" || true
else
systemctl start "$service" || true
fi
}
# Stop service
service_stop() {
local service="$1"
local vmid="${2:-}"
local host="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
log_info "Stopping service: $service${vmid:+ on VMID $vmid}"
if [ -n "$vmid" ]; then
ssh_container "$host" "$vmid" "systemctl stop $service" || true
else
systemctl stop "$service" || true
fi
}
# Restart service
service_restart() {
local service="$1"
local vmid="${2:-}"
local host="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
log_info "Restarting service: $service${vmid:+ on VMID $vmid}"
if [ -n "$vmid" ]; then
ssh_container "$host" "$vmid" "systemctl restart $service" || true
else
systemctl restart "$service" || true
fi
}