[Shell Script in CentOS] Redis Auto Build :: 2014/07/08 15:46

#!/bin/sh

CURRENT_DIR=$(pwd)

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"
}

client_run_shutdown() {
  local down_result=$($REDIS_CLIENT_RUN shutdown)
  echo "$down_result"
}

echo "Step 1 : Check and setting install environments...."
  sleep 1
  env_set
echo "  done"
sleep 1

echo "Step 2 : Unpackage the redis server source....."
  sleep 1
  if [[ -f "redis.tar.gz" ]]; then
    tar -zxvf redis.tar.gz
    wait $!
  else
    echo "  Error. redis.tar.gz does not exist."
    exit 1
  fi
 
echo "  done"
sleep 1

echo "Step 3 : Check the installed make exists or not...."
  sleep 1
  MAKE_CHK_ONE=$(rpm -qa | grep ^make)
  MAKE_CHK_TWO=$(yum info make | grep Repo)
  if [[ -z "$MAKE_CHK_ONE" ]]; then
    if [[ -z "$MAKE_CHK_TWO" ]]; then
      echo "  There is not any installed make."
      echo "  Now, installing the make....."
      yum install make -y
      wait $!
      echo "  done"
    fi
  else
    echo "  make is already installed."
  fi
sleep 1

echo "Step 4 : Build the redis server...."
  sleep 1
 
  if [[ -d "$CURRENT_DIR/redis" ]]; then
    cd $CURRENT_DIR/redis
    make
    wait $!
  else
    echo "  Error. $CURRENT_DIR/redis folder does not exist."
    exit 1
  fi
 
  echo "  done"
sleep 2

echo "Step 5 : Setting redis server to REDIS_HOME...."
  sleep 1
  cd $CURRENT_DIR
  source ~/.bash_profile
  sleep 1
 
  if [[ -d "redis" ]]; then
    if [[ -d "$AG_HOME" ]]; then
   
      if [[ -d "$AG_HOME/redis" ]]; then
        rm -rf $AG_HOME/redis
      fi
     
      mv redis $AG_HOME/redis
      chmod 777 -R $AG_HOME/redis/
     
      if [[ -f "$REDIS_HOME/redis.conf" ]]; then
        mv $REDIS_HOME/redis.conf $REDIS_CONF_PATH
      else
        echo "  Error. $REDIS_HOME/redis.conf file does not exist."
        exit 1
      fi
    else
      echo "  Error. $AG_HOME folder does not exist."
      exit 1
    fi
  else
    echo "  Error. redis folder does not exist."
    exit 1
  fi
 
echo "  done"

2014/07/08 15:46 2014/07/08 15:46
Trackback Address :: http://www.yongbi.net/trackback/598
[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다
Name
Password
Homepage

Secret
< PREV |  1  |  ...  197  |  198  |  199  |  200  |  201  |  202  |  203  |  204  |  205  |  ...  566  |  NEXT >