All Downloads are FREE. Search and download functionalities are using the official Maven repository.

archetype-resources.scripts.app Maven / Gradle / Ivy

There is a newer version: 1.1.14
Show newest version
#!/bin/bash

script_home=$(readlink -f $(dirname $(readlink -f "$0")))
app_home=$(readlink -f $(dirname $script_home))
# 查找app java环境所在的目录
java_home="$JAVA_HOME_17"
if [ -z "$java_home" ]; then
  java_home="$JAVA_HOME"
fi
if [ ! -d "$java_home" ]; then
  echo "cannot found java_home: $java_home"
  exit 1
fi
# 查找java命令
java_cmd="$java_home/bin/java"
if [ ! -x "$java_cmd" ]; then
  echo "cannot found executable java_cmd: $java_cmd"
  exit 1
fi
# 设置java环境
export JAVA_HOME=$java_home
# 获取日志路径
app_runtime_home=$APP_RUNTIME_HOME
if [ -z "$app_runtime_home" ]; then
    app_runtime_home=$app_home
fi
# 查找agent
agent_jar=$(find . -maxdepth 1 -type f -name 'convention4j-agent-*.jar')
# spring环境
spring_profiles_active='prod'
if [ -n "$SPRING_PROFILES_ACTIVE" ]; then
  spring_profiles_active="$SPRING_PROFILES_ACTIVE"
fi

env() {
  echo "script_home: $script_home"
  echo "app_home: $app_home"
  echo "app_runtime_home: $app_runtime_home"
  echo "java_home: $java_home"
  echo "java_cmd: $java_cmd"
  echo "agent_jar: $agent_jar"
  echo "spring_profiles_active: $spring_profiles_active"
}

build() {
  set -e
  cd $app_home
  mvn clean install
}

pid() {
  app_pid=$(cat $app_runtime_home/app.pid 2>/dev/null)
  echo "$app_pid"
}

stop() {
  set -e
  app_pid=$(cat $app_runtime_home/app.pid 2>/dev/null)
  if [ -n "$app_pid" ]; then
    kill $app_pid
    rm -f $app_runtime_home/app.pid
  fi
}

start() {
  set -e
  trap stop SIGINT SIGQUIT SIGTERM
  if [ -n "$JAVA_OPTS" ]; then
    JAVA_OPTS=" $JAVA_OPTS"
  fi
  JAVA_OPTS="-server -Xms64M -Xmx256M$JAVA_OPTS"
  JAVA_OPTS="$JAVA_OPTS -Dsun.net.inetaddr.ttl=30 -Dsun.net.inetaddr.negative.ttl=5"
  #JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:10000 $JAVA_OPTS"
  if [ "$DEBUG" == "true" ]; then
    JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:10000"
  fi
  if [ -n "$agent_jar" ]; then
    JAVA_OPTS="$JAVA_OPTS -javaagent:$agent_jar"
  fi
  if [ "$spring_profiles_active" == 'dev' ]; then
    echo "$java_cmd $JAVA_OPTS -jar $app_home/web/target/*.jar --spring.profiles.active=$spring_profiles_active --logging.path=$app_runtime_home/logs"
    $java_cmd $JAVA_OPTS -jar $app_home/web/target/*.jar \
      --spring.profiles.active=$spring_profiles_active \
      --logging.path=$app_runtime_home/logs
  else
    echo "nohup $java_cmd $JAVA_OPTS -jar $app_home/web/target/*.jar --spring.profiles.active=$spring_profiles_active --logging.path=$app_runtime_home/logs >>$app_runtime_home/logs/console.log 2>&1 &"
    nohup $java_cmd $JAVA_OPTS -jar $app_home/web/target/*.jar \
      --spring.profiles.active=$spring_profiles_active \
      --logging.path=$app_runtime_home/logs >>$app_runtime_home/logs/console.log 2>&1 &
  fi
  app_pid=$!
  echo $app_pid > $app_runtime_home/app.pid
}

help() {
  echo "Usage: $0 {env|build|start|stop}"
}

case "$1" in
  'env')
    env
    ;;
  'build')
    build
    ;;
  'start')
    start
    ;;
  'stop')
    stop
    ;;
  'pid')
    pid
    ;;
  *)
    help
    ;;
esac




© 2015 - 2025 Weber Informatics LLC | Privacy Policy