Fix a typo in the vkernel rc script.
[dragonfly.git] / etc / rc.d / vkernel
CommitLineData
2feb07f7
SW
1#!/bin/sh
2#
3
4# PROVIDE: vkernel
5# REQUIRE: LOGIN NETWORKING
6
7. /etc/rc.subr
8
9name="vkernel"
10rcvar=`set_rcvar`
11start_cmd="vkernel_start"
12stop_cmd="vkernel_stop"
13
14vkernel_start()
15{
16 echo -n 'Starting virtual kernels:'
17 for _vkernel in ${vkernel_list}
18 do
19 # Check if already running
20 eval pidfile="/var/run/vkernel.${_vkernel}.pid"
db511d28
R
21 if [ -f "${pidfile}" ]; then
22 eval pid=`cat ${pidfile}`
178edca6 23 if [ ! -z "${pid}" -a ! -z "`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`" ]; then
db511d28
R
24 echo
25 warn "Vkernel ${_vkernel} already running? (check ${pidfile})"
26 continue
27 fi
2feb07f7
SW
28 fi
29
30 # Configure vkernel binary
31 eval _bin=\"\${vkernel_${_vkernel}_bin}\"
32 if [ -z "${_bin}" -o ! -x "${_bin}" ]; then
2214b591
R
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
38 fi
2feb07f7 39 fi
2214b591 40 bin=${_bin}
2feb07f7
SW
41
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}"
50 fi
51
52 # Configure vkernel root image(s)
53 eval _rootimgs=\"\${vkernel_${_vkernel}_rootimg_list}\"
54 if [ -z "${_rootimgs}" ]; then
55 echo
2214b591 56 warn "No root image has been defined for vkernel '${_vkernel}'."
2feb07f7
SW
57 else
58 for _rootimg in ${_rootimgs}
59 do
60 eval rootimgs=\"${rootimgs} -r ${_rootimg}\"
61 done
62 fi
63
64 # Configure optional vkernel network interface(s)
65 eval _ifaces=\"\${vkernel_${_vkernel}_iface_list}\"
66 if [ -n "${_ifaces}" ]; then
67 for _iface in ${_ifaces}
68 do
69 eval ifaces=\"${ifaces} -I ${_iface}\"
70 done
71 fi
72
73 # Configure optional console logfile
74 eval logfile=\"\${vkernel_${_vkernel}_logfile}\"
75 [ -z "${logfile}" ] && logfile="/dev/null"
76
77 # Configure optional flags
78 eval flags=\"\${vkernel_${_vkernel}_flags}\"
79
7c53feed 80 eval "daemon ${bin} ${memsize} ${rootimgs} ${ifaces} ${flags} -p ${pidfile} >>${logfile} 2>&1 </dev/null"
2feb07f7
SW
81 echo -n " ${_vkernel}"
82 done
83 echo '.'
84}
85
86vkernel_stop()
87{
88 for _vkernel in ${vkernel_list}
89 do
90 eval pidfile="/var/run/vkernel.${_vkernel}.pid"
91 if [ -f "${pidfile}" ]; then
92 eval pid=`cat ${pidfile}`
2feb07f7
SW
93 fi
94 if [ -z "${pid}" ]; then
95 warn "vkernel '${_vkernel}' not running?"
7c53feed
R
96 continue
97 fi
98 eval kill -TERM ${pid}
99
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
105 fi
106 fi
107
108 # Check that the vkernel ended properly
109 cnt=1
178edca6 110 eval temp_pid=`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`
7c53feed 111 while [ ! -z "${temp_pid}" -a "${cnt}" -lt "${_kill_timeout}" ]; do
178edca6 112 eval temp_pid=`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`
7c53feed
R
113 cnt=`expr $cnt + 1`
114 sleep 1
115 done
116
117 if [ ! -z "${temp_pid}" ]; then
118 eval kill -KILL ${pid}
119 warn "'${_vkernel}' had to be forcefully killed."
2feb07f7
SW
120 fi
121 done
122}
123
124
125load_rc_config $name
126run_rc_command "$1"