From 1f406c9679f978aa53960befa2e44087bafbb004 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 11 May 2025 18:24:59 -0600 Subject: [PATCH 1/3] migrate: Allow live migration --- usr/local/share/bastille/migrate.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/usr/local/share/bastille/migrate.sh b/usr/local/share/bastille/migrate.sh index 59b05143..1b0f96e6 100644 --- a/usr/local/share/bastille/migrate.sh +++ b/usr/local/share/bastille/migrate.sh @@ -47,6 +47,7 @@ usage() { -b | --backup Retain archives on remote system. -d | --destroy Destroy local jail after migration. | --doas Use 'doas' instead of 'sudo'. + -l | --live Migrate a running jail (ZFS only). -p | --password Use password based authentication. -x | --debug Enable debug mode. @@ -56,6 +57,7 @@ EOF # Handle options. AUTO=0 +LIVE=0 OPT_BACKUP=0 OPT_DESTROY=0 OPT_PASSWORD=0 @@ -81,6 +83,10 @@ while [ "$#" -gt 0 ]; do OPT_SU="doas" shift ;; + -l|--live) + LIVE=1 + shift + ;; -p|--password) OPT_PASSWORD=1 shift @@ -95,6 +101,7 @@ while [ "$#" -gt 0 ]; do a) AUTO=1 ;; b) OPT_BACKUP=1 ;; d) OPT_DESTROY=1 ;; + l) LIVE=1 ;; p) OPT_PASSWORD=1 ;; x) enable_debug ;; *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; @@ -334,12 +341,18 @@ for _jail in ${JAILS}; do ( # Validate jail state - check_target_is_stopped "${_jail}" || if [ "${AUTO}" -eq 1 ]; then - bastille stop "${_jail}" - else - info "\n[${_jail}]:" - error_notify "Jail is running." - error_continue "Use [-a|--auto] to auto-stop the jail." + if [ "${LIVE}" -eq 1 ]; then + if ! check_target_is_running "${_jail}"; then + error_exit "[ERROR]: [-l|--live] can only be used with a running jail." + fi + elif ! check_target_is_stopped "${_jail}"; then + if [ "${AUTO}" -eq 1 ]; then + bastille stop "${_jail}" + else + info "\n[${_jail}]:" + error_notify "[ERROR]: Jail is running." + error_exit "Use [-a|--auto] to auto-stop the jail, or [-l|--live] (ZFS only) to migrate a running jail." + fi fi info "\nAttempting to migrate '${_jail}' to '${HOST}'..." From b80744f9239d8521a46e75e201098872d90cf0d3 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 11 May 2025 18:26:19 -0600 Subject: [PATCH 2/3] docs: Update migrate for live migration --- docs/chapters/subcommands/migrate.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/chapters/subcommands/migrate.rst b/docs/chapters/subcommands/migrate.rst index 97809672..daf26d8c 100644 --- a/docs/chapters/subcommands/migrate.rst +++ b/docs/chapters/subcommands/migrate.rst @@ -25,5 +25,6 @@ port by supplying it as in ``user@host:port``. -d | --destroy Destroy local jail after migration. -b | --backup Retain archives on remote system. | --doas Use 'doas' instead of 'sudo'. + -l | --live Migrate a running jail (ZFS only). -p | --password Use password based authentication. -x | --debug Enable debug mode. From f94c273a9d3f687db489aa3a4b979da5cd165674 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 11 May 2025 18:28:12 -0600 Subject: [PATCH 3/3] Update migrate.sh --- usr/local/share/bastille/migrate.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/usr/local/share/bastille/migrate.sh b/usr/local/share/bastille/migrate.sh index 1b0f96e6..8f492021 100644 --- a/usr/local/share/bastille/migrate.sh +++ b/usr/local/share/bastille/migrate.sh @@ -115,6 +115,13 @@ while [ "$#" -gt 0 ]; do esac done +# Validate options +if [ "${LIVE}" -eq 1 ]; then + if ! checkyesno bastille_zfs_enable; then + error_exit "[ERROR]: [-l|--live] can only be used with ZFS systems." + fi +fi + if [ "$#" -ne 2 ]; then usage fi