#!/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/response/599

#!/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"

받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/598

#!/bin/sh

CURRENT_DIR=$(pwd)

make_default_config() {
  echo "daemonize no" >> $REDIS_DIR/redis.conf
  echo "pidfile /var/run/redis.pid" >> $REDIS_DIR/redis.conf
  echo "tcp-backlog 511" >> $REDIS_DIR/redis.conf
  echo "port 6379" >> $REDIS_DIR/redis.conf
  echo "timeout 0" >> $REDIS_DIR/redis.conf
  echo "tcp-keepalive 0" >> $REDIS_DIR/redis.conf
  echo "loglevel notice" >> $REDIS_DIR/redis.conf
  if [[ -z "$AG_HOME" ]]; then
    echo "logfile \"$HOME/ag/logs/redis.log\"" >> $REDIS_DIR/redis.conf
  else
    echo "logfile \"$AG_HOME/logs/redis.log\"" >> $REDIS_DIR/redis.conf
  fi
  echo "databases 16" >> $REDIS_DIR/redis.conf
  echo "save 900 1" >> $REDIS_DIR/redis.conf
  echo "save 300 10" >> $REDIS_DIR/redis.conf
  echo "save 60 10000" >> $REDIS_DIR/redis.conf
  echo "stop-writes-on-bgsave-error yes" >> $REDIS_DIR/redis.conf
  echo "rdbcompression yes" >> $REDIS_DIR/redis.conf
  echo "rdbchecksum yes" >> $REDIS_DIR/redis.conf
  echo "dbfilename \"dump.rdb\"" >> $REDIS_DIR/redis.conf
  if [[ -z "$REDIS_HOME" ]]; then
    echo "dir \"$HOME/ag/redis\"" >> $REDIS_DIR/redis.conf
  else
    echo "dir \"$REDIS_HOME\"" >> $REDIS_DIR/redis.conf
  fi
  echo "slave-serve-stale-data yes" >> $REDIS_DIR/redis.conf
  echo "slave-read-only yes" >> $REDIS_DIR/redis.conf
  echo "repl-disable-tcp-nodelay no" >> $REDIS_DIR/redis.conf
  echo "slave-priority 100" >> $REDIS_DIR/redis.conf
  echo "appendonly yes" >> $REDIS_DIR/redis.conf
  echo "appendfilename \"appendonly.aof\"" >> $REDIS_DIR/redis.conf
  echo "appendfsync everysec" >> $REDIS_DIR/redis.conf
  echo "no-appendfsync-on-rewrite no" >> $REDIS_DIR/redis.conf
  echo "auto-aof-rewrite-percentage 100" >> $REDIS_DIR/redis.conf
  echo "auto-aof-rewrite-min-size 64mb" >> $REDIS_DIR/redis.conf
  echo "lua-time-limit 5000" >> $REDIS_DIR/redis.conf
  echo "slowlog-max-len 128" >> $REDIS_DIR/redis.conf
  echo "notify-keyspace-events \"\"" >> $REDIS_DIR/redis.conf
  echo "hash-max-ziplist-entries 512" >> $REDIS_DIR/redis.conf
  echo "hash-max-ziplist-value 64" >> $REDIS_DIR/redis.conf
  echo "list-max-ziplist-entries 512" >> $REDIS_DIR/redis.conf
  echo "list-max-ziplist-value 64" >> $REDIS_DIR/redis.conf
  echo "set-max-intset-entries 512" >> $REDIS_DIR/redis.conf
  echo "zset-max-ziplist-entries 128" >> $REDIS_DIR/redis.conf
  echo "zset-max-ziplist-value 64" >> $REDIS_DIR/redis.conf
  echo "hll-sparse-max-bytes 3000" >> $REDIS_DIR/redis.conf
  echo "activerehashing yes" >> $REDIS_DIR/redis.conf
  echo "client-output-buffer-limit normal 0 0 0" >> $REDIS_DIR/redis.conf
  echo "client-output-buffer-limit slave 256mb 64mb 60" >> $REDIS_DIR/redis.conf
  echo "client-output-buffer-limit pubsub 32mb 8mb 60" >> $REDIS_DIR/redis.conf
  echo "hz 10" >> $REDIS_DIR/redis.conf
  echo "aof-rewrite-incremental-fsync yes" >> $REDIS_DIR/redis.conf
  echo "maxclients 8160" >> $REDIS_DIR/redis.conf
}

DOWN_BASE_URL="http://download.redis.io/releases/"
BASE_PREFIX="redis-"
BASE_SUFFIX=".tar.gz"

# Check Input Parameters
while getopts "l:v:" o;
do
  case "${o}" in
  l)
    LOCATE=${OPTARG}
    ;;
  v)
    VERSION=${OPTARG}
    ;;
  *)
    echo "Invalid Parameter."
    exit 1
    ;;
  \?)
    echo "Invalid Parameter."
    exit 1
    ;;
  esac
done

echo "Step 1 : Check redis server source package....."
  sleep 1
 
  if [[ -z "$LOCATE" ]]; then
    LOCATE="local"
  fi
 
  if [[ -z "$VERSION" ]]; then
    VERSION="2.8.12"
  fi
 
  if [[ "$LOCATE" == "remote" ]]; then
    wget $DOWN_BASE_URL$BASE_PREFIX$VERSION$BASE_SUFFIX
  else
    cd $CURRENT_DIR
    if [ -f "$BASE_PREFIX$VERSION$BASE_SUFFIX" ]; then
      echo "  $BASE_PREFIX$VERSION$BASE_SUFFIX exists in current directory."
    else
      echo "  $BASE_PREFIX$VERSION$BASE_SUFFIX does not exist in current directory."
      exit 1
    fi
  fi
 
echo "  done"
sleep 1

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

REDIS_DIR=$CURRENT_DIR/$BASE_PREFIX$VERSION

echo "Step 3 : Default redis configuration file create...."
  sleep 1
  mv $REDIS_DIR/redis.conf $REDIS_DIR/redis.conf.bak
  touch $REDIS_DIR/redis.conf
  make_default_config
echo "  done"
sleep 1

echo "Step 4 : Repackage the redis server source...."
  sleep 1
  cd $CURRENT_DIR
  mv $BASE_PREFIX$VERSION redis
  tar -zcvf redis.tar.gz redis
  wait $!
  rm -rf redis
echo "  done"

받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/597

<Pre-Environments>
 
  1. AG_HOME = $HOME/ag
  2. REDIS_HOME = $AG_HOME/redis
  3. Default Redis Configuration File : REDIS_CONF=$AG_HOME/conf/redis.conf
  4. IVP ML HOST : AG_ML_HOST=10.xxx.xxx.xxx:8080
<Redis Build>
Build Shell Script : sl_build.sh
 
  1. Redis Latest Package Download : http://download.redis.io/redis-stable.tar.gz
    wget http://download.redis.io/redis-stable.tar.gz
  2. 압축 해제 : tar -zxvf  {download_redis_file.tar.gz}
    tar -zxvf redis-stable.tar.gz
  3. make 설치 확인
    rpm -qa | grep ^make
    yum info make | grep Repo
  4. make 설치 안되었으면 make 설치
    yum install make -y
  5. cd {download_redis_file}
    $(cd redis-stable)
  6. make
  7. Default Redis Configuration File 생성
    touch redis.conf
    echo "...." >> redis.conf
  8. build 결과 tar로 압축
    tar -zcvf redis.tar.gz redis-stable
<Redis Install>
Install Shell Script : sl_install.sh
 
  1. 환경 변수 설정 : .bash_profile
    echo "..." >> .bash_profile
    $(source $HOME/.bash_profile)
  2. build결과 tar.gz 압축 해제
    tar -zxvf redis.tar.gz
  3. $REDIS_HOME으로 압축 해제한 폴더 이동 (폴더 명 : redis)
    mv redis $REDIS_HOME
  4. Default Redis Configuration $REDIS_CONF로 이동
    mv /redis/redis.conf $REDIS_CONF/
  5. Default Configuration으로 Redis 서버 실행 : Check (PID?)
    redis_run / redis_down

<IVP Shell>
IVP Shell Script : sl_ivp.sh
 
  1. Default Configuration으로 Redis 서버 실행 : Check (PID?)
    redis_run / redis_down
  2. Redis 서버 기동 후 Health Check : Check
    RES=$($REDIS_HOME/src/redis-cli -p {port} ping)
  3. Redis 서버 Default Configuration Display : Check
    RES=$($REDIS_HOME/src/redis-cli -p {port} info)
  4. 모두 Pass일 경우, ML에 ivp 정보 전송
    curl -x POST ....
<Redis Running>
  1. ./src/redis-server $REDIS_CONF
  2. alias 등록 (in profile or shell = redis_run)
<Redis LOG>
  • Default Log Path=$AG_HOME/logs/redis.log => Default Configuration에 추가
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/596

org.apache.commons.vfs2.impl.DefaultFileMonitor
http://docs.oracle.com/javase/tutorial/essential/io/notification.html
http://www.java2s.com/Code/Java/File-Input-Output/MonitoringaFileforchanges.htm
http://howtodoinjava.com/2012/10/10/auto-reload-of-configuration-when-any-change-happen/
http://tunatore.wordpress.com/2011/05/13/how-to-detect-file-change-using-java-filechangeevent/
http://www.javaspecialists.eu/archive/Issue095.html <===

서비스를 운영하는 중에 설정을 변경하여 실시간으로 반영해야 하는 요건이 종종 발생한다.
이 때 처리할 수 있는 방법은 크게 2가지가 있다.

하나는 파일 변경에 대한 OS레벨의 시스템 이벤트를 Triggering할 수 있도록 프로그래밍하는 것이고, 다른 하나는 일정 주기로 해당 File을 Polling하여 변경 여부를 판별하여 설정에 반영하는 것이다.

시스템에서 파일 변경 이벤트를 받을 수 있다면, 첫번째 방법이 가장 확실하다.
하지만,  Java  환경에서는 Timer나 Task를 이용하여 데몬으로 동작하는 프로그램을 작성하여 파일 변경을 감시하거나, 일정 주기로  Thread에서 파일 변경을 감시하는 것이 대부분이다.

대표적으로 Apache의 VFS나 commons-configuration이 이에 해당한다.

OS별로 파일 변경에 대한 시스템 이벤트를 Triggering할 수 있는 방안은 없을까?
다음 버전의 JDK에는 반영이 되었으면 좋겠다.
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/594