agent.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #echo color
  3. WHITE_COLOR="\E[1;37m";
  4. RED_COLOR="\E[1;31m";
  5. BLUE_COLOR='\E[1;34m';
  6. GREEN_COLOR="\E[1;32m";
  7. YELLOW_COLOR="\E[1;33m";
  8. RES="\E[0m";
  9. echo_r () {
  10. # Color red: Error, Failed
  11. [ $# -ne 1 ] && return 1
  12. echo -e "[${GREEN_COLOR}opencron${RES}] ${RED_COLOR}$1${RES}"
  13. }
  14. echo_g () {
  15. # Color green: Success
  16. [ $# -ne 1 ] && return 1
  17. echo -e "[${GREEN_COLOR}opencron${RES}] ${GREEN_COLOR}$1${RES}"
  18. }
  19. echo_y () {
  20. # Color yellow: Warning
  21. [ $# -ne 1 ] && return 1
  22. echo -e "[${GREEN_COLOR}opencron${RES}] ${YELLOW_COLOR}$1${RES}"
  23. }
  24. echo_w () {
  25. # Color yellow: White
  26. [ $# -ne 1 ] && return 1
  27. echo -e "[${GREEN_COLOR}opencron${RES}] ${WHITE_COLOR}$1${RES}"
  28. }
  29. # OS specific support. $var _must_ be set to either true or false.
  30. cygwin=false
  31. darwin=false
  32. os400=false
  33. case "`uname`" in
  34. CYGWIN*) cygwin=true;;
  35. Darwin*) darwin=true;;
  36. OS400*) os400=true;;
  37. esac
  38. # resolve links - $0 may be a softlink
  39. PRG="$0"
  40. while [ -h "$PRG" ]; do
  41. ls=`ls -ld "$PRG"`
  42. link=`expr "$ls" : '.*-> \(.*\)$'`
  43. if expr "$link" : '/.*' > /dev/null; then
  44. PRG="$link"
  45. else
  46. PRG=`dirname "$PRG"`/"$link"
  47. fi
  48. done
  49. # Get standard environment variables
  50. PRGDIR=`dirname "$PRG"`
  51. WORKDIR=`cd "$PRGDIR" >/dev/null; pwd`;
  52. APP_ARTIFACT=opencron-agent
  53. APP_VERSION="1.1.0-RELEASE";
  54. APP_TAR_NAME=${APP_ARTIFACT}-${APP_VERSION}.tar.gz
  55. MAVEN_TARGET_TAR="${WORKDIR}"/${APP_ARTIFACT}/target/${APP_TAR_NAME}
  56. DIST_PATH=${WORKDIR}/dist/
  57. [ ! -d "${DIST_PATH}" ] && mkdir -p "${DIST_PATH}"
  58. DEPLOY_PATH=${WORKDIR}/dist/opencron-agent
  59. #先检查dist下是否有war包
  60. if [ ! -f "${DIST_PATH}/${APP_TAR_NAME}" ] ; then
  61. #dist下没有tar包则检查agent的target下是否有tar包.
  62. if [ ! -f "${MAVEN_TARGET_TAR}" ] ; then
  63. echo_w "[opencron] please build project first!"
  64. exit 0;
  65. else
  66. cp ${MAVEN_TARGET_TAR} ${DIST_PATH};
  67. fi
  68. fi
  69. [ -d "${DEPLOY_PATH}" ] && rm -rf ${DEPLOY_PATH}/* || mkdir -p ${DEPLOY_PATH}
  70. tar -xzvf ${DIST_PATH}/${APP_TAR_NAME} -C ${DEPLOY_PATH}/../ >/dev/null 2>&1
  71. #startup
  72. /bin/bash +x "${DEPLOY_PATH}/bin/startup.sh" "$@"