mirror of
https://github.com/churchers/vm-bhyve.git
synced 2025-12-12 01:40:40 +01:00
Add a "vm restart guest" command
This causes a guest shutdown but then restarts the guest without requiring a full reload or destroying/re-creating network devices.
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
VERSION=1.3-devel
|
||||
VERSION_INT=103028
|
||||
VERSION_INT=103029
|
||||
VERSION_BSD=$(uname -K)
|
||||
PATH=${PATH}:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
CMD_VALID_LIST="init,switch,datastore,image,get,set,list,create,destroy,rename,install,start,stop,add"
|
||||
CMD_VALID_LIST="${CMD_VALID_LIST},reset,poweroff,startall,stopall,console,iso,configure,passthru,_run"
|
||||
CMD_VALID_LIST="init,switch,datastore,image,get,set,list,create,destroy,rename,install,start,stop,restart"
|
||||
CMD_VALID_LIST="${CMD_VALID_LIST},add,reset,poweroff,startall,stopall,console,iso,configure,passthru,_run"
|
||||
CMD_VALID_LIST="${CMD_VALID_LIST},info,clone,snapshot,rollback,send,recv,version,usage"
|
||||
|
||||
# cmd: vm ...
|
||||
@@ -74,6 +74,7 @@ cmd::parse(){
|
||||
install) core::install "$@" ;;
|
||||
start) core::start "$@" ;;
|
||||
stop) core::stop "$@" ;;
|
||||
restart) core::restart "$@" ;;
|
||||
add) core::add "$@" ;;
|
||||
reset) core::reset "$@" ;;
|
||||
poweroff) core::poweroff "$@" ;;
|
||||
|
||||
15
lib/vm-core
15
lib/vm-core
@@ -530,6 +530,21 @@ core::__start(){
|
||||
fi
|
||||
}
|
||||
|
||||
# 'vm restart'
|
||||
# restart a guest
|
||||
# all we do is create a "restart" file which vm-run looks for
|
||||
#
|
||||
# @param string _name name of the guest to restart
|
||||
#
|
||||
core::restart(){
|
||||
local _name="$1"
|
||||
|
||||
datastore::get_guest "${_name}" || util::err "unable to locate specified guest"
|
||||
echo "Setting guest restart flag"
|
||||
touch "${VM_DS_PATH}/${_name}/restart" >/dev/null 2>&1
|
||||
core::stop "${_name}"
|
||||
}
|
||||
|
||||
# 'vm stop'
|
||||
# send a kill signal to the specified guest
|
||||
#
|
||||
|
||||
10
lib/vm-run
10
lib/vm-run
@@ -152,7 +152,7 @@ vm::run(){
|
||||
_opts="-Hwl bootrom,${_bootrom}"
|
||||
_uefi="yes"
|
||||
else
|
||||
_uefi="no"
|
||||
_uefi=""
|
||||
fi
|
||||
|
||||
# add any custom bhyve options
|
||||
@@ -321,7 +321,13 @@ vm::handle_exit(){
|
||||
case "${_code}" in
|
||||
0) config::get "${_var}" "on_restart" "restart" ;;
|
||||
1) ;&
|
||||
2) setvar "${_var}" "shutdown" ;;
|
||||
2) if [ -e "${VM_DS_PATH}/${_name}/restart" ]; then
|
||||
setvar "${_var}" "restart"
|
||||
unlink "${VM_DS_PATH}/${_name}/restart" >/dev/null 2>&1
|
||||
else
|
||||
setvar "${_var}" "shutdown"
|
||||
fi
|
||||
;;
|
||||
*) config::get "${_var}" "on_fault" "shutdown" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -161,6 +161,7 @@ Usage: vm ...
|
||||
install [-fi] <name> <iso>
|
||||
start [-fi] <name> [...]
|
||||
stop <name> [...]
|
||||
restart <name>
|
||||
console <name> [com1|com2]
|
||||
configure <name>
|
||||
rename <name> <new-name>
|
||||
|
||||
12
vm.8
12
vm.8
@@ -101,6 +101,9 @@
|
||||
.Ar name
|
||||
.Ar ...
|
||||
.Nm
|
||||
.Cm restart
|
||||
.Ar name
|
||||
.Nm
|
||||
.Cm console
|
||||
.Ar name
|
||||
.Op Ar com1|com2
|
||||
@@ -725,6 +728,15 @@ If a guest is stuck in the bootloader stage, you are given the option to forcibl
|
||||
.Pp
|
||||
Multiple guests can be specified to this command at the same time.
|
||||
Each one will be sent a poweroff event.
|
||||
.It Cm restart Ar name
|
||||
Attempt to restart the specified guest. This causes a shutdown event to be sent to the
|
||||
guest, however, vm-bhyve will restart the guest rather than stopping completely.
|
||||
.Pp
|
||||
A benfit of using this function is that vm-bhyve will not destroy and recreate network devices like
|
||||
it would when using
|
||||
.Sy stop/start .
|
||||
Note that guest configuration is not re-loaded, so all guest settings will be as they were
|
||||
when the guest was originally started.
|
||||
.It Cm console Ar name Op Ar com1|com2
|
||||
Connect to the console of the named virtual machine.
|
||||
Without network access, this is the primary way of connecting to the guest once
|
||||
|
||||
Reference in New Issue
Block a user