-
Notifications
You must be signed in to change notification settings - Fork 23
/
vbox_init.sh
61 lines (57 loc) · 1.48 KB
/
vbox_init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#############################################
# "openbsd-init"
#
# Script to autostart a virtualbox VM on boot
#
# Place in /etc/init.d/
#
# A new copy can be made if more than one VM
# autostart is required. Change filename to
# match the value of $COMMAND
#
# Use the following arguments to control it:
# - start
# - stop
# - shutdown
# - reset
# - status
# - showlog
#
# Cribbed from https://askubuntu.com/a/778379
# and:
# https://www.virtualbox.org/manual/ch08.html
#############################################
VBUSER="string"
VM="OpenBSD"
COMMAND=$VM-init
case "$1" in
start)
echo "Starting $VM virtual machine"
sudo -H -u $VBUSER VBoxHeadless --startvm "$VM"
;;
stop)
echo "Saving state for $VM virtual machine"
sudo -H -u $VBUSER VBoxManage controlvm "$VM" savestate
sleep 120
;;
shutdown)
echo "Shutdown command sent to $VM virtual machine"
sudo -H -u $VBUSER VBoxManage controlvm "$VM" acpipowerbutton
sleep 120
;;
reset)
echo "Restart command sent to $VM virtual machine"
sudo -H -u $VBUSER VBoxManage controlvm "$VM" reset
;;
status)
echo -n "VM->";sudo -H -u $VBUSER VBoxManage showvminfo "$VM" --details
;;
showlog)
echo -n "VM->";sudo -H -u $VBUSER VBoxManage showvminfo "$VM" --log
;;
echo "Usage: /etc/init.d/$COMMAND {start|stop|shutdown|reset|status}"
exit 1
;;
esac
exit 0