1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-08 20:58:17 +03:00

feature #1678: New stop_probes action in the IM driver

This commit is contained in:
Jaime Melis 2013-10-24 16:33:51 +02:00
parent f98a2daee9
commit f7aa3c503d
4 changed files with 116 additions and 11 deletions

View File

@ -881,7 +881,8 @@ VMM_EXEC_EC2_SCRIPTS="src/vmm_mad/remotes/ec2/cancel \
# Information Manager Probes, to be installed under $REMOTES_LOCATION/im
#-------------------------------------------------------------------------------
IM_PROBES_FILES="src/im_mad/remotes/run_probes"
IM_PROBES_FILES="src/im_mad/remotes/run_probes \
src/im_mad/remotes/stop_probes"
IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/collectd-client_control.sh \
src/im_mad/remotes/kvm.d/collectd-client.rb"

View File

@ -49,6 +49,7 @@ class InformationManagerDriver < OpenNebulaDriver
# register actions
register_action(:MONITOR, method("action_monitor"))
register_action(:STOPMONITOR, method("stop_monitor"))
# collectd port
@collectd_port = 4124
@ -84,6 +85,11 @@ class InformationManagerDriver < OpenNebulaDriver
do_action("#{@hypervisor} #{ds_location} #{@collectd_port}", number, host,
:MONITOR, :script_name => 'run_probes', :base64 => true)
end
def stop_monitor(number, host)
do_action("#{@hypervisor}", number, host,
:STOPMONITOR, :script_name => 'stop_probes', :base64 => true)
end
end

View File

@ -16,8 +16,23 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
#--------------------------------------------------------------------------- #
# Process Arguments
#--------------------------------------------------------------------------- #
ACTION="start"
if [ "$1" = "stop" ]; then
shift
ACTION="stop"
fi
ARGV=$*
#--------------------------------------------------------------------------- #
#--------------------------------------------------------------------------- #
# Directory that contains this file
DIR=$(pwd)
@ -35,17 +50,30 @@ function start_client() {
nohup /usr/bin/env ruby $CLIENT $ARGV >/dev/null 2>&1 &
}
function stop_client() {
PID=$(get_pid)
kill $PID
}
function remove_pid_file() {
rm -f $CLIENT_PID_FILE
}
# Write the PID
function write_pid() {
echo $1 > $CLIENT_PID_FILE
}
function get_pid() {
cat $CLIENT_PID_FILE
}
# Check if running process
function check_running() {
# Assume the process is not running if there is no pid file
test ! -f $CLIENT_PID_FILE && return 1
PID=$(cat $CLIENT_PID_FILE)
PID=$(get_pid)
if ps --no-headers -o command $PID 2>/dev/null | grep -q $BASENAME; then
return 0
@ -56,14 +84,29 @@ function check_running() {
fi
}
if ! check_running; then
start_client
write_pid $!
fi
# This script returns the run_probes execution
HYPERVISOR=$1
shift
set $HYPERVISOR-probes $@
case $ACTION in
start)
if ! check_running; then
start_client
write_pid $!
fi
# This script returns the run_probes execution
HYPERVISOR=$1
shift
set $HYPERVISOR-probes $@
$DIR/../run_probes $@
;;
stop)
if check_running; then
stop_client
remove_pid_file
fi
;;
esac
$DIR/../run_probes $@

55
src/im_mad/remotes/stop_probes Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
#Arguments: hypervisor(0)
source $(dirname $0)/../scripts_common.sh
export LANG=C
HYPERVISOR_DIR=$1.d
ARGUMENTS=$*
SCRIPTS_DIR=`dirname $0`
cd $SCRIPTS_DIR
function run_dir {
(
cd $1
for i in `ls *_control.sh`;do
if [ -x "$i" ]; then
./$i stop
EXIT_CODE=$?
if [ "x$EXIT_CODE" != "x0" ]; then
error_message "Error executing $i"
exit $EXIT_CODE
fi
fi
done
)
}
if [ -d "$HYPERVISOR_DIR" ]; then
run_dir "$HYPERVISOR_DIR"
fi
EXIT_CODE=$?
if [ "x$EXIT_CODE" != "x0" ]; then
exit $EXIT_CODE
fi