rc.d: completely stop the vkernels
authorRumko <rumcic@gmail.com>
Sun, 10 Oct 2010 17:12:33 +0000 (19:12 +0200)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Tue, 12 Oct 2010 21:13:49 +0000 (23:13 +0200)
When stopping the vkernel, after a set timeout if the vkernel is still
alive, send a SIGKILL.
Also redirect STDIN when starting the vkernels.

etc/defaults/rc.conf
etc/rc.d/vkernel

index 683c4c6..52d66c4 100644 (file)
@@ -458,6 +458,7 @@ jail_sysvipc_allow="NO"     # Allow SystemV IPC use from within a jail
 vkernel_enable="NO"    # Set to YES to enable starting of vkernels
 vkernel_list=""                # Space separated list of names of vkernels
 #vkernel_bin="/boot/kernel.VKERNEL"    # Default path to the vkernel binary
+#vkernel_kill_timeout="45"     # Default timeout before a SIGKILL is issued
 
 #
 # Create an entry for each vkernel specified in vkernel_list
@@ -475,6 +476,8 @@ vkernel_list=""             # Space separated list of names of vkernels
        # Optional: path to the console log file
 #vkernel_example_flags="-U"
        # Optional: aditional flags to start the vkernel with
+#vkernel_example_kill_timeout="45"
+       # Optional: timeout before SIGKILL is issued when stopping the vkernel
 
 ##############################################################
 ### Define source_rc_confs, the mechanism used by /etc/rc.* ##
index 35c8a43..3193482 100644 (file)
@@ -74,7 +74,7 @@ vkernel_start()
                # Configure optional flags
                eval flags=\"\${vkernel_${_vkernel}_flags}\"
 
-               eval "daemon ${bin} ${memsize} ${rootimgs} ${ifaces} ${flags} -p ${pidfile} >>${logfile} 2>&1"
+               eval "daemon ${bin} ${memsize} ${rootimgs} ${ifaces} ${flags} -p ${pidfile} >>${logfile} 2>&1 </dev/null"
                echo -n " ${_vkernel}"
        done
        echo '.'
@@ -90,8 +90,30 @@ vkernel_stop()
                fi
                if [ -z "${pid}" ]; then
                        warn "vkernel '${_vkernel}' not running?"
-               else
-                       eval kill -TERM ${pid}
+                       continue
+               fi
+               eval kill -TERM ${pid}
+
+               eval _kill_timeout=\"\${vkernel_${_vkernel}_kill_timeout}\"
+               if [ -z "${_kill_timeout}" ]; then
+                       eval _kill_timeout=\"\${vkernel_kill_timeout}\"
+                       if [ -z "${_kill_timeout}" ]; then
+                               _kill_timeout=60
+                       fi
+               fi
+
+               # Check that the vkernel ended properly
+               cnt=1
+               eval temp_pid=`ps axwwp ${pid} | grep -wE "^[ ]+${pid}" | grep -v grep | awk '{print $1}'`
+               while [ ! -z "${temp_pid}" -a "${cnt}" -lt "${_kill_timeout}" ]; do
+                       eval temp_pid=`ps axwwp ${pid} | grep -wE "^[ ]+${pid}" | grep -v grep | awk '{print $1}'`
+                       cnt=`expr $cnt + 1`
+                       sleep 1
+               done
+
+               if [ ! -z "${temp_pid}" ]; then
+                       eval kill -KILL ${pid}
+                       warn "'${_vkernel}' had to be forcefully killed."
                fi
        done
 }