Sample - Redis
This is example tehcnical microservice which is covering Redis. It is defined only for linux machines. File structure is shown below:
+--+ redis
|
+--+ linux
| |
| +--- configuration.yml
| |
| +--+ bin
| | |
| | +--- env
| | |
| | +--- getpid.sh
| | |
| | +--- start.sh
| | |
| | +--- stop.sh
| |
| +--- [...] (other redis files)
Now look at the configuraiton file:
CONFIGURATION:
BASE:
name: redis
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: 1
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`"
redisServer=${prefix}/src/redis-server
redisCli=${prefix}/src/redis-cli
redisConf=${prefix}/redis.conf
redisPid=${prefix}/logs/redis.pid # NOTICE that the same path to pidfile should be set in redis.conf
start.sh
This script runs redis with proper configuration file.
#!/bin/bash
envDir=`dirname $0`
source ${envDir}/env "$0"
redisPidDir=`dirname ${redisPid}`
[ ! -x ${redisPidDir} ] && mkdir -p ${redisPidDir}
${redisServer} ${redisConf}
stop.sh
This script shutdowns redis.
#!/bin/bash
envDir=`dirname $0`
source ${envDir}/env "$0"
${redisCli} shutdown
getpid.sh
This script returns PID for monitoring redis process.
#!/bin/bash
envDir=`dirname $0`
source ${envDir}/env "$0"
if [ -f ${redisPid} ]
then
cat ${redisPid}
else
echo "none"
fi