5 # REQUIRE: LOGIN NETWORKING
12 start_cmd
="vkernel_start"
13 stop_cmd
="vkernel_stop"
17 echo -n 'Starting virtual kernels:'
18 for _vkernel
in ${vkernel_list}
20 # Start with a clean set of variables
21 unset pidfile bin memsize rootimgs ifaces logfile flags
22 unset vkuser vkgroup memimg
24 # Configure user to run vkernel
25 eval vkuser
=\"\
${vkernel_${_vkernel}_user}\"
26 if [ -z "${vkuser}" ]; then
30 vkgroup
=$
(id
-ng ${vkuser})
33 # Check if already running
34 eval pidfile
="/var/run/vkernel.${_vkernel}.pid"
35 if [ -f "${pidfile}" ]; then
36 eval pid
=`cat ${pidfile}`
37 if [ ! -z "${pid}" -a ! -z "`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`" ]; then
39 warn
"vkernel ${_vkernel} already running? (check ${pidfile})"
43 # Regular users do not have write access in /var/run
44 install -c -o ${vkuser} -g ${vkgroup} /dev/null ${pidfile}
47 # Configure vkernel binary
48 eval _bin
=\"\
${vkernel_${_vkernel}_bin}\"
49 if [ -z "${_bin}" -o ! -x "${_bin}" ]; then
50 eval _bin
=\"\
${vkernel_bin}\"
51 if [ -z "${_bin}" -o ! -x "${_bin}" ]; then
53 warn
"Missing or undefined binary for vkernel '${_vkernel}'. Skipping."
59 # Configure vkernel memory
60 eval _memsize
=\"\
$vkernel_${_vkernel}_memsize
\"
61 if [ -z "${_memsize}" ]; then
63 warn
"No memsize has been defined for vkernel '${_vkernel}'. Skipping."
66 memsize
="-m ${_memsize}"
69 # Configure vkernel memory image file
70 eval _memimg
=\"\
${vkernel_${_vkernel}_memimg}\"
71 if [ -z "${_memimg}" ]; then
72 mkdir
-m 1777 -p /var
/vkernel
74 for n
in $
(seq 0 999999)
76 eval _memf
=$
(printf "/var/vkernel/memimg.%06s" ${n})
77 if [ ! -f "${_memf}" ]
82 if lockf
-kst 0 ${_memf} echo >/dev
/null
84 # Test if memimg is writable by vkuser
85 su
- ${vkuser} -c "test -w ${_memf}"
95 memimg
="-i ${_memimg}"
98 # Configure vkernel root image(s)
99 eval _rootimgs
=\"\
${vkernel_${_vkernel}_rootimg_list}\"
100 if [ -z "${_rootimgs}" ]; then
102 warn
"No root image has been defined for vkernel '${_vkernel}'."
104 for _rootimg
in ${_rootimgs}
106 eval rootimgs
=\"${rootimgs} -r ${_rootimg}\"
110 # Configure optional vkernel network interface(s)
111 eval _ifaces
=\"\
${vkernel_${_vkernel}_iface_list}\"
112 if [ -n "${_ifaces}" ]; then
113 for _iface
in ${_ifaces}
115 eval ifaces
=\"${ifaces} -I ${_iface}\"
119 # Configure optional console logfile
120 eval logfile
=\"\
${vkernel_${_vkernel}_logfile}\"
121 [ -z "${logfile}" ] && logfile
="/dev/null"
123 # Configure optional flags
124 eval flags
=\"\
${vkernel_${_vkernel}_flags}\"
126 eval "daemon -u ${vkuser} ${bin} ${memsize} ${rootimgs} " \
127 "${memimg} ${ifaces} ${flags} -p ${pidfile}" \
128 ">>${logfile} 2>&1 </dev/null"
129 echo -n " ${_vkernel}"
136 for _vkernel
in ${vkernel_list}
138 eval pidfile
="/var/run/vkernel.${_vkernel}.pid"
139 if [ -f "${pidfile}" ]; then
140 eval pid
=`cat ${pidfile}`
142 if [ -z "${pid}" ]; then
143 warn
"vkernel '${_vkernel}' not running?"
146 eval kill -TERM ${pid}
148 eval _kill_timeout
=\"\
${vkernel_${_vkernel}_kill_timeout}\"
149 if [ -z "${_kill_timeout}" ]; then
150 eval _kill_timeout
=\"\
${vkernel_kill_timeout}\"
151 if [ -z "${_kill_timeout}" ]; then
156 # Check that the vkernel ended properly
158 eval temp_pid
=`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`
159 while [ ! -z "${temp_pid}" -a "${cnt}" -lt "${_kill_timeout}" ]; do
160 eval temp_pid
=`ps axwwp ${pid} | grep -wE "^[ ]*${pid}" | grep -v grep | awk '{print $1}'`
165 if [ ! -z "${temp_pid}" ]; then
166 eval kill -KILL ${pid}
167 warn
"'${_vkernel}' had to be forcefully killed."