Refactor dev MOTD/SSH setup and journal cleanup
Moved MOTD/SSH setup for dev mode in LXC containers to run after installation and when containers are kept for debugging, improving reliability and clarity. Updated journalctl cleanup to avoid using $STD and suppress errors if systemd-journald is not initialized. Also refactored indentation in misc/api.func for consistency.
This commit is contained in:
parent
1090081a66
commit
a7daaee5ae
@ -2746,21 +2746,6 @@ EOF'
|
|||||||
# Install SSH keys
|
# Install SSH keys
|
||||||
install_ssh_keys_into_ct
|
install_ssh_keys_into_ct
|
||||||
|
|
||||||
# Dev mode: Setup MOTD/SSH AFTER network is ready and before installation
|
|
||||||
# This ensures the container is fully booted and accessible via SSH
|
|
||||||
if [[ "${DEV_MODE_MOTD:-false}" == "true" ]]; then
|
|
||||||
msg_dev "Setting up MOTD and SSH for debugging access"
|
|
||||||
# Load common install functions and run motd_ssh if available
|
|
||||||
if pct exec "$CTID" -- bash -c "
|
|
||||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/install.func)
|
|
||||||
declare -f motd_ssh >/dev/null 2>&1 && motd_ssh || true
|
|
||||||
" >/dev/null 2>&1; then
|
|
||||||
msg_dev "MOTD/SSH ready - container accessible via SSH (IP: $ip_in_lxc)"
|
|
||||||
else
|
|
||||||
msg_warn "MOTD/SSH setup failed, but continuing with installation"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run application installer
|
# Run application installer
|
||||||
# NOTE: We disable error handling here because:
|
# NOTE: We disable error handling here because:
|
||||||
# 1. Container errors are caught by error_handler INSIDE container
|
# 1. Container errors are caught by error_handler INSIDE container
|
||||||
@ -2850,6 +2835,18 @@ EOF'
|
|||||||
echo -e "${BFR}${CM}${GN}Container ${CTID} removed${CL}"
|
echo -e "${BFR}${CM}${GN}Container ${CTID} removed${CL}"
|
||||||
elif [[ "$response" =~ ^[Nn]$ ]]; then
|
elif [[ "$response" =~ ^[Nn]$ ]]; then
|
||||||
echo -e "\n${TAB}${YW}Container ${CTID} kept for debugging${CL}"
|
echo -e "\n${TAB}${YW}Container ${CTID} kept for debugging${CL}"
|
||||||
|
|
||||||
|
# Dev mode: Setup MOTD/SSH for debugging access to broken container
|
||||||
|
if [[ "${DEV_MODE_MOTD:-false}" == "true" ]]; then
|
||||||
|
echo -e "${TAB}${HOLD}${DGN}Setting up MOTD and SSH for debugging...${CL}"
|
||||||
|
if pct exec "$CTID" -- bash -c "
|
||||||
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/install.func)
|
||||||
|
declare -f motd_ssh >/dev/null 2>&1 && motd_ssh || true
|
||||||
|
" >/dev/null 2>&1; then
|
||||||
|
local ct_ip=$(pct exec "$CTID" ip a s dev eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1)
|
||||||
|
echo -e "${BFR}${CM}${GN}MOTD/SSH ready - SSH into container: ssh root@${ct_ip}${CL}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Timeout - auto-remove
|
# Timeout - auto-remove
|
||||||
@ -3760,6 +3757,17 @@ create_lxc_container() {
|
|||||||
# - Posts final "done" status to API telemetry
|
# - Posts final "done" status to API telemetry
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
description() {
|
description() {
|
||||||
|
# Dev mode: Setup MOTD/SSH on successful installation
|
||||||
|
if [[ "${DEV_MODE_MOTD:-false}" == "true" ]]; then
|
||||||
|
msg_dev "Setting up MOTD and SSH for debugging access"
|
||||||
|
if pct exec "$CTID" -- bash -c "
|
||||||
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/install.func)
|
||||||
|
declare -f motd_ssh >/dev/null 2>&1 && motd_ssh || true
|
||||||
|
" >/dev/null 2>&1; then
|
||||||
|
msg_dev "MOTD/SSH configured successfully"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
|
IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
|
||||||
|
|
||||||
# Generate LXC Description
|
# Generate LXC Description
|
||||||
|
|||||||
@ -834,8 +834,9 @@ cleanup_lxc() {
|
|||||||
if command -v composer &>/dev/null; then $STD composer clear-cache || true; fi
|
if command -v composer &>/dev/null; then $STD composer clear-cache || true; fi
|
||||||
|
|
||||||
if command -v journalctl &>/dev/null; then
|
if command -v journalctl &>/dev/null; then
|
||||||
$STD journalctl --rotate || true
|
# Journal rotation may fail if systemd-journald not fully initialized yet
|
||||||
$STD journalctl --vacuum-time=10m || true
|
journalctl --rotate 2>/dev/null || true
|
||||||
|
journalctl --vacuum-time=10m 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
msg_ok "Cleaned"
|
msg_ok "Cleaned"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user