bkctld-rename: rename a jail and all its incs and configuration…
This commit is contained in:
parent
31fb33adc4
commit
a50991226c
|
@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
* bkctld-rename: rename a jail and all its incs and configuration…
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
10
bkctld
10
bkctld
|
@ -156,6 +156,16 @@ case "${subcommand}" in
|
||||||
done
|
done
|
||||||
echo "finish"
|
echo "finish"
|
||||||
;;
|
;;
|
||||||
|
"rename")
|
||||||
|
jail_name="${2:-}"
|
||||||
|
new_jail_name="${3:-}"
|
||||||
|
if [ -z "${jail_name}" ] || [ -z "${new_jail_name}" ]; then
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${new_jail_name}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
show_help
|
show_help
|
||||||
exit 1
|
exit 1
|
||||||
|
|
71
lib/bkctld-rename
Executable file
71
lib/bkctld-rename
Executable file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Description: Rename a jail
|
||||||
|
# Usage: rename <jailname> <new-jailname>
|
||||||
|
# Return codes:
|
||||||
|
# * 1: error
|
||||||
|
#
|
||||||
|
|
||||||
|
# shellcheck source=./includes
|
||||||
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
||||||
|
|
||||||
|
jail_name="${1:?}"
|
||||||
|
new_jail_name="${2:?}"
|
||||||
|
if [ -z "${jail_name}" ] || [ -z "${new_jail_name}" ]; then
|
||||||
|
show_help && exit 1
|
||||||
|
fi
|
||||||
|
jail_path=$(jail_path "${jail_name}")
|
||||||
|
incs_path=$(incs_path "${jail_name}")
|
||||||
|
jail_config_dir=$(jail_config_dir "${jail_name}")
|
||||||
|
legacy_config_file="${CONFDIR}/${jail_name}"
|
||||||
|
|
||||||
|
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
|
||||||
|
|
||||||
|
new_jail_path=$(jail_path "${new_jail_name}")
|
||||||
|
new_incs_path=$(incs_path "${new_jail_name}")
|
||||||
|
new_jail_config_dir=$(jail_config_dir "${new_jail_name}")
|
||||||
|
new_legacy_config_file="${CONFDIR}/${new_jail_name}"
|
||||||
|
|
||||||
|
test -d "${new_jail_path}" && error "${new_jail_name}: jail already exists" 2
|
||||||
|
|
||||||
|
"${LIBDIR}/bkctld-is-on" "${jail_name}" 2>/dev/null
|
||||||
|
case "$?" in
|
||||||
|
0)
|
||||||
|
jail_initial_status="on"
|
||||||
|
;;
|
||||||
|
100)
|
||||||
|
jail_initial_status="off"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
unset jail_initial_status
|
||||||
|
error "Error evaluating jail \`${jail_name}' state. bkctld-is-on exited with \`$?'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
test "${jail_initial_status}" = "on" && "${LIBDIR}/bkctld-stop" "${jail_name}"
|
||||||
|
|
||||||
|
if dry_run; then
|
||||||
|
echo "[dry-run] rename ${jail_path} to ${new_jail_path}"
|
||||||
|
echo "[dry-run] rename ${incs_path} to ${new_incs_path}"
|
||||||
|
else
|
||||||
|
mv "${jail_path}" "${new_jail_path}"
|
||||||
|
mv "${incs_path}" "${new_incs_path}"
|
||||||
|
fi
|
||||||
|
if [ -d "${jail_config_dir}" ]; then
|
||||||
|
if dry_run; then
|
||||||
|
mv "${jail_config_dir}" "${new_jail_config_dir}"
|
||||||
|
else
|
||||||
|
echo "[dry-run] rename ${jail_config_dir} to ${new_jail_config_dir}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ -f "${legacy_config_file}" ]; then
|
||||||
|
if dry_run; then
|
||||||
|
mv "${legacy_config_file}" "${new_legacy_config_file}"
|
||||||
|
else
|
||||||
|
echo "[dry-run] rename ${legacy_config_file} to ${new_legacy_config_file}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
test "${jail_initial_status}" = "on" && "${LIBDIR}/bkctld-start" "${new_jail_name}"
|
||||||
|
|
||||||
|
notice "Rename jail \`${jail_name}' to \`${new_jail_name}' : OK"
|
|
@ -61,6 +61,20 @@ load test_helper
|
||||||
refute_equal "${pid_before}" "${pid_after}"
|
refute_equal "${pid_before}" "${pid_after}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "A jail should be able to be renamed" {
|
||||||
|
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
|
||||||
|
new_name="${JAILNAME}-new"
|
||||||
|
# A started jail should report to be ON
|
||||||
|
run /usr/lib/bkctld/bkctld-rename "${JAILNAME}" "${new_name}"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run /usr/lib/bkctld/bkctld-is-on "${new_name}"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
# change variable to new name,for teardown
|
||||||
|
JAILNAME="${new_name}"
|
||||||
|
}
|
||||||
|
|
||||||
@test "Status should return information" {
|
@test "Status should return information" {
|
||||||
run /usr/lib/bkctld/bkctld-status "${JAILNAME}"
|
run /usr/lib/bkctld/bkctld-status "${JAILNAME}"
|
||||||
assert_success
|
assert_success
|
||||||
|
@ -76,4 +90,4 @@ load test_helper
|
||||||
# A stopped jail should not report to be ON
|
# A stopped jail should not report to be ON
|
||||||
run /usr/lib/bkctld/bkctld-is-on "${JAILNAME}"
|
run /usr/lib/bkctld/bkctld-is-on "${JAILNAME}"
|
||||||
assert_failure
|
assert_failure
|
||||||
}
|
}
|
Loading…
Reference in a new issue