docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
69
scripts/utils/config-utils.sh
Executable file
69
scripts/utils/config-utils.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# Configuration Utility Functions
|
||||
# Consolidated functions from small config-related scripts
|
||||
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/config-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
|
||||
|
||||
# Validate config file
|
||||
config_validate() {
|
||||
local config_file="$1"
|
||||
|
||||
if [ -f "$config_file" ]; then
|
||||
log_success "Configuration file exists: $config_file"
|
||||
return 0
|
||||
else
|
||||
log_error "Configuration file missing: $config_file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Backup config file
|
||||
config_backup() {
|
||||
local config_file="$1"
|
||||
local backup_file="${config_file}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
|
||||
if [ -f "$config_file" ]; then
|
||||
cp "$config_file" "$backup_file"
|
||||
log_success "Backed up: $config_file → $backup_file"
|
||||
return 0
|
||||
else
|
||||
log_error "Config file not found: $config_file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get config value
|
||||
config_get() {
|
||||
local config_file="$1"
|
||||
local key="$2"
|
||||
|
||||
if [ -f "$config_file" ]; then
|
||||
grep "^${key}=" "$config_file" | cut -d'=' -f2- | sed 's/^["'\'']//;s/["'\'']$//'
|
||||
fi
|
||||
}
|
||||
|
||||
# Set config value
|
||||
config_set() {
|
||||
local config_file="$1"
|
||||
local key="$2"
|
||||
local value="$3"
|
||||
|
||||
if [ -f "$config_file" ]; then
|
||||
if grep -q "^${key}=" "$config_file"; then
|
||||
sed -i "s|^${key}=.*|${key}=${value}|" "$config_file"
|
||||
else
|
||||
echo "${key}=${value}" >> "$config_file"
|
||||
fi
|
||||
log_success "Set ${key}=${value} in $config_file"
|
||||
else
|
||||
log_error "Config file not found: $config_file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
56
scripts/utils/container-utils.sh
Executable file
56
scripts/utils/container-utils.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
# Container Utility Functions
|
||||
# Consolidated functions from small container-related scripts
|
||||
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/container-utils.sh"
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Load IP configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||||
|
||||
|
||||
# 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/proxmox-api.sh" 2>/dev/null || true
|
||||
|
||||
# Container status check
|
||||
container_status() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
check_container_status "$vmid" "$host"
|
||||
}
|
||||
|
||||
# Container restart
|
||||
container_restart() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
log_info "Restarting container $vmid on $host"
|
||||
ssh_proxmox "$host" "pct restart $vmid" || true
|
||||
}
|
||||
|
||||
# Container start
|
||||
container_start() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
log_info "Starting container $vmid on $host"
|
||||
ssh_proxmox "$host" "pct start $vmid" || true
|
||||
}
|
||||
|
||||
# Container stop
|
||||
container_stop() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
log_info "Stopping container $vmid on $host"
|
||||
ssh_proxmox "$host" "pct stop $vmid" || true
|
||||
}
|
||||
|
||||
# List all containers
|
||||
container_list() {
|
||||
local host="${1:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "pct list" || true
|
||||
}
|
||||
50
scripts/utils/container-utils.sh.bak
Executable file
50
scripts/utils/container-utils.sh.bak
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Container Utility Functions
|
||||
# Consolidated functions from small container-related scripts
|
||||
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/container-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/proxmox-api.sh" 2>/dev/null || true
|
||||
|
||||
# Container status check
|
||||
container_status() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
check_container_status "$vmid" "$host"
|
||||
}
|
||||
|
||||
# Container restart
|
||||
container_restart() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
log_info "Restarting container $vmid on $host"
|
||||
ssh_proxmox "$host" "pct restart $vmid" || true
|
||||
}
|
||||
|
||||
# Container start
|
||||
container_start() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
log_info "Starting container $vmid on $host"
|
||||
ssh_proxmox "$host" "pct start $vmid" || true
|
||||
}
|
||||
|
||||
# Container stop
|
||||
container_stop() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
log_info "Stopping container $vmid on $host"
|
||||
ssh_proxmox "$host" "pct stop $vmid" || true
|
||||
}
|
||||
|
||||
# List all containers
|
||||
container_list() {
|
||||
local host="${1:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "pct list" || true
|
||||
}
|
||||
30
scripts/utils/dry-run-example.sh
Normal file
30
scripts/utils/dry-run-example.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
# Example --dry-run pattern for deployment/change scripts
|
||||
# Recommendation: docs/10-best-practices/RECOMMENDATIONS_AND_SUGGESTIONS.md (§ Script Improvements)
|
||||
# Usage: DRY_RUN=1 ./your-script.sh OR ./your-script.sh --dry-run
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DRY_RUN="${DRY_RUN:-0}"
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "--dry-run" || "$arg" == "-n" ]]; then
|
||||
DRY_RUN=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
run_or_echo() {
|
||||
if [[ "$DRY_RUN" == "1" ]]; then
|
||||
echo "[DRY-RUN] Would execute: $*"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Example: run_or_echo pct set 106 --memory 8192
|
||||
# Example: run_or_echo cp config.toml /opt/besu/
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
echo "DRY_RUN=$DRY_RUN - Use DRY_RUN=1 or --dry-run to preview without executing."
|
||||
run_or_echo echo "Example command (no-op when dry-run)"
|
||||
fi
|
||||
54
scripts/utils/network-utils.sh
Executable file
54
scripts/utils/network-utils.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
# Network Utility Functions
|
||||
# Consolidated functions from small network-related scripts
|
||||
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/network-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
|
||||
|
||||
# Test network connectivity
|
||||
network_test() {
|
||||
local ip="$1"
|
||||
local port="${2:-}"
|
||||
|
||||
if [ -n "$port" ]; then
|
||||
if timeout 2 bash -c "</dev/tcp/$ip/$port" 2>/dev/null; then
|
||||
log_success "Network connectivity OK: $ip:$port"
|
||||
return 0
|
||||
else
|
||||
log_error "Network connectivity FAILED: $ip:$port"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if ping -c 2 -W 2 "$ip" >/dev/null 2>&1; then
|
||||
log_success "Network reachable: $ip"
|
||||
return 0
|
||||
else
|
||||
log_error "Network unreachable: $ip"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Get IP address
|
||||
network_get_ip() {
|
||||
local interface="${1:-eth0}"
|
||||
ip addr show "$interface" 2>/dev/null | grep -oP 'inet \K[\d.]+' | head -1
|
||||
}
|
||||
|
||||
# Check DNS resolution
|
||||
network_check_dns() {
|
||||
local hostname="$1"
|
||||
if host "$hostname" >/dev/null 2>&1; then
|
||||
log_success "DNS resolution OK: $hostname"
|
||||
return 0
|
||||
else
|
||||
log_error "DNS resolution FAILED: $hostname"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
53
scripts/utils/proxmox-utils.sh
Executable file
53
scripts/utils/proxmox-utils.sh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
# Proxmox Utility Functions
|
||||
# Consolidated functions from small Proxmox-related scripts
|
||||
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/proxmox-utils.sh"
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Load IP configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||||
|
||||
|
||||
# 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/proxmox-api.sh" 2>/dev/null || true
|
||||
|
||||
# List all VMs
|
||||
proxmox_list_vms() {
|
||||
local host="${1:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "qm list" || true
|
||||
}
|
||||
|
||||
# List all containers
|
||||
proxmox_list_containers() {
|
||||
local host="${1:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "pct list" || true
|
||||
}
|
||||
|
||||
# Get VM status
|
||||
proxmox_vm_status() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "qm status $vmid" || true
|
||||
}
|
||||
|
||||
# Get container status
|
||||
proxmox_container_status() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
check_container_status "$vmid" "$host"
|
||||
}
|
||||
|
||||
# Proxmox API call wrapper
|
||||
proxmox_api() {
|
||||
local method="$1"
|
||||
local endpoint="$2"
|
||||
local host="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
proxmox_api_call "$method" "$endpoint" "$host"
|
||||
}
|
||||
47
scripts/utils/proxmox-utils.sh.bak
Executable file
47
scripts/utils/proxmox-utils.sh.bak
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Proxmox Utility Functions
|
||||
# Consolidated functions from small Proxmox-related scripts
|
||||
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/../utils/proxmox-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/proxmox-api.sh" 2>/dev/null || true
|
||||
|
||||
# List all VMs
|
||||
proxmox_list_vms() {
|
||||
local host="${1:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "qm list" || true
|
||||
}
|
||||
|
||||
# List all containers
|
||||
proxmox_list_containers() {
|
||||
local host="${1:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "pct list" || true
|
||||
}
|
||||
|
||||
# Get VM status
|
||||
proxmox_vm_status() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
ssh_proxmox "$host" "qm status $vmid" || true
|
||||
}
|
||||
|
||||
# Get container status
|
||||
proxmox_container_status() {
|
||||
local vmid="$1"
|
||||
local host="${2:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
check_container_status "$vmid" "$host"
|
||||
}
|
||||
|
||||
# Proxmox API call wrapper
|
||||
proxmox_api() {
|
||||
local method="$1"
|
||||
local endpoint="$2"
|
||||
local host="${3:-${PROXMOX_HOST_ML110:-192.168.11.10}}"
|
||||
proxmox_api_call "$method" "$endpoint" "$host"
|
||||
}
|
||||
36
scripts/utils/retry_with_backoff.sh
Normal file
36
scripts/utils/retry_with_backoff.sh
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# Retry with exponential backoff - Recommendation from docs/10-best-practices/RECOMMENDATIONS_AND_SUGGESTIONS.md
|
||||
# Usage: source this file, then: retry_with_backoff 3 2 some_command [args...]
|
||||
# $1 = max_attempts, $2 = initial_delay_seconds, rest = command and args
|
||||
|
||||
retry_with_backoff() {
|
||||
local max_attempts="${1:?Usage: retry_with_backoff MAX_ATTEMPTS INITIAL_DELAY COMMAND [ARGS...]}"
|
||||
local delay="${2:?Usage: retry_with_backoff MAX_ATTEMPTS INITIAL_DELAY COMMAND [ARGS...]}"
|
||||
shift 2
|
||||
local attempt=1
|
||||
|
||||
while [ "$attempt" -le "$max_attempts" ]; do
|
||||
if "$@"; then
|
||||
return 0
|
||||
fi
|
||||
if [ "$attempt" -lt "$max_attempts" ]; then
|
||||
echo "[WARN] Attempt $attempt failed, retrying in ${delay}s..." >&2
|
||||
sleep "$delay"
|
||||
delay=$((delay * 2))
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
echo "[ERROR] Failed after $max_attempts attempts" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Allow script to be sourced or run (run = execute first non-option args as command)
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
if [[ $# -ge 3 ]]; then
|
||||
retry_with_backoff "$@"
|
||||
else
|
||||
echo "Usage: $0 MAX_ATTEMPTS INITIAL_DELAY COMMAND [ARGS...]"
|
||||
echo "Example: $0 3 2 curl -s -o /dev/null -w '%{http_code}' https://example.com"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
74
scripts/utils/service-utils.sh
Executable file
74
scripts/utils/service-utils.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/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 IP configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||||
|
||||
|
||||
# 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
|
||||
}
|
||||
68
scripts/utils/service-utils.sh.bak
Executable file
68
scripts/utils/service-utils.sh.bak
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/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
|
||||
}
|
||||
Reference in New Issue
Block a user