From 63e515e7617f349acc5a8887e4db6a84f38ab582 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 4 Jun 2020 20:19:51 +0200 Subject: [PATCH] M #-:vCenter monitor service start --- src/im_mad/im_exec/one_im_sh | 41 +++++++++++++++++-- src/im_mad/remotes/lib/vcenter_monitor.rb | 19 --------- .../vcenter.d/monitord-client_control.sh | 23 ----------- 3 files changed, 37 insertions(+), 46 deletions(-) diff --git a/src/im_mad/im_exec/one_im_sh b/src/im_mad/im_exec/one_im_sh index 05ac1d11e9..148c642217 100755 --- a/src/im_mad/im_exec/one_im_sh +++ b/src/im_mad/im_exec/one_im_sh @@ -18,15 +18,48 @@ if [ -z "${ONE_LOCATION}" ]; then MAD_LOCATION=/usr/lib/one/mads + VAR_LOCATION=/var/lib/one else MAD_LOCATION=$ONE_LOCATION/lib/mads + VAR_LOCATION=$ONE_LOCATION/var fi export DRIVER_NAME="one_im_sh_${BASH_ARGV##* }" -# Explicitly execute the vCenter monitor driver in the background -# This way we don't have to wait until OpenNebula -# issues the add_hosts commands to know about missing hosts -#(/usr/bin/env ruby $VAR_LOCATION/remotes/im/lib/vcenter_monitor.rb &) +#------------------------------------------------------------------------------- +# vCenter Monitor Service startup routine +#------------------------------------------------------------------------------- +# Explicitly execute the vCenter monitor driver initialization and run it in the +# background. This way we don't have to wait until OpenNebula issues the +# add_hosts commands to know about missing hosts +#------------------------------------------------------------------------------- +if [ "${BASH_ARGV##* }" = "vcenter" ]; then + + FIFO_PATH="/tmp/vcenter_monitor.fifo" + VMON_PATH="$VAR_LOCATION/remotes/im/lib/vcenter_monitor.rb" + + # Sanitize previous instances + VMON_PIDS=$(ps axuww | grep "ruby $VMON_PATH" | grep -v grep | awk '{print $2}') + + if [ -n "$VMON_PIDS" ]; then + kill $VMON_PIDS + fi + + # Create server FIFO + rm -f $FIFO_PATH > /dev/null 2>&1 + mkfifo $FIFO_PATH + + # Start & check vcenter monitor service + /usr/bin/env ruby $VMON_PATH /dev/null & + + sleep 3 + + VMON_PIDS=$(ps axuww | grep "ruby $VMON_PATH" | grep -v grep | awk '{print $2}') + + if [ -z "$VMON_PIDS" ]; then + echo "Cannot start vcenter_monitor service" + exit 1 + fi +fi exec $MAD_LOCATION/one_im_exec -l $* diff --git a/src/im_mad/remotes/lib/vcenter_monitor.rb b/src/im_mad/remotes/lib/vcenter_monitor.rb index bf90241b4d..72af337d87 100644 --- a/src/im_mad/remotes/lib/vcenter_monitor.rb +++ b/src/im_mad/remotes/lib/vcenter_monitor.rb @@ -71,9 +71,6 @@ class VcenterMonitorManager # #--------------------------------------------------------------------------- def initialize - # Sanitize previous instances - kill_other_instances - @clusters = ClusterSet.new @clusters.bootstrap @@ -85,17 +82,6 @@ class VcenterMonitorManager Thread.new { timer } end - # Kills previous monitor instances - def kill_other_instances - path = File.expand_path(__FILE__) - ps_str = "ps auxwww|grep \"ruby #{path}\"|grep -v grep|awk {'print $2'}" - ids = `#{ps_str}` - return if ids.nil? - - ids = ids.split("\n").map{|pid| pid.to_i} - ids.each{ |pid| Process.kill('KILL', pid) if pid!=Process.pid } - end - #--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- @@ -176,11 +162,6 @@ class IOThread end -Thread.new do - exit unless system('pgrep oned') - sleep 5 -end - vcentermm = VcenterMonitorManager.new io = IOThread.new(vcentermm) diff --git a/src/im_mad/remotes/vcenter.d/monitord-client_control.sh b/src/im_mad/remotes/vcenter.d/monitord-client_control.sh index d43e280b14..2fe82e60ac 100755 --- a/src/im_mad/remotes/vcenter.d/monitord-client_control.sh +++ b/src/im_mad/remotes/vcenter.d/monitord-client_control.sh @@ -26,29 +26,6 @@ else LOG=$ONE_LOCATION/var/vcenter_monitor.log fi -#------------------------------------------------------------------------------- -# Check if vcenter_monitor is running -#------------------------------------------------------------------------------- -if [ ! -p $IO_FIFO_PATH ]; then - rm -f $IO_FIFO_PATH > /dev/null 2>&1 - mkfifo $IO_FIFO_PATH -fi - -pid=`ps auxx | grep vcenter_monitor.rb | grep -v grep | awk '{print $2}'` - -if [ -z $pid ]; then - ruby $BIN > $LOG 2>&1 & - - sleep 3 - - pid=`ps auxx | grep vcenter_monitor.rb | grep -v grep | awk '{print $2}'` - - if [ -z $pid ]; then - echo "Cannot start vcenter_monitor service: `cat $LOG`" - exit 1 - fi -fi - #------------------------------------------------------------------------------- # Process Arguments #-------------------------------------------------------------------------------