Last active
August 1, 2016 08:54
-
-
Save okdtsk/9950724 to your computer and use it in GitHub Desktop.
MMS Monitor agent: Modify to be able to launch each Group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(20): > CLUSTER=$2 | |
23: PID_FILE="/var/run/mongodb-mms-monitoring-agent.pid" | PID_FILE="/var/run/mongodb-mms-monitoring-agent-$CLUSTER.pid" | |
24: LOG_FILE="/var/log/mongodb-mms/monitoring-agent.log" | LOG_FILE="/var/log/mongodb-mms/monitoring-agent-$CLUSTER.log" | |
25: CONF_FILE="/etc/mongodb-mms/monitoring-agent.config" | CONF_FILE="/etc/mongodb-mms/monitoring-agent-$CLUSTER.config" | |
107: echo $"Usage: $0 {start|stop|restart|status}" | echo $"Usage: $0 {start|stop|restart|status} CLUSTER_ID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chkconfig: 35 90 10 | |
# description: A script to run the MongoDB MMS Monitoring Agent. | |
# | |
### BEGIN INIT INFO | |
# Provides: mongodb-mms-monitoring-agent | |
# Required-Start: $local_fs $network | |
# Required-Stop: $local_fs $network | |
# Default-Start: 3 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: MongoDB MMS Monitoring Agent | |
# Description: MongoDB MMS Monitoring Agent | |
### END INIT INFO | |
ME=`whoami` | |
SCRIPT_NAME=`basename $0` | |
CLUSTER=$2 | |
APP_NAME="mongodb-mms-monitoring-agent for $CLUSTER" | |
SERVICE_USER="mongodb-mms-agent" | |
PID_FILE="/var/run/mongodb-mms-monitoring-agent-$CLUSTER.pid" | |
LOG_FILE="/var/log/mongodb-mms/monitoring-agent-$CLUSTER.log" | |
CONF_FILE="/etc/mongodb-mms/monitoring-agent-$CLUSTER.config" | |
start() { | |
if is_running; then | |
echo "$APP_NAME is already running" | |
else | |
echo "$APP_NAME is starting" | |
nohup su -s /bin/bash $SERVICE_USER -c "/usr/bin/mongodb-mms-monitoring-agent -conf $CONF_FILE" >> $LOG_FILE 2>&1 & | |
echo $! > $PID_FILE | |
fi | |
} | |
stop() { | |
if is_running; then | |
echo "$APP_NAME is stopping" | |
kill `get_pid` | |
wait_while_running 30 | |
if is_running; then | |
echo "$APP_NAME still not stopped. Trying kill -9" | |
kill -9 `get_pid` | |
wait_while_running 30 | |
if is_running; then | |
echo "$APP_NAME still not stopped. Giving up." | |
exit 1 | |
fi | |
fi | |
else | |
echo "$APP_NAME is NOT running" | |
fi | |
} | |
restart() { | |
stop | |
start | |
} | |
status() { | |
if is_running; then | |
echo "$APP_NAME is running" | |
else | |
echo "$APP_NAME is NOT running" | |
exit 3 | |
fi | |
} | |
get_pid() { | |
if [[ ! -f ${PID_FILE} ]]; then | |
echo "x" | |
else | |
cat ${PID_FILE} | |
fi | |
} | |
is_running() { | |
ps -e -o pid,command | grep "$APP_NAME" | awk '{print $1}' | grep -q "^`get_pid`$" | |
return $? | |
} | |
wait_while_running() { | |
TIMEOUT=$1 | |
COUNTER=0 | |
echo -n "waiting..." | |
while is_running && [ $COUNTER -lt $TIMEOUT ]; do | |
sleep 1 | |
echo -n . | |
let COUNTER=COUNTER+1 | |
done | |
if is_running; then | |
echo | |
else | |
echo " stopped" | |
fi | |
} | |
case "$1" in | |
start|stop|restart|status) | |
$1 | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|status} CLUSTER_ID" | |
exit 2 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment