#!/bin/sh
read_profile() {
local value=$(cat ~/.bash_profile)
echo "$value"
}
chk_profile() {
local profile_value=$(read_profile)
chk_value="$1"
local chk_result=0
if echo "$profile_value" | grep -q "$1"; then
# Check Value exists in Bash Profile
chk_result=1
else
# Check Value does not exist in Bash Profile
chk_result=0
fi
echo "$chk_result"
}
env_set() {
# AG_HOME
if [ ! -d "$HOME/ag" ]; then
mkdir $HOME/ag
fi
local chk_ag__home_result=$(chk_profile "AG_HOME")
if [[ "$chk_ag__home_result" != "1" ]]; then
echo "export AG_HOME=$HOME/ag" >> ~/.bash_profile
fi
AG_HOME_SHELL=$HOME/ag
# REDIS_HOME
local chk_redis_home_result=$(chk_profile "REDIS_HOME")
if [[ "$chk_redis_home_result" != "1" ]]; then
echo "export REDIS_HOME=\$AG_HOME/redis" >> ~/.bash_profile
fi
# Redis configuration file location
if [ ! -d "$AG_HOME_SHELL/conf" ]; then
mkdir $AG_HOME_SHELL/conf
fi
local chk_redis_conf_path_result=$(chk_profile "REDIS_CONF_PATH")
if [[ "$chk_redis_conf_path_result" != "1" ]]; then
echo "export REDIS_CONF_PATH=\$AG_HOME/conf/redis.conf" >> ~/.bash_profile
fi
# Redis log file location
if [ ! -d "$AG_HOME_SHELL/logs" ]; then
mkdir $AG_HOME_SHELL/logs
fi
local chk_redis_log_path_result=$(chk_profile "REDIS_LOG_PATH")
if [[ "$chk_redis_log_path_result" != "1" ]]; then
echo "export REDIS_LOG_PATH=\$AG_HOME/logs/redis.log" >> ~/.bash_profile
fi
# Redis Server Run Path
local chk_redis_server_run_result=$(chk_profile "REDIS_SERVER_RUN")
if [[ "$chk_redis_server_run_result" != "1" ]]; then
echo "export REDIS_SERVER_RUN=\$REDIS_HOME/src/redis-server" >> ~/.bash_profile
fi
# Redis Client Run Path
local chk_redis_client_run_result=$(chk_profile "REDIS_CLIENT_RUN")
if [[ "$chk_redis_client_run_result" != "1" ]]; then
echo "export REDIS_CLIENT_RUN=\$REDIS_HOME/src/redis-cli" >> ~/.bash_profile
fi
# Management Layer IVP Host : 10.217.37.28, 172.27.139.98
local chk_ag_ml_host_result=$(chk_profile "AG_ML_HOST")
if [[ "$chk_ag_ml_host_result" != "1" ]]; then
echo "export AG_ML_HOST=172.27.139.98:8080" >> ~/.bash_profile
fi
# alias for redis server run
local chk_alias_redis_run=$(chk_profile "redis_run")
if [[ "$chk_alias_redis_run" != "1" ]]; then
echo "alias redis_run='nohup \$REDIS_SERVER_RUN \$REDIS_CONF_PATH >> \$REDIS_LOG_PATH 2>1&'" >> ~/.bash_profile
fi
# alias for redis server shutdown
local chk_alias_redis_shutdown=$(chk_profile "redis_shutdown")
if [[ "$chk_alias_redis_shutdown" != "1" ]]; then
echo "alias redis_shutdown='\$REDIS_CLIENT_RUN shutdown'" >> ~/.bash_profile
fi
# Apply Profile
source ~/.bash_profile
sleep 1
}
server_run() {
local run_result=$(nohup $REDIS_SERVER_RUN $REDIS_CONF_PATH >> $REDIS_LOG_PATH 2>1&)
echo "$run_result"
}
server_run_chk() {
local run_chk=$(ps -ef | grep r[e]dis)
#local run_chk=$(ps -ef | pgrep redis)
echo "$run_chk"
}
server_healthchk() {
local health_result=$($REDIS_CLIENT_RUN ping)
echo "$health_result"
}
# Check input parameters
while getopts "i:p:" o;
do
case "${o}" in
i)
NODE_IP=${OPTARG}
;;
p)
NODE_PORT=${OPTARG}
;;
*)
echo "Invalid parameter."
exit 1
;;
\?)
echo "Invalid parameter."
exit 1
;;
esac
done
echo "Step 1 : Check and setting default environments....."
sleep 1
env_set
echo " done"
sleep 1
# Redis Server Start
echo "Step 2 : Run the redis server....."
sleep 1
source ~/.bash_profile
sleep 1
chk_run_result=$(server_run_chk)
if [[ -z "$chk_run_result" ]]; then
result_run=$(server_run)
if [[ -z "$result_run" ]]; then
echo " Redis server is runned."
else
echo " Error. Redis server cannot run."
echo " " $result_run
exit 1
fi
else
echo " Redis server is alreay running..."
fi
sleep 1
# Redis Server Health Check
echo "Step 3 : Redis server health check......"
sleep 1
source ~/.bash_profile
sleep 1
result_health=$(server_healthchk)
if [[ "$result_health" == "PONG" ]]; then
echo " Redis server health check : " $result_health
else
echo " Error. Redis server health check is failed."
echo " Result health check : " $result_health
exit 1
fi
sleep 1
# IVP Send
echo "Step 4 : IVP send to management layer....."
sleep 1
NODE_NAME=$(hostname -s)
if [[ -z "$NODE_IP" ]]; then
NODE_IP=$(hostname -i)
fi
if [[ -z "$NODE_PORT" ]]; then
NODE_PORT=6379
fi
curl -i -X PUT -H "Content-Type:application/json" http://$AG_ML_HOST/_AG_/sl/nodes/$NODE_IP -d '{"port":"'"$NODE_PORT"'"}'
댓글을 달아 주세요
댓글 RSS 주소 : http://www.yongbi.net/rss/comment/607