[MDRM] HP-UX 재부팅시 MDRM Agent 자동 기동 안됨

Step-by-step guide #

HP-UX 재부팅시 MDRM Agent 자동 기동 안됨 #

<원인> #

MDRM Agent 스크립트 일부에 bash 특화된 문법 작성으로 오류 발생

<환경> #

HP-UX 운영체제

MDRM Agent 1.1.1 이하

<해결> #

방법 #1 : MDRM Agent 1.1.2로 업그레이드 #

1. /opt/gam_agent/application.properties 백업

2. MDRM Agent 구버전 제거

3. MDRM Agent 신버전 (1.1.2 이상) 설치

4. /opt/gam_agent/application.properties 복원

방법 #2 : MDRM Agent 스크립트 수정 #

1. /opt/gam_agent/bin/unix_service.sh를 아래 내용으로 변경

#!/bin/sh
###############################
#GAM agent UNIX service handler for start & stop & restart & status
###############################


# HP UX Service is no /usr/bin in path
PATH=$PATH:/usr/sbin:/usr/bin
export PATH

# “home” will be replaced by installer as a path to GAM Agent.
MDRM_HOME=/opt/gam_agent
APP_NAME=gam_agent
JARFILE=”$MDRM_HOME/$APP_NAME.jar”

[ -n “$JARFILE” ] && jarfile=”$JARFILE”
[ -n “$APP_NAME” ] && identity=”$APP_NAME”

# Initialize log file name if not provided by the config file
[ -z “$LOG_FILENAME” ] && LOG_FILENAME=”${identity}.log”

#read gam_agent environment variable
[ -f $MDRM_HOME/gam_agent.conf ] && . $MDRM_HOME/gam_agent.conf
if [ -z “$JAVA_HOME” ]; then
  echoRed “JAVA_HOME not defined, try to read /etc/profile”
  [ -f /etc/profile ] && . /etc/profile
fi

test -x $MDRM_HOME || exit 5

action=”$1″

# Initialize stop wait time if not provided by the config file
[ -z “$STOP_WAIT_TIME” ] && STOP_WAIT_TIME=”60″

# ANSI Colors, not work well in some unix system.
echoRed() {
  echo “$1” ;
  echo “`date` $1” >> ${log_file}
}
echoGreen() {
  echo “$1” ;
  echo “`date` $1” >> ${log_file}
}
echoYellow() {
  echo “$1” ;
  echo “`date` $1” >> ${log_file}
}

# Utility functions
checkPermissions() {
  touch “$pid_file” || { echoRed “Operation not permitted (cannot access pid file)”; return 4; }
  touch “$log_file” || { echoRed “Operation not permitted (cannot access log file)”; return 4; }
}

isRunning() {
  ps -p “$1”
}

await_file() {
  end=$(date +%s)
  end=$((end+10))
  while [ ! -s “$1” ]
  do
    now=$(date +%s)
    if [ $now -ge $end ]; then
      break
    fi
    sleep 1
  done
}



# Initialize PID/LOG locations if they weren’t provided by the config file
[ -z “$PID_FOLDER” ] && PID_FOLDER=”/var/run”
[ -z “$LOG_FOLDER” ] && LOG_FOLDER=”/var/log”
! [ -x “$PID_FOLDER” ] && PID_FOLDER=”/tmp”
! [ -x “$LOG_FOLDER” ] && LOG_FOLDER=”/tmp”

# Build the pid and log filenames
PID_FOLDER=”$PID_FOLDER/${identity}”
pid_file=”$PID_FOLDER/${identity}.pid”
log_file=”$LOG_FOLDER/$LOG_FILENAME”


# Find Java
if [ -n “$JAVA_HOME” ] && [ -x “$JAVA_HOME/bin/java” ]; then
    javaexe=”$JAVA_HOME/bin/java”
elif type -p java > /dev/null; then
    javaexe=$(which java)
elif [ -x “/usr/bin/java” ];  then
    javaexe=”/usr/bin/java”
else
    echoRed “Unable to find Java”
    exit 1
fi

arguments=”-Dsun.misc.URLClassPath.disableJarChecking=true -Dfile.encoding=UTF8 $JAVA_OPTS -jar $jarfile $RUN_ARGS $1″

#echoGreen “arguments: ${arguments}”

# Action functions
start() {
  if [ -f “$pid_file” ]; then
    pid=$(cat “$pid_file”)
    isRunning “$pid” && { echoYellow “Already running [$pid]”; return 0; }
  fi
  do_start “$@”
}

do_start() {
  echoGreen “do_start”
  working_dir=$(dirname “$jarfile”)
  mkdir -p “$PID_FOLDER”
  cd $MDRM_HOME
  if [ -n “$run_user” ]; then
    echoGreen “no run_user”
    checkPermissions || return $?
    chown “$run_user” “$PID_FOLDER”
    chown “$run_user” “$pid_file”
    chown “$run_user” “$log_file”
    echoGreen “su -s /bin/sh -c $javaexe ${arguments}”
    su -s /bin/sh -c “$javaexe $(printf “\”%s\” ” “${arguments}”) >> \”$log_file\” 2>&1 & echo \$!” “$run_user” > “$pid_file”
    pid=$(cat “$pid_file”)
#    $javaexe ${arguments} >> $log_file &
#    pid=$!
#    “$pid” > “$pid_file”
    echoGreen “pid_file location: $pid_file”
  else
    echoGreen “have run_user, ${javaexe} ${arguments[@]}”
    checkPermissions || return $?
    echoGreen “$javaexe ${arguments}”
    #nohup $javaexe ${arguments} >> $log_file &
    nohup $javaexe ${arguments} &
    pid=$!
    echo “$pid” > “$pid_file”
    echoGreen “pid_file location: $pid_file”
  fi
  [ -z $pid ] && { echoRed “Failed to start”; return 1; }
  echoGreen “Started [$pid]”
}

stop_service() {
  echoGreen “stop_service”
  working_dir=$(dirname “$jarfile”)
  [ -f $pid_file ] || { echoYellow “Not running (pidfile not found)”; return 0; }
  pid=$(cat “$pid_file”)
  isRunning “$pid” || { echoYellow “Not running (process ${pid}). Removing stale pid file.”; rm -f “$pid_file”; return 0; }
  do_stop “$pid” “$pid_file”
}

do_stop() {
  echoGreen “doStop Service”
  kill “$1” || { echoRed “Unable to kill process $1”; return 1; }
  ##solaris have no “seq” command, so hardcoding 60 for time out number.
  isRunning “$1” || { echoGreen “Stopped [$1]”; rm -f “$2”; return 0; }
  sleep 2
  isRunning “$1” || { echoGreen “Stopped [$1]”; rm -f “$2”; return 0; }
  sleep 4
  isRunning “$1” || { echoGreen “Stopped [$1]”; rm -f “$2”; return 0; }
  sleep 4
  isRunning “$1” || { echoGreen “Stopped [$1]”; rm -f “$2”; return 0; }
  kill -9 “$1” || { echoRed “Unable to kill process $1”; return 1; }
  isRunning “$1” || { echoGreen “Stopped [$1]”; rm -f “$2”; return 0; }
  echoRed “Unable to kill process $1”;
  return 1;
}

force_stop() {
  echoGreen “force Stop Service”
  [ -f $pid_file ] || { echoYellow “Not running (pidfile not found)”; return 0; }
  pid=$(cat “$pid_file”)
  isRunning “$pid” || { echoYellow “Not running (process ${pid}). Removing stale pid file.”; rm -f “$pid_file”; return 0; }
  do_force_stop “$pid” “$pid_file”
}

do_force_stop() {
  kill -9 “$1” || { echoRed “Unable to kill process $1”; return 1; }
}

restart() {
  stop_service
  start
}

force_reload() {
  working_dir=$(dirname “$jarfile”)
  [ -f $pid_file ] || { echoRed “Not running (pidfile not found)”; return 7; }
  pid=$(cat “$pid_file”)
  rm -f “$pid_file”
  isRunning “$pid” || { echoRed “Not running (process ${pid} not found)”; return 7; }
  do_stop “$pid” “$pid_file”
  do_start
}

status() {
  working_dir=$(dirname “$jarfile”)
  [ -f “$pid_file” ] || { echoRed “Not running”; return 3; }
  pid=$(cat “$pid_file”)
  isRunning “$pid” || { echoRed “Not running (process ${pid} not found)”; return 1; }
  echoGreen “Running [$pid]”
  return 0
}

run() {
  “$javaexe” “${arguments}”
  result=$?
  popd > /dev/null
  return “$result”
}

echoGreen “$action”
# Call the appropriate action function
case “$action” in
‘start’)
  start “$@”; exit $?;;
‘stop’)
  stop_service “$@”; exit $?;;
‘force-stop’)
  force_stop “$@”; exit $?;;
‘restart’)
  restart “$@”; exit $?;;
‘force-reload’)
  force_reload “$@”; exit $?;;
‘status’)
  status “$@”; exit $?;;
‘run’)
  run “$@”; exit $?;;
*)
  echo “Usage: $0 {start|stop|force-stop|restart|force-reload|status|run}”; exit 1;
esac

exit 0MDRM