Extract pct create cmd to var & call with command
This commit is contained in:
@@ -4627,7 +4627,7 @@ create_lxc_container() {
|
|||||||
msg_ok "LXC stack upgraded."
|
msg_ok "LXC stack upgraded."
|
||||||
if [[ "$do_retry" == "yes" ]]; then
|
if [[ "$do_retry" == "yes" ]]; then
|
||||||
msg_info "Retrying container creation after upgrade"
|
msg_info "Retrying container creation after upgrade"
|
||||||
if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "$PCT_OPTIONS" >>"$LOGFILE" 2>&1; then
|
if command "pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} $PCT_OPTIONS" >>"$LOGFILE" 2>&1; then
|
||||||
msg_ok "Container created successfully after upgrade."
|
msg_ok "Container created successfully after upgrade."
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@@ -5077,11 +5077,14 @@ create_lxc_container() {
|
|||||||
# Release lock after template validation - pct create has its own internal locking
|
# Release lock after template validation - pct create has its own internal locking
|
||||||
exec 9>&-
|
exec 9>&-
|
||||||
|
|
||||||
msg_debug "pct create command: pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} $PCT_OPTIONS"
|
local pct_create_cmd="pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} $PCT_OPTIONS"
|
||||||
|
local pct_create_fallback_cmd="pct create $CTID local:vztmpl/${TEMPLATE} $PCT_OPTIONS"
|
||||||
|
|
||||||
|
msg_debug "pct create command: $pct_create_cmd"
|
||||||
msg_debug "Logfile: $LOGFILE"
|
msg_debug "Logfile: $LOGFILE"
|
||||||
|
|
||||||
# First attempt (PCT_OPTIONS is a multi-line string, use it directly)
|
# First attempt (PCT_OPTIONS is a multi-line string, use it directly)
|
||||||
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "$PCT_OPTIONS" >"$LOGFILE" 2>&1; then
|
if ! command $pct_create_cmd >"$LOGFILE" 2>&1; then
|
||||||
msg_debug "Container creation failed on ${TEMPLATE_STORAGE}. Checking error..."
|
msg_debug "Container creation failed on ${TEMPLATE_STORAGE}. Checking error..."
|
||||||
|
|
||||||
# Check if template issue - retry with fresh download
|
# Check if template issue - retry with fresh download
|
||||||
@@ -5093,7 +5096,7 @@ create_lxc_container() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Retry after repair
|
# Retry after repair
|
||||||
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "$PCT_OPTIONS" >>"$LOGFILE" 2>&1; then
|
if ! command $pct_create_cmd >>"$LOGFILE" 2>&1; then
|
||||||
# Fallback to local storage if not already on local
|
# Fallback to local storage if not already on local
|
||||||
if [[ "$TEMPLATE_STORAGE" != "local" ]]; then
|
if [[ "$TEMPLATE_STORAGE" != "local" ]]; then
|
||||||
msg_info "Retrying container creation with fallback to local storage"
|
msg_info "Retrying container creation with fallback to local storage"
|
||||||
@@ -5106,7 +5109,7 @@ create_lxc_container() {
|
|||||||
else
|
else
|
||||||
msg_ok "Trying local storage fallback"
|
msg_ok "Trying local storage fallback"
|
||||||
fi
|
fi
|
||||||
if ! pct create "$CTID" "local:vztmpl/${TEMPLATE}" "$PCT_OPTIONS" >>"$LOGFILE" 2>&1; then
|
if ! command $pct_create_fallback_cmd >>"$LOGFILE" 2>&1; then
|
||||||
# Local fallback also failed - check for LXC stack version issue
|
# Local fallback also failed - check for LXC stack version issue
|
||||||
if grep -qiE 'unsupported .* version' "$LOGFILE"; then
|
if grep -qiE 'unsupported .* version' "$LOGFILE"; then
|
||||||
echo
|
echo
|
||||||
@@ -5130,7 +5133,7 @@ create_lxc_container() {
|
|||||||
msg_error "Container creation failed. See $LOGFILE"
|
msg_error "Container creation failed. See $LOGFILE"
|
||||||
if whiptail --yesno "pct create failed.\nDo you want to enable verbose debug mode and view detailed logs?" 12 70; then
|
if whiptail --yesno "pct create failed.\nDo you want to enable verbose debug mode and view detailed logs?" 12 70; then
|
||||||
set -x
|
set -x
|
||||||
pct create "$CTID" "local:vztmpl/${TEMPLATE}" "$PCT_OPTIONS" 2>&1 | tee -a "$LOGFILE"
|
command $pct_create_fallback_cmd 2>&1 | tee -a "$LOGFILE"
|
||||||
set +x
|
set +x
|
||||||
fi
|
fi
|
||||||
exit 209
|
exit 209
|
||||||
@@ -5162,7 +5165,7 @@ create_lxc_container() {
|
|||||||
msg_error "Container creation failed. See $LOGFILE"
|
msg_error "Container creation failed. See $LOGFILE"
|
||||||
if whiptail --yesno "pct create failed.\nDo you want to enable verbose debug mode and view detailed logs?" 12 70; then
|
if whiptail --yesno "pct create failed.\nDo you want to enable verbose debug mode and view detailed logs?" 12 70; then
|
||||||
set -x
|
set -x
|
||||||
pct create "$CTID" "local:vztmpl/${TEMPLATE}" "$PCT_OPTIONS" 2>&1 | tee -a "$LOGFILE"
|
command $pct_create_fallback_cmd 2>&1 | tee -a "$LOGFILE"
|
||||||
set +x
|
set +x
|
||||||
fi
|
fi
|
||||||
exit 209
|
exit 209
|
||||||
|
|||||||
Reference in New Issue
Block a user