startup.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. printf "${GREEN_COLOR}\n"
  10. cat<<EOT
  11. --------------------------------------------
  12. / \\
  13. / ___ _ __ ___ _ __ ___ _ __ ___ _ __ \\
  14. / / _ \| '_ \ / _ \ '_ \ / __| '__/ _ \| '_ \\ \\
  15. / | (_) | |_) | __/ | | | (__| | | (_) | | | | \\
  16. \\ \___/| .__/ \___|_| |_|\___|_| \___/|_| |_| /
  17. \\ |_| /
  18. \\ /
  19. \\ --opencron,Let's crontab easy! /
  20. --------------------------------------------
  21. EOT
  22. printf "${RES}\n";
  23. echo_r () {
  24. # Color red: Error, Failed
  25. [ $# -ne 1 ] && return 1
  26. printf "[${GREEN_COLOR}opencron${RES}] ${RED_COLOR}$1${RES}\n"
  27. }
  28. echo_g () {
  29. # Color green: Success
  30. [ $# -ne 1 ] && return 1
  31. printf "[${GREEN_COLOR}opencron${RES}] ${GREEN_COLOR}$1${RES}\n"
  32. }
  33. echo_y () {
  34. # Color yellow: Warning
  35. [ $# -ne 1 ] && return 1
  36. printf "[${GREEN_COLOR}opencron${RES}] ${YELLOW_COLOR}$1${RES}\n"
  37. }
  38. echo_w () {
  39. # Color yellow: White
  40. [ $# -ne 1 ] && return 1
  41. printf "[${GREEN_COLOR}opencron${RES}] ${WHITE_COLOR}$1${RES}\n"
  42. }
  43. # Make sure prerequisite environment variables are set
  44. if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  45. if $darwin; then
  46. # Bugzilla 54390
  47. if [ -x '/usr/libexec/java_home' ] ; then
  48. export JAVA_HOME=`/usr/libexec/java_home`
  49. # Bugzilla 37284 (reviewed).
  50. elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
  51. export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
  52. fi
  53. else
  54. JAVA_PATH=`which java 2>/dev/null`
  55. if [ "x$JAVA_PATH" != "x" ]; then
  56. JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
  57. JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
  58. fi
  59. if [ "x$JRE_HOME" = "x" ]; then
  60. # XXX: Should we try other locations?
  61. if [ -x /usr/bin/java ]; then
  62. JRE_HOME=/usr
  63. fi
  64. fi
  65. fi
  66. if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  67. echo_r "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
  68. echo_r "At least one of these environment variable is needed to run this program"
  69. exit 1
  70. fi
  71. fi
  72. if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
  73. echo "JAVA_HOME should point to a JDK in order to run in debug mode."
  74. exit 1
  75. fi
  76. if [ -z "$JRE_HOME" ]; then
  77. JRE_HOME="$JAVA_HOME"
  78. fi
  79. # If we're running under jdb, we need a full jdk.
  80. if [ "$1" = "debug" ] ; then
  81. if [ "$os400" = "true" ]; then
  82. if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
  83. echo_r "The JAVA_HOME environment variable is not defined correctly"
  84. echo_r "This environment variable is needed to run this program"
  85. echo_r "NB: JAVA_HOME should point to a JDK not a JRE"
  86. exit 1
  87. fi
  88. else
  89. if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
  90. echo_r "The JAVA_HOME environment variable is not defined correctly"
  91. echo_r "This environment variable is needed to run this program"
  92. echo_r "NB: JAVA_HOME should point to a JDK not a JRE"
  93. exit 1
  94. fi
  95. fi
  96. fi
  97. # Don't override the endorsed dir if the user has set it previously
  98. if [ -z "$JAVA_ENDORSED_DIRS" ]; then
  99. # Set the default -Djava.endorsed.dirs argument
  100. JAVA_ENDORSED_DIRS="$OPENCRON_HOME"/endorsed
  101. fi
  102. # Set standard commands for invoking Java, if not already set.
  103. if [ -z "$RUNJAVA" ]; then
  104. RUNJAVA="$JRE_HOME"/bin/java
  105. fi
  106. if [ "$os400" != "true" ]; then
  107. if [ -z "$_RUNJDB" ]; then
  108. _RUNJDB="$JAVA_HOME"/bin/jdb
  109. fi
  110. fi
  111. #check java exists.
  112. $RUNJAVA >/dev/null 2>&1
  113. if [ $? -ne 1 ];then
  114. echo_r "ERROR: java is not install,please install java first!"
  115. exit 1;
  116. fi
  117. #check openjdk
  118. if [ "`${RUNJAVA} -version 2>&1 | head -1|grep "openjdk"|wc -l`"x == "1"x ]; then
  119. echo_r "ERROR: please uninstall OpenJDK and install jdk first"
  120. exit 1;
  121. fi
  122. # OS specific support. $var _must_ be set to either true or false.
  123. cygwin=false
  124. darwin=false
  125. os400=false
  126. case "`uname`" in
  127. CYGWIN*) cygwin=true;;
  128. Darwin*) darwin=true;;
  129. OS400*) os400=true;;
  130. esac
  131. # resolve links - $0 may be a softlink
  132. PRG="$0"
  133. while [ -h "$PRG" ]; do
  134. ls=`ls -ld "$PRG"`
  135. link=`expr "$ls" : '.*-> \(.*\)$'`
  136. if expr "$link" : '/.*' > /dev/null; then
  137. PRG="$link"
  138. else
  139. PRG=`dirname "$PRG"`/"$link"
  140. fi
  141. done
  142. # Get standard environment variables
  143. PRGDIR=`dirname "$PRG"`
  144. WORKDIR=`cd "$PRGDIR" >/dev/null; pwd`;
  145. APP_ARTIFACT=opencron-server
  146. LIB_PATH="$WORKDIR"/WEB-INF/lib
  147. LOG_PATH="$WORKDIR"/work/logs
  148. # Add jars to classpath
  149. if [ ! -z "$CLASSPATH" ] ; then
  150. CLASSPATH="$CLASSPATH":
  151. fi
  152. CLASSPATH="$CLASSPATH""$WORKDIR"/WEB-INF/classes
  153. for jar in ${LIB_PATH}/*
  154. do
  155. CLASSPATH="$CLASSPATH":"$jar"
  156. done
  157. #start server....
  158. printf "[${BLUE_COLOR}opencron${RES}] ${WHITE_COLOR} server Starting.... ${RES}\n"
  159. eval "\"$RUNJAVA\"" \
  160. -classpath "\"$CLASSPATH\"" \
  161. -Dserver.launcher=tomcat \
  162. org.opencron.server.bootstrap.Startup $1 \
  163. >/dev/null 2>&1 "&";
  164. printf "[${BLUE_COLOR}opencron${RES}] ${WHITE_COLOR} please see log for more detail:${RES}${GREEN_COLOR} $LOG_PATH/opencron.out ${RES}\n"
  165. exit $?