aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2021-10-20 20:03:15 +0000
committerrodri <rgl@antares-labs.eu>2021-10-20 20:03:15 +0000
commit0f6ff3b8ef4d0747112f1087d8cced7c9a16eb5f (patch)
tree0f18ac9ce7308854c5f2c891828cb24f97d884e1
downloadbhyve-rc.d-0f6ff3b8ef4d0747112f1087d8cced7c9a16eb5f.tar.gz
bhyve-rc.d-0f6ff3b8ef4d0747112f1087d8cced7c9a16eb5f.tar.bz2
bhyve-rc.d-0f6ff3b8ef4d0747112f1087d8cced7c9a16eb5f.zip
let the game begin.
-rwxr-xr-xbhyve_coeus57
-rwxr-xr-xbhyve_linux57
-rwxr-xr-xbhyve_test57
-rw-r--r--readme.md3
-rwxr-xr-xvmm/machine/coeus/run16
-rwxr-xr-xvmm/machine/linux/run17
-rwxr-xr-xvmm/machine/test/run15
7 files changed, 222 insertions, 0 deletions
diff --git a/bhyve_coeus b/bhyve_coeus
new file mode 100755
index 0000000..e6f443a
--- /dev/null
+++ b/bhyve_coeus
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# $AntaresLabs$
+#
+
+# PROVIDE: bhyve_coeus
+# REQUIRE: DAEMON FILESYSTEMS
+# KEYWORD: nojail shutdown
+
+. /etc/rc.subr
+
+vmname=coeus
+name="bhyve_${vmname}"
+desc="Bhyve - ${vmname} VM"
+rcvar="${name}_enable"
+start_cmd="bhyve_start"
+stop_cmd="bhyve_stop"
+status_cmd="bhyve_status"
+extra_commands="status"
+
+load_rc_config $name
+: ${bhyve_coeus_enable:=NO}
+
+runvm()
+{
+ local rc=0
+
+ while [ $rc -eq 0 ];do
+ /vmm/machine/${vmname}/run
+ rc=$?
+ done
+}
+
+bhyve_start()
+{
+ runvm &
+}
+
+bhyve_status()
+{
+ local pid=$(ps axo pid,command | egrep "${vmname}.*\\(bhyve\\)" | awk '{print $1}')
+
+ if [ ! -z $pid ];then
+ echo $name is running with pid $pid. 2>&1
+ return 0
+ else
+ echo $name is not running.
+ fi
+}
+
+bhyve_stop()
+{
+ local pid=$(ps axo pid,command | egrep "${vmname}.*\\(bhyve\\)" | awk '{print $1}')
+ kill -TERM $pid
+}
+
+run_rc_command "$1"
diff --git a/bhyve_linux b/bhyve_linux
new file mode 100755
index 0000000..117c0e7
--- /dev/null
+++ b/bhyve_linux
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# $AntaresLabs$
+#
+
+# PROVIDE: bhyve_linux
+# REQUIRE: DAEMON FILESYSTEMS
+# KEYWORD: nojail shutdown
+
+. /etc/rc.subr
+
+vmname=linux
+name="bhyve_${vmname}"
+desc="Bhyve - ${vmname} VM"
+rcvar="${name}_enable"
+start_cmd="bhyve_start"
+stop_cmd="bhyve_stop"
+status_cmd="bhyve_status"
+extra_commands="status"
+
+load_rc_config $name
+: ${bhyve_linux_enable:=NO}
+
+runvm()
+{
+ local rc=0
+
+ while [ $rc -eq 0 ];do
+ /vmm/machine/${vmname}/run
+ rc=$?
+ done
+}
+
+bhyve_start()
+{
+ runvm &
+}
+
+bhyve_status()
+{
+ local pid=$(ps axo pid,command | egrep "${vmname}.*\\(bhyve\\)" | awk '{print $1}')
+
+ if [ ! -z $pid ];then
+ echo $name is running with pid $pid. 2>&1
+ return 0
+ else
+ echo $name is not running.
+ fi
+}
+
+bhyve_stop()
+{
+ local pid=$(ps axo pid,command | egrep "${vmname}.*\\(bhyve\\)" | awk '{print $1}')
+ kill -TERM $pid
+}
+
+run_rc_command "$1"
diff --git a/bhyve_test b/bhyve_test
new file mode 100755
index 0000000..a20cf0f
--- /dev/null
+++ b/bhyve_test
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# $AntaresLabs$
+#
+
+# PROVIDE: bhyve_test
+# REQUIRE: DAEMON FILESYSTEMS
+# KEYWORD: nojail shutdown
+
+. /etc/rc.subr
+
+vmname=test
+name="bhyve_${vmname}"
+desc="Bhyve - ${vmname} VM"
+rcvar="${name}_enable"
+start_cmd="bhyve_start"
+stop_cmd="bhyve_stop"
+status_cmd="bhyve_status"
+extra_commands="status"
+
+load_rc_config $name
+: ${bhyve_test_enable:=NO}
+
+runvm()
+{
+ local rc=0
+
+ while [ $rc -eq 0 ];do
+ /vmm/machine/${vmname}/run
+ rc=$?
+ done
+}
+
+bhyve_start()
+{
+ runvm &
+}
+
+bhyve_status()
+{
+ local pid=$(ps axo pid,command | egrep "${vmname}.*\\(bhyve\\)" | awk '{print $1}')
+
+ if [ ! -z $pid ];then
+ echo $name is running with pid $pid. 2>&1
+ return 0
+ else
+ echo $name is not running.
+ fi
+}
+
+bhyve_stop()
+{
+ local pid=$(ps axo pid,command | egrep "${vmname}.*\\(bhyve\\)" | awk '{print $1}')
+ kill -TERM $pid
+}
+
+run_rc_command "$1"
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..fd2b099
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,3 @@
+# rc.d services for Bhyve VM management
+
+These are some of the services I use to run the VMs in my internal grid under FreeBSD. It offers very basic management and monitoring at the moment.
diff --git a/vmm/machine/coeus/run b/vmm/machine/coeus/run
new file mode 100755
index 0000000..a3054b8
--- /dev/null
+++ b/vmm/machine/coeus/run
@@ -0,0 +1,16 @@
+#!/bin/sh
+name=coeus
+id=0
+mem=4096
+ncpu=4
+fbw=1024
+fbh=768
+bhyve -AHPw -s0:0,hostbridge \
+ -s1:0,lpc \
+ -s2:0,virtio-net,tap$id \
+ -s3:0,virtio-blk,/dev/zvol/zroot/${name}disk \
+ -l com1,/dev/nmdm${id}A \
+ -s29,fbuf,tcp=127.0.0.1:$((5900+$id)),w=$fbw,h=$fbh \
+ -s30,xhci,tablet \
+ -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
+ -c $ncpu -m $mem $name >>/vmm/machine/$name/log/out 2>>/vmm/machine/$name/log/err
diff --git a/vmm/machine/linux/run b/vmm/machine/linux/run
new file mode 100755
index 0000000..67bdb63
--- /dev/null
+++ b/vmm/machine/linux/run
@@ -0,0 +1,17 @@
+#!/bin/sh
+name=linux
+id=1
+mem=4096
+ncpu=4
+fbw=1920
+fbh=1080
+bhyve -AHPw -s0:0,hostbridge \
+ -s1:0,lpc \
+ -s2:0,virtio-net,tap$id \
+ -s3:0,virtio-blk,/dev/zvol/zroot/${name}disk \
+ -s16:0,hda,play=/dev/dsp,rec=/dev/dsp \
+ -l com1,/dev/nmdm${id}A \
+ -s29,fbuf,tcp=127.0.0.1:$((5900+$id)),w=$fbw,h=$fbh \
+ -s30,xhci,tablet \
+ -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
+ -c $ncpu -m $mem $name >>/vmm/machine/$name/log/out 2>>/vmm/machine/$name/log/err
diff --git a/vmm/machine/test/run b/vmm/machine/test/run
new file mode 100755
index 0000000..b563543
--- /dev/null
+++ b/vmm/machine/test/run
@@ -0,0 +1,15 @@
+#!/bin/sh
+name=test
+id=3
+mem=2048
+ncpu=1
+fbw=1024
+fbh=768
+bhyve -AHPw -s0:0,hostbridge \
+ -s1:0,lpc \
+ -s2:0,virtio-net,tap$id \
+ -s3:0,virtio-blk,/dev/zvol/zroot/${name}disk \
+ -l com1,/dev/nmdm${id}A \
+ -s29,fbuf,tcp=127.0.0.1:$((5900+$id)),w=$fbw,h=$fbh \
+ -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
+ -c $ncpu -m $mem $name >>/vmm/machine/$name/log/out 2>>/vmm/machine/$name/log/err