Sample - RabbitMQ
This is example tehcnical microservice which is covering RabbitMQ. It is defined only for linux machines. File structure is shown below:
+--+ rabbitmq
|
+--+ linux
| |
| +--- configuration.yml
| |
| +--+ bin
| | |
| | +--- env
| | |
| | +--- getpid.sh
| | |
| | +--- start.sh
| | |
| | +--- stop.sh
| |
| +--- [...] (other rabbitmq files)
Now look at the configuraiton file:
CONFIGURATION:
BASE:
name: rabbitmq
type: default
readStreamsWaitTimeInMillis: 5000
OPERATIONS:
start: 'bin/start.sh'
stop: 'bin/stop.sh'
getPid: 'bin/getpid.sh'
PARAMETERS:
waitAfterStopOperationTime: 6000
version: '1.0'
PROPERTIES:
platformVersion: '1.6.0.0'
isCritical: true
startupOrder: 2
isStartOnMainServerInitialize: true
As you can see three operations are defined: start
, stop
and getPid
. Lets see inside them:
env
This is configuration file shared for all scripts.
#!/bin/bash
workDir=`dirname $1`
cd ${workDir} && cd ../
prefix="`pwd`"
rabbitmqServer=${prefix}/sbin/rabbitmq-server
rabbitmqCtl=${prefix}/sbin/rabbitmqctl
rabbitmqConf=${prefix}/etc/rabbitmq/rabbitmq.config
rabbitmqAdvConf=${prefix}/etc/rabbitmq/advanced.config
export RABBITMQ_PID_FILE=${prefix}/logs/rabbitmq.pid
RABBITMQ_LOG_BASE="../../../logs/technical/rabbitmq"
start.sh
This script runs rabbit with proper configuration file.
#!/bin/bash
envDir=`dirname $0`
source ${envDir}/env "$0"
RABBITMQ_PID_FILE_DIR=`dirname RABBITMQ_PID_FILE`
[ ! -x ${RABBITMQ_LOG_BASE} ] && mkdir -p ${RABBITMQ_LOG_BASE}
[ ! -x ${RABBITMQ_PID_FILE_DIR} ] && mkdir -p ${RABBITMQ_PID_FILE_DIR}
nohup ${rabbitmqServer} >> "$RABBITMQ_LOG_BASE/startup_log" 2>> "$RABBITMQ_LOG_BASE/startup_err" &
${rabbitmqCtl} wait ${RABBITMQ_PID_FILE} >>"$RABBITMQ_LOG_BASE/control_log" 2>&1
retVal=$?
if [ ${retVal} -eq 0 ]
then
echo "Succeeded"
else
echo "Failed(${retVal})"
fi
stop.sh
This script shutdowns rabbit.
#!/bin/bash
envDir=`dirname $0`
source ${envDir}/env "$0"
${rabbitmqCtl} stop
retVal=$?
if [ ${retVal} -eq 0 ]
then
echo "Succeeded"
rm -f ${RABBITMQ_PID_FILE}
else
echo "Failed(${retVal})"
fi
exit ${retVal}
getpid.sh
This script returns PID for monitoring rabbit process.
#!/bin/bash
envDir=`dirname $0`
source ${envDir}/env "$0"
if [ -f ${RABBITMQ_PID_FILE} ]
then
cat ${RABBITMQ_PID_FILE}
else
echo "none"
fi