Ubuntu 14.04 의 JBoss EAP 5.2 init 스크립트
JBoss EAP 5.2 를 Ubuntu 14.04 에서 운영할 경우에 서비스 시작을 init 에 등록하기 위한 스크립트. Wildfly 에 내용을 가지고 와서 마이그레이션 했다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
#!/bin/bash # # /etc/init.d/jboss-SvrAPI01 -- startup script for jboss of SvrAPI01 # # NAME="systemV" DEFAULT="/opt/jboss/domains/${NAME}/jboss-env.sh" DESC="Jboss EAP 5.2 Application Server for $NAME" # clear work and tmp dirs? CLEAR_WORK_TMP="Y" HOST_NAME=`/sbin/ifconfig ens3|grep 'inet addr:'|awk '{print $2}'|awk -F : '{print $2}'` # Check privilege if [ `id -u` -ne 0 ]; then echo "You need root privileges to run this script" exit 1 fi # Make sure wildfly is started with system locale if [ -r /etc/default/locale ]; then . /etc/default/locale export LANG fi . /lib/lsb/init-functions if [ -r /etc/default/rcS ]; then . /etc/default/rcS fi # Overwrite settings from default file if [ -f "$DEFAULT" ]; then . "$DEFAULT" fi # Setup the JVM if [ -z "$JAVA" ]; then if [ -n "$JAVA_HOME" ]; then JAVA="$JAVA_HOME/bin/java" else JAVA="java" fi fi # Check if wildfly is installed if [ ! -f "$JBOSS_HOME/bin/run.jar" ]; then log_failure_msg "$NAME is not installed in \"$JBOSS_HOME\"" exit 1 fi # Run as wildfly user # Example of user creation for Debian based: # adduser --system --group --no-create-home --home $JBOSS_HOME --disabled-login wildfly if [ -z "$JBOSS_USER" ]; then JBOSS_USER=sbhyun fi # Check wildfly user id $JBOSS_USER > /dev/null 2>&1 if [ $? -ne 0 -o -z "$JBOSS_USER" ]; then log_failure_msg "User \"$JBOSS_USER\" does not exist..." exit 1 fi # Check owner of JBOSS_HOME if [ ! $(stat -L -c "%U" "$JBOSS_HOME") = $JBOSS_USER ]; then log_failure_msg "The user \"$JBOSS_USER\" is not owner of \"$JBOSS_HOME\"" exit 1 fi # The amount of time to wait for startup if [ -z "$STARTUP_WAIT" ]; then STARTUP_WAIT=120 fi # The amount of time to wait for shutdown if [ -z "$SHUTDOWN_WAIT" ]; then SHUTDOWN_WAIT=120 fi # Location to keep the console log if [ -z "$JBOSS_CONSOLE_LOG" ]; then JBOSS_CONSOLE_LOG="$SERVER_HOME/$SERVER_NAME/log/console.log" fi export JBOSS_CONSOLE_LOG touch $JBOSS_CONSOLE_LOG chown $JBOSS_USER $JBOSS_CONSOLE_LOG # Location to set the pid file JBOSS_PIDFILE="$SERVER_HOME/$SERVER_NAME/run/$SERVER_NAME.pid" export JBOSS_PIDFILE # Launch Jboss in background LAUNCH_JBOSS_IN_BACKGROUND=1 export LAUNCH_JBOSS_IN_BACKGROUND function cleanWorkTmp() { # clean tmp and work dirs echo "clean work and tmp dirs from ${SERVER_NAME}..." rm -Rf "${SERVER_HOME}/${SERVER_NAME}/work" rm -Rf "${SERVER_HOME}/${SERVER_NAME}/tmp" } function jbossPID() { # try get the JVM PID local jbossPID="x" jbossPID=$(ps -eo pid,cmd | grep "org.jboss.Main" | grep "${DOMAIN_IP}" | grep "${SERVER_NAME}" | grep -v grep | cut -c1-6) echo "$jbossPID" } # Helper function to check status of Jboss service check_status() { pidofproc -p "$JBOSS_PIDFILE" "$JAVA" >/dev/null 2>&1 } START_SCRIPT="$JBOSS_HOME/bin/run.sh" SHUTDOWN_SCRIPT="$JAVA -classpath $JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar org.jboss.Shutdown --shutdown -s jnp://$DOMAIN_IP:$JNP_PORT -u $JBOSS_ADMIN_USER -p $JBOSS_ADMIN_PWD" case "$1" in start) log_daemon_msg "Starting $DESC" log_daemon_msg "instance $SERVER_NAME at $DOMAIN_IP ..." check_status status_start=$? if [ $status_start -eq 3 ]; then mkdir -p $(dirname "$JBOSS_PIDFILE") mkdir -p $(dirname "$JBOSS_CONSOLE_LOG") cat /dev/null > "$JBOSS_CONSOLE_LOG" su -l $JBOSS_USER -c "source $DEFAULT; $START_SCRIPT $JBOSS_OPTS --host $HOST_NAME -c $SERVER_NAME -b $DOMAIN_IP > ${JBOSS_CONSOLE_LOG} 2>&1 &" count=0 launched=0 until [ $count -gt $STARTUP_WAIT ] do grep 'Started in' "$JBOSS_CONSOLE_LOG" > /dev/null if [ $? -eq 0 ] ; then launched=1 break fi sleep 1 count=$((count + 1)); done if [ $launched -eq 1 ] ; then echo `jbossPID` > $JBOSS_PIDFILE chown $JBOSS_USER $(dirname "$JBOSS_PIDFILE") || true fi if check_status; then log_end_msg 0 else log_end_msg 1 fi if [ $launched -eq 0 ]; then log_warning_msg "$DESC hasn't started within the timeout allowed" log_warning_msg "please review file \"$JBOSS_CONSOLE_LOG\" to see the status of the service" fi elif [ $status_start -eq 1 ]; then log_failure_msg "$DESC is not running but the pid file exists" exit 1 elif [ $status_start -eq 0 ]; then log_success_msg "$DESC (already running)" fi ;; stop) check_status status_stop=$? if [ $status_stop -eq 0 ]; then read kpid < "$JBOSS_PIDFILE" log_daemon_msg "Stopping $DESC" su -l $JBOSS_USER -c "source $DEFAULT; $SHUTDOWN_SCRIPT" count=0 until [ $count -gt $SHUTDOWN_WAIT ] do if ! check_status; then break fi sleep 1 count=$((count + 1)); done if check_status; then kill -9 $kpid fi if [ "$CLEAR_WORK_TMP" = "Y" ]; then cleanWorkTmp fi rm "$JBOSS_PIDFILE" log_end_msg 0 elif [ $status_stop -eq 1 ]; then log_action_msg "$DESC is not running but the pid file exists, cleaning up" rm -f $JBOSS_PIDFILE elif [ $status_stop -eq 3 ]; then log_action_msg "$DESC is not running" fi ;; restart) check_status status_restart=$? if [ $status_restart -eq 0 ]; then $0 stop fi $0 start ;; status) check_status status=$? if [ $status -eq 0 ]; then read pid < $JBOSS_PIDFILE log_action_msg "$DESC is running with pid $pid" exit 0 elif [ $status -eq 1 ]; then log_action_msg "$DESC is not running and the pid file exists" exit 1 elif [ $status -eq 3 ]; then log_action_msg "$DESC is not running" exit 3 else log_action_msg "Unable to determine $NAME status" exit 4 fi ;; *) log_action_msg "Usage: $0 {start|stop|restart|reload|force-reload|status}" exit 2 ;; esac exit 0 |
아래는 jboss-env.sh 의 내용.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
#!/bin/sh # jboss-env.sh - starts a new shell with instance variables set ## set jboss base env export JBOSS_HOME="/opt/jboss/jboss-as" export SERVER_HOME="/opt/jboss/domains" export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/jboss/lib" export JBOSS_USER=sbhyun export SERVER_NAME=systemV export DOMAIN_IP=0.0.0.0 export JNP_PORT=1199 export JAVA_HOME=/opt/java export CLASSPATH=.:/opt/java/jre/lib export PATH=$JAVA_HOME/bin:$JBOSS_HOME/bin:$PATH # JMX Credentials JMX_CREDETIALS_FILE="$SERVER_HOME/$SERVER_NAME/conf/props/jmx-console-users.properties" JMX_USER=$(cat $JMX_CREDETIALS_FILE | grep -v '#' | cut -d '=' -f 1 | head -n 1) JMX_PWD="$(cat $JMX_CREDETIALS_FILE | grep -v '#' | cut -d '=' -f 2 | head -n 1 | tr -d '\r')" JBOSS_ADMIN_USER=${JMX_USER:-"admin"} JBOSS_ADMIN_PWD=${JMX_PWD:-"admin"} if [ "x$JBOSS_OPTS" = "x" ]; then JBOSS_OPTS="-Dserver=$SERVER_NAME" JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.base.dir=$SERVER_HOME" JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.base.url=file://$SERVER_HOME" JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.log.dir=$SERVER_HOME/$SERVER_NAME/log" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.log.threshold=DEBUG" JBOSS_OPTS="$JBOSS_OPTS -Djboss.messaging.ServerPeerID=2" JBOSS_OPTS="$JBOSS_OPTS -Djboss.service.binding.set=ports-01" JBOSS_OPTS="$JBOSS_OPTS -Djboss.partition.name=systemV" JBOSS_OPTS="$JBOSS_OPTS -Djboss.default.jgroups.stack=tcp" JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.tcp.tcpping.initial_hosts=192.168.96.30[7700],192.168.96.31[7701]" JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.tcp.tcp_port=7600" JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.bind.address=192.168.96.30" #JBOSS_OPTS="$JBOSS_OPTS -Djgroups.bind_addr=228.2.2.2" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.tcp.tcp_port=7600" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.partition.udpGroup=228.2.2.2" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.hapartition.mcast_port=44552" fi if [ "x$JAVA_OPTS" = "x" ]; then JAVA_OPTS="-server" JAVA_OPTS="$JAVA_OPTS -noverify" JAVA_OPTS="$JAVA_OPTS -Xms512m" JAVA_OPTS="$JAVA_OPTS -Xmx512m" JAVA_OPTS="$JAVA_OPTS -XX:PermSize=128m" JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=128m" #JAVA_OPTS="$JAVA_OPTS -Xss128k" JAVA_OPTS="$JAVA_OPTS -verbose:gc" JAVA_OPTS="$JAVA_OPTS -Xloggc:$SERVER_HOME/$SERVER_NAME/gclog/gc.log" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps" JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC" JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError" JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$SERVER_HOME/$SERVER_NAME/gclog/java_pid.hprof" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8286" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false" JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" JAVA_OPTS="$JAVA_OPTS -Dsun.rmi.dgc.client.gcInterval=3600000" JAVA_OPTS="$JAVA_OPTS -Dsun.rmi.dgc.server.gcInterval=3600000" JAVA_OPTS="$JAVA_OPTS -Dsun.lang.ClassLoader.allowArraySyntax=true " fi export JBOSS_OPTS JAVA_OPTS |