Manuel Amador (Rudd-O) 05c020e1f6 Source code committed
2010-08-11 09:13:29 -07:00

141 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
#
# vmops Script to start and stop VMOps console proxy in domR/domP.
#
# Author: Chiradeep Vittal <chiradeep@vmops.com>
# chkconfig: 2345 99 01
# description: Start up the VMOps agent
#
# This file exists in /etc/init.d/ in the domR/DomP
# with a software link /etc/rc.d/rc3.d/S99vmops pointed to it
#
# @VERSION@
if [ -f /mnt/cmdline ]
then
CMDLINE=$(cat /mnt/cmdline)
else
CMDLINE=$(cat /proc/cmdline)
fi
TEMPLATE="domR"
for i in $CMDLINE
do
# search for foo=bar pattern and cut out foo
FIRSTPATTERN=$(echo $i | cut -d= -f1)
case $FIRSTPATTERN in
template)
TEMPLATE=$(echo $i | cut -d= -f2)
;;
esac
done
# Source function library.
if [ -f /etc/init.d/functions ]
then
. /etc/init.d/functions
fi
_success() {
if [ -f /etc/init.d/functions ]
then
success
else
echo "Success"
fi
}
_failure() {
if [ -f /etc/init.d/functions ]
then
failure
else
echo "Failed"
fi
}
RETVAL=$?
VMOPS_HOME="/usr/local/vmops"
# mkdir -p /var/log/vmops
get_pids() {
local i
for i in $(ps -ef| grep java | grep -v grep | awk '{print $2}');
do
echo $(pwdx $i) | grep "$VMOPS_HOME" | grep -i console | awk -F: '{print $1}';
done
}
start() {
if [ "$TEMPLATE" == "domP" ];
then
local pid=$(get_pids)
echo -n "Starting VMOps Console Proxy: "
if [ -f $VMOPS_HOME/consoleproxy/run.sh ];
then
if [ "$pid" == "" ]
then
if [ ! -d /var/log/vmops ]
then
mkdir -p /var/log/vmops
fi
if [ ! -f /var/log/vmops/vmops.out ]
then
touch /var/log/vmops/vmops.out
fi
(cd $VMOPS_HOME/consoleproxy; nohup ./run.sh > /var/log/vmops/vmops.out 2>&1 & )
pid=$(get_pids)
echo $pid > /var/run/vmops.pid
fi
_success
else
_failure
fi
echo
fi
}
stop() {
if [ "$TEMPLATE" == "domP" ];
then
local pid
echo -n "Stopping VMOps agent: "
for pid in $(get_pids)
do
kill $pid
done
_success
echo
fi
}
status() {
if [ "$TEMPLATE" == "domP" ];
then
local pids=$(get_pids)
if [ "$pids" == "" ]
then
echo "VMOps agent is not running"
return 1
fi
echo "VMOps agent is running: process id: $pids"
fi
return 0
}
case "$1" in
start) start
;;
stop) stop
;;
status) status
;;
restart) stop
start
;;
*) echo $"Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL