kernel - Add kprintf0() (#ifdef'd out)
[dragonfly.git] / etc / rc.d / vkernel
blob78ec7c332467dcacb6c23baa7c0756d824472985
1 #!/bin/sh
4 # PROVIDE: vkernel
5 # REQUIRE: LOGIN NETWORKING
7 . /etc/rc.subr
9 name="vkernel"
10 rcvar=`set_rcvar`
11 start_cmd="vkernel_start"
12 stop_cmd="vkernel_stop"
14 vkernel_start()
16 echo -n 'Starting virtual kernels:'
17 for _vkernel in ${vkernel_list}
19 # Check if already running
20 eval pidfile="/var/run/vkernel.${_vkernel}.pid"
21 if [ -f "${pidfile}" ]; then
22 eval pid=`cat ${pidfile}`
23 if [ ! -z "${pid}" -a ! -z "`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`" ]; then
24 echo
25 warn "Vkernel ${_vkernel} already running? (check ${pidfile})"
26 continue
30 # Configure vkernel binary
31 eval _bin=\"\${vkernel_${_vkernel}_bin}\"
32 if [ -z "${_bin}" -o ! -x "${_bin}" ]; then
33 eval _bin=\"\${vkernel_bin}\"
34 if [ -z "${_bin}" -o ! -x "${_bin}" ]; then
35 echo
36 warn "Missing or undefined binary for vkernel '${_vkernel}'. Skipping."
37 continue
40 bin=${_bin}
42 # Configure vkernel memory
43 eval _memsize=\"\$vkernel_${_vkernel}_memsize\"
44 if [ -z "${_memsize}" ]; then
45 echo
46 warn "No memsize has been defined for vkernel '${_vkernel}'. Skipping."
47 continue
48 else
49 memsize="-m ${_memsize}"
52 # Configure vkernel root image(s)
53 eval _rootimgs=\"\${vkernel_${_vkernel}_rootimg_list}\"
54 if [ -z "${_rootimgs}" ]; then
55 echo
56 warn "No root image has been defined for vkernel '${_vkernel}'."
57 else
58 for _rootimg in ${_rootimgs}
60 eval rootimgs=\"${rootimgs} -r ${_rootimg}\"
61 done
64 # Configure optional vkernel network interface(s)
65 eval _ifaces=\"\${vkernel_${_vkernel}_iface_list}\"
66 if [ -n "${_ifaces}" ]; then
67 for _iface in ${_ifaces}
69 eval ifaces=\"${ifaces} -I ${_iface}\"
70 done
73 # Configure optional console logfile
74 eval logfile=\"\${vkernel_${_vkernel}_logfile}\"
75 [ -z "${logfile}" ] && logfile="/dev/null"
77 # Configure optional flags
78 eval flags=\"\${vkernel_${_vkernel}_flags}\"
80 eval "daemon ${bin} ${memsize} ${rootimgs} ${ifaces} ${flags} -p ${pidfile} >>${logfile} 2>&1 </dev/null"
81 echo -n " ${_vkernel}"
82 done
83 echo '.'
86 vkernel_stop()
88 for _vkernel in ${vkernel_list}
90 eval pidfile="/var/run/vkernel.${_vkernel}.pid"
91 if [ -f "${pidfile}" ]; then
92 eval pid=`cat ${pidfile}`
94 if [ -z "${pid}" ]; then
95 warn "vkernel '${_vkernel}' not running?"
96 continue
98 eval kill -TERM ${pid}
100 eval _kill_timeout=\"\${vkernel_${_vkernel}_kill_timeout}\"
101 if [ -z "${_kill_timeout}" ]; then
102 eval _kill_timeout=\"\${vkernel_kill_timeout}\"
103 if [ -z "${_kill_timeout}" ]; then
104 _kill_timeout=60
108 # Check that the vkernel ended properly
109 cnt=1
110 eval temp_pid=`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`
111 while [ ! -z "${temp_pid}" -a "${cnt}" -lt "${_kill_timeout}" ]; do
112 eval temp_pid=`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`
113 cnt=`expr $cnt + 1`
114 sleep 1
115 done
117 if [ ! -z "${temp_pid}" ]; then
118 eval kill -KILL ${pid}
119 warn "'${_vkernel}' had to be forcefully killed."
121 done
125 load_rc_config $name
126 run_rc_command "$1"