Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VBoxManage controlvm <uuid>|<name>
- pause|resume|reset|poweroff|savestate|
- acpipowerbutton|acpisleepbutton|
- #!/bin/bash
- if [ -z "$1" ]; then
- echo "Usage: $0 VMNAME_or_UUID"
- exit 1
- fi
- set -x
- VBoxManage controlvm "$1" poweroff #enforce turnoff
- VBoxManage snapshot "$1" restorecurrent #retore state
- VBoxManage showvminfo "$1" | grep State #display state to ensure
- VBoxHeadless -s "$1" #run in headless mode in background
- [Unit]
- Description=VBox Virtual Machine %i Service
- Requires=systemd-modules-load.service
- After=systemd-modules-load.service
- [Service]
- User=user
- Group=vboxusers
- ExecStart=/usr/bin/VBoxHeadless -s %i
- ExecStop=/usr/bin/VBoxManage controlvm %i savestate
- [Install]
- WantedBy=multi-user.target
- $ sudo systemctl enable vboxvmservice@vm_name.service
- ...
- start(){
- su -c "VBoxHeadless --startvm thevm" -s /bin/bash theuser &
- # maybe another vbox command
- }
- stop(){
- su -c "VBoxManage controlvm thevm acpipowerbutton" -s /bin/bash theuser
- # maybe another vbox command
- while [ "`su -c 'VBoxManage list runningvms' -s /bin/bash theuser`" != "" ]
- do
- echo waiting for VMs to shutdown
- sleep 3
- done
- }
- ...
- VBoxManage startvm VMNAME --type headless
- VBoxManage controlvm VMNAME savestate
- VBoxManage list runningvms
- VBoxManage list runningvms | tr -s '" {' '%{' | cut -d '%' -f3 | while read uuid; do
- VBoxManage controlvm $uuid savestate;
- done
Add Comment
Please, Sign In to add comment