Add an rc script for starting vkernels upon boot.
authorSascha Wildner <saw@online.de>
Thu, 8 Apr 2010 10:04:44 +0000 (12:04 +0200)
committerSascha Wildner <saw@online.de>
Thu, 8 Apr 2010 10:04:44 +0000 (12:04 +0200)
I'm committing this for now since it works OK here and seems to be a
good thing.

Should anyone come up with better ideas for connecting to the vkernels'
consoles (as suggested by Matt and Nuno), that can go in later.

Dragonfly-bug: <http://bugs.dragonflybsd.org/issue697>

etc/defaults/rc.conf
etc/rc.d/Makefile
etc/rc.d/vkernel [new file with mode: 0644]
share/man/man5/rc.conf.5

index a5334d5..9bafa94 100644 (file)
@@ -14,7 +14,6 @@
 # All arguments must be in double or single quotes.
 #
 # $FreeBSD: src/etc/defaults/rc.conf,v 1.180 2003/06/26 09:50:50 smkelly Exp $
-# $DragonFly: src/etc/defaults/rc.conf,v 1.52 2008/10/03 00:26:21 hasso Exp $
 
 ##############################################################
 ###  Important initial Boot-time options  ####################
@@ -457,6 +456,30 @@ jail_sysvipc_allow="NO"    # Allow SystemV IPC use from within a jail
 #jail_example_flags="-l -U root"               # flags for jail(8)
 
 ##############################################################
+###  VKernel options #########################################
+##############################################################
+
+vkernel_enable="NO"    # Set to YES to enable starting of vkernels
+vkernel_list=""                # Space separated list of names of vkernels
+
+#
+# Create an entry for each vkernel specified in vkernel_list
+# replacing 'example' by the name of the vkernel.
+#
+#vkernel_example_bin="/boot/kernel.VKERNEL"
+       # Path to the vkernel binary
+#vkernel_example_memsize="64m"
+       # Amount of memory for the vkernel
+#vkernel_example_rootimg_list="/var/vkernel/rootimg.01"
+       # Space separated list of disk images
+#vkernel_example_iface_list="auto:bridge0"
+       # Optional: space separated list network interfaces for the vkernel
+#vkernel_example_logfile="/dev/null"
+       # Optional: path to the console log file
+#vkernel_example_flags="-U"
+       # Optional: aditional flags to start the vkernel with
+
+##############################################################
 ### Define source_rc_confs, the mechanism used by /etc/rc.* ##
 ### scripts to source rc_conf_files overrides safely.      ##
 ##############################################################
index 70b7d54..2532122 100644 (file)
@@ -1,10 +1,9 @@
 # $NetBSD: Makefile,v 1.16 2001/01/14 15:37:22 minoura Exp $
 # $FreeBSD: src/etc/rc.d/Makefile,v 1.20 2003/06/29 05:15:57 mtm Exp $
-# $DragonFly: src/etc/rc.d/Makefile,v 1.31 2008/10/03 10:27:42 swildner Exp $
 
 .include <bsd.own.mk>
 
-# note: bgfsk, devfs, and lomac left out (from 5.0)
+# note: bgfsk and lomac left out (from 5.0)
 #
 FILES= DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz \
        amd apm apmd atm1 atm2 atm3 \
@@ -23,7 +22,8 @@ FILES=        DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz \
        quota random rarpd rcconf resident rndcontrol root route6d routed \
        routing rpcbind rtadvd rtsold rwho sysdb savecore sdpd securelevel \
        sendmail sensorsd serial sppp sshd statd swap1 syscons sysctl syslogd \
-       timed ttys usbd varsym vinum virecover watchdogd wpa_supplicant \
+       timed ttys usbd varsym vinum vkernel virecover \
+       watchdogd wpa_supplicant \
        ypbind yppasswdd ypserv ypset ypupdated ypxfrd
 
 FILESDIR=      /etc/rc.d
diff --git a/etc/rc.d/vkernel b/etc/rc.d/vkernel
new file mode 100644 (file)
index 0000000..ef28133
--- /dev/null
@@ -0,0 +1,105 @@
+#!/bin/sh
+#
+
+# PROVIDE: vkernel
+# REQUIRE: LOGIN NETWORKING
+
+. /etc/rc.subr
+
+name="vkernel"
+rcvar=`set_rcvar`
+start_cmd="vkernel_start"
+stop_cmd="vkernel_stop"
+
+vkernel_start()
+{
+       echo -n 'Starting virtual kernels:'
+       for _vkernel in ${vkernel_list}
+       do
+               # Check if already running
+               eval pidfile="/var/run/vkernel.${_vkernel}.pid"
+               if [ -f "${_pidfile}" ]; then
+                       echo
+                       warn "Vkernel ${_vkernel} already running? (check ${pidfile})"
+                       continue
+               fi
+
+               # Configure vkernel binary
+               eval _bin=\"\${vkernel_${_vkernel}_bin}\"
+               if [ -z "${_bin}" -o ! -x "${_bin}" ]; then
+                       echo
+                       warn "Missing or undefined binary for vkernel '${_vkernel}'. Skipping."
+                       continue
+               else
+                       bin=${_bin}
+               fi
+
+               # Configure vkernel memory
+               eval _memsize=\"\$vkernel_${_vkernel}_memsize\"
+               if [ -z "${_memsize}" ]; then
+                       echo
+                       warn "No memsize has been defined for vkernel '${_vkernel}'. Skipping."
+                       continue
+               else
+                       memsize="-m ${_memsize}"
+               fi
+
+               # Configure vkernel root image(s)
+               eval _rootimgs=\"\${vkernel_${_vkernel}_rootimg_list}\"
+               if [ -z "${_rootimgs}" ]; then
+                       echo
+                       warn "No root image has been defined for vkernel '${_vkernel}'. Skipping."
+                       continue
+               else
+                       for _rootimg in ${_rootimgs}
+                       do
+                               eval rootimgs=\"${rootimgs} -r ${_rootimg}\"
+                       done
+               fi
+
+               # Configure optional vkernel network interface(s)
+               eval _ifaces=\"\${vkernel_${_vkernel}_iface_list}\"
+               if [ -n "${_ifaces}" ]; then
+                       for _iface in ${_ifaces}
+                       do
+                               eval ifaces=\"${ifaces} -I ${_iface}\"
+                       done
+               fi
+
+               # Configure optional console logfile
+               eval logfile=\"\${vkernel_${_vkernel}_logfile}\"
+               [ -z "${logfile}" ] && logfile="/dev/null"
+
+               # Configure optional flags
+               eval flags=\"\${vkernel_${_vkernel}_flags}\"
+
+               eval "daemon ${bin} ${memsize} ${rootimgs} ${ifaces} ${flags} -p ${pidfile} >>${logfile} 2>&1"
+               echo -n " ${_vkernel}"
+       done
+       echo '.'
+}
+
+vkernel_stop()
+{
+       for _vkernel in ${vkernel_list}
+       do
+               eval pidfile="/var/run/vkernel.${_vkernel}.pid"
+               if [ -f "${pidfile}" ]; then
+                       eval pid=`cat ${pidfile}`
+               else
+                       eval _bin=\"\${vkernel_${_vkernel}_bin}\"
+                       if [ -n "$_bin" ]; then
+                               eval pid=`ps auxwww | grep ${_bin} | grep -v grep | awk '{print $2}'`
+                       fi
+               fi
+               if [ -z "${pid}" ]; then
+                       warn "vkernel '${_vkernel}' not running?"
+               else
+                       eval kill -TERM ${pid}
+               fi
+       done
+}
+
+
+load_rc_config $name
+run_rc_command "$1"
index 386fb50..c7128fb 100644 (file)
@@ -23,8 +23,8 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $FreeBSD: src/share/man/man5/rc.conf.5,v 1.197 2003/07/28 13:56:00 mbr Exp $
-.\" $DragonFly: src/share/man/man5/rc.conf.5,v 1.61 2008/10/20 07:35:08 swildner Exp $
-.Dd December 12, 2009
+.\"
+.Dd April 8, 2010
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -2824,6 +2824,35 @@ If set, start a watchdog timer in the background which will terminate
 if
 .Xr shutdown 8
 has not completed within the specified time (in seconds).
+.It Va vkernel_enable
+.Pq Vt bool
+If set to
+.Dq Li NO ,
+any configured vkernels will not be started.
+.It Va vkernel_list
+.Pq Vt str
+A space separated list of names for vkernels.
+This is purely a configuration aid to help identify and
+configure multiple vkernels.
+The names specified in this list will be used to
+identify settings common to a vkernel instance.
+Assuming that the vkernel in question was named
+.Li example ,
+you would have the following dependent variables
+(filled with reference values in this text):
+.Bd -literal
+vkernel_example_bin="/usr/obj/usr/src/sys/VKERNEL/kernel.debug"
+vkernel_example_memsize="64m"
+vkernel_example_rootimg_list="/var/vkernel/rootimg.01"
+vkernel_example_iface_list="auto:bridge0"
+vkernel_example_logfile="/dev/null"
+vkernel_example_flags="-U"
+.Ed
+.Pp
+The last three are optional.
+They default to an empty string if not set, except for logfile which defaults to
+.Pa /dev/null
+if it is not set.
 .El
 .Sh FILES
 .Bl -tag -width ".Pa /etc/start_if. Ns Aq Ar interface" -compact