Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison files/fbhyve.in @ 467:6ecd16725818
Begin refactoring bhyve into fbhyve.
Planned:
- more consistent naming (analogous to jails)
- using bhyve configuration files instead of RC variables for bhyve devices
- more docs
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 14 Jun 2024 09:40:04 +0200 |
| parents | c8abd9d7aac7 |
| children | 57f253106ed6 |
comparison
equal
deleted
inserted
replaced
| 466:4638f2f68b9d | 467:6ecd16725818 |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 # PROVIDE: bhyve | 3 # PROVIDE: fbhyve |
| 4 # REQUIRE: LOGIN | 4 # REQUIRE: LOGIN |
| 5 # KEYWORD: nojail | 5 # KEYWORD: shutdown nojail |
| 6 # | 6 # |
| 7 | |
| 8 # @(#)%%SIMPLEVERSIONTAG%% | |
| 7 | 9 |
| 8 # | 10 # |
| 9 # Add the following lines to /etc/rc.conf to enable bhyve: | 11 # Add the following lines to /etc/rc.conf to enable bhyve: |
| 10 # bhyve_enable (bool): Set to "NO" by default. | 12 # fbhyve_enable (bool): Set to "NO" by default. |
| 11 # Set it to "YES" to enable bhyve | 13 # Set it to "YES" to enable bhyve |
| 12 # bhyve_profiles (str): Set to "" by default. | 14 # bhyve_profiles (str): Set to "" by default. |
| 13 # Define your profiles here. | 15 # Define your profiles here. |
| 14 # bhyve_tapdev (str): Set to "tap0" by default. | 16 # bhyve_tapdev (str): Set to "tap0" by default. |
| 15 # Set to the tap(4) device to use. | 17 # Set to the tap(4) device to use. |
| 16 # bhyve_diskdev (str): Must be set, no default. | 18 # bhyve_diskdev (str): Must be set, no default. |
| 20 # bhyve_memsize (int): Set to 512 by default. | 22 # bhyve_memsize (int): Set to 512 by default. |
| 21 # Set to the number of MB of memory for the VM. | 23 # Set to the number of MB of memory for the VM. |
| 22 | 24 |
| 23 . /etc/rc.subr | 25 . /etc/rc.subr |
| 24 | 26 |
| 25 name="bhyve" | 27 name="fbhyve" |
| 26 rcvar=bhyve_enable | 28 rcvar=fbhyve_enable |
| 27 | 29 |
| 28 start_precmd="bhyve_prestart" | 30 start_precmd="bhyve_prestart" |
| 29 status_cmd="bhyve_status" | 31 status_cmd="bhyve_status" |
| 30 poll_cmd="bhyve_poll" | 32 poll_cmd="bhyve_poll" |
| 31 stop_cmd="bhyve_stop" | 33 stop_cmd="bhyve_stop" |
| 32 _session=$name | 34 _session=$name |
| 33 command="/usr/local/bin/tmux" | 35 command="/usr/local/bin/tmux" |
| 34 procname="-sh" | 36 procname="-sh" |
| 35 | 37 |
| 36 [ -z "$bhyve_enable" ] && bhyve_enable="NO" | |
| 37 [ -z "$bhyve_tapdev" ] && bhyve_tapdev="tap0" | 38 [ -z "$bhyve_tapdev" ] && bhyve_tapdev="tap0" |
| 38 [ -z "$bhyve_diskdev" ] && bhyve_diskdev="none" | 39 [ -z "$bhyve_diskdev" ] && bhyve_diskdev="none" |
| 39 [ -z "$bhyve_ncpu" ] && bhyve_ncpu="1" | 40 [ -z "$bhyve_ncpu" ] && bhyve_ncpu="1" |
| 40 [ -z "$bhyve_memsize" ] && bhyve_memsize="512" | 41 [ -z "$bhyve_memsize" ] && bhyve_memsize="512" |
| 41 | 42 |
| 42 load_rc_config $name | 43 load_rc_config $name |
| 43 | 44 |
| 45 : {fbhyve_enable:="NO"} | |
| 46 : {fbhyve_configdir:="%%PREFIX%%/etc/fbhyve"} | |
| 47 | |
| 48 | |
| 44 if [ -n "$2" ]; then | 49 if [ -n "$2" ]; then |
| 45 profile="$2" | 50 profile="$2" |
| 46 _session="${_session}_${profile}" | 51 _session="${_session}_${profile}" |
| 47 if [ "x${bhyve_profiles}" != "x" ]; then | 52 if [ "x${bhyve_profiles}" != "x" ]; then |
| 48 eval bhyve_enable="\${${_session}_enable:-${bhyve_enable}}" | 53 eval fbhyve_enable="\${${_session}_enable:-${fbhyve_enable}}" |
| 49 eval bhyve_tapdev="\${${_session}_tapdev:-${bhyve_tapdev}}" | 54 eval bhyve_tapdev="\${${_session}_tapdev:-${bhyve_tapdev}}" |
| 50 eval bhyve_diskdev="\${${_session}_diskdev:-${bhyve_diskdev}}" | 55 eval bhyve_diskdev="\${${_session}_diskdev:-${bhyve_diskdev}}" |
| 51 eval bhyve_ncpu="\${${_session}_ncpu:-${bhyve_ncpu}}" | 56 eval bhyve_ncpu="\${${_session}_ncpu:-${bhyve_ncpu}}" |
| 52 eval bhyve_memsize="\${${_session}_memsize:-${bhyve_memsize}}" | 57 eval bhyve_memsize="\${${_session}_memsize:-${bhyve_memsize}}" |
| 53 else | 58 else |
| 55 fi | 60 fi |
| 56 else | 61 else |
| 57 if [ "x${bhyve_profiles}" != "x" -a "x$1" != "x" ]; then | 62 if [ "x${bhyve_profiles}" != "x" -a "x$1" != "x" ]; then |
| 58 for profile in ${bhyve_profiles}; do | 63 for profile in ${bhyve_profiles}; do |
| 59 eval _enable="\${bhyve_${profile}_enable}" | 64 eval _enable="\${bhyve_${profile}_enable}" |
| 60 case "x${_enable:-${bhyve_enable}}" in | 65 case "x${_enable:-${fbhyve_enable}}" in |
| 61 x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee]) | 66 x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee]) |
| 62 continue | 67 continue |
| 63 ;; | 68 ;; |
| 64 x[Yy][Ee][Ss]) | 69 x[Yy][Ee][Ss]) |
| 65 ;; | 70 ;; |
| 66 *) | 71 *) |
| 67 if test -z "$_enable"; then | 72 if test -z "$_enable"; then |
| 68 _var=bhyve_enable | 73 _var=fbhyve_enable |
| 69 else | 74 else |
| 70 _var=bhyve_"${profile}"_enable | 75 _var=bhyve_"${profile}"_enable |
| 71 fi | 76 fi |
| 72 echo "Bad value" \ | 77 echo "Bad value" \ |
| 73 "'${_enable:-${bhyve_enable}}'" \ | 78 "'${_enable:-${fbhyve_enable}}'" \ |
| 74 "for ${_var}. " \ | 79 "for ${_var}. " \ |
| 75 "Profile ${profile} skipped." | 80 "Profile ${profile} skipped." |
| 76 continue | 81 continue |
| 77 ;; | 82 ;; |
| 78 esac | 83 esac |
