jboss-as-domain.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/sh
  2. #
  3. # JBoss domain control script
  4. #
  5. # chkconfig: - 80 20
  6. # description: JBoss AS Domain
  7. # processname: domain
  8. # pidfile: /var/run/jboss-as/jboss-as-domain.pid
  9. # config: /etc/jboss-as/jboss-as.conf
  10. # Source function library.
  11. . /etc/init.d/functions
  12. # Load Java configuration.
  13. [ -r /etc/java/java.conf ] && . /etc/java/java.conf
  14. export JAVA_HOME
  15. # Load JBoss AS init.d configuration.
  16. if [ -z "$JBOSS_CONF" ]; then
  17. JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
  18. fi
  19. [ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"
  20. # Set defaults.
  21. if [ -z "$JBOSS_HOME" ]; then
  22. JBOSS_HOME=/usr/share/jboss-as
  23. fi
  24. export JBOSS_HOME
  25. if [ -z "$JBOSS_PIDFILE" ]; then
  26. JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-domain.pid
  27. fi
  28. export JBOSS_PIDFILE
  29. if [ -z "$JBOSS_CONSOLE_LOG" ]; then
  30. JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log
  31. fi
  32. if [ -z "$STARTUP_WAIT" ]; then
  33. STARTUP_WAIT=30
  34. fi
  35. if [ -z "$SHUTDOWN_WAIT" ]; then
  36. SHUTDOWN_WAIT=30
  37. fi
  38. if [ -z "$JBOSS_DOMAIN_CONFIG" ]; then
  39. JBOSS_DOMAIN_CONFIG=domain.xml
  40. fi
  41. if [ -z "$JBOSS_HOST_CONFIG" ]; then
  42. JBOSS_HOST_CONFIG=host.xml
  43. fi
  44. JBOSS_SCRIPT=$JBOSS_HOME/bin/domain.sh
  45. prog='jboss-as'
  46. CMD_PREFIX=''
  47. if [ ! -z "$JBOSS_USER" ]; then
  48. if [ -x /etc/rc.d/init.d/functions ]; then
  49. CMD_PREFIX="daemon --user $JBOSS_USER"
  50. else
  51. CMD_PREFIX="su - $JBOSS_USER -c"
  52. fi
  53. fi
  54. start() {
  55. echo -n "Starting $prog: "
  56. if [ -f $JBOSS_PIDFILE ]; then
  57. read ppid < $JBOSS_PIDFILE
  58. if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  59. echo -n "$prog is already running"
  60. failure
  61. echo
  62. return 1
  63. else
  64. rm -f $JBOSS_PIDFILE
  65. fi
  66. fi
  67. mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
  68. cat /dev/null > $JBOSS_CONSOLE_LOG
  69. mkdir -p $(dirname $JBOSS_PIDFILE)
  70. chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
  71. #$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &
  72. #$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &
  73. if [ ! -z "$JBOSS_USER" ]; then
  74. if [ -r /etc/rc.d/init.d/functions ]; then
  75. daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT --domain-config=$JBOSS_DOMAIN_CONFIG --host-config=$JBOSS_HOST_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &
  76. else
  77. su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT --domain-config=$JBOSS_DOMAIN_CONFIG --host-config=$JBOSS_HOST_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &
  78. fi
  79. fi
  80. count=0
  81. launched=false
  82. until [ $count -gt $STARTUP_WAIT ]
  83. do
  84. grep 'JBoss AS.*started in' $JBOSS_CONSOLE_LOG > /dev/null
  85. if [ $? -eq 0 ] ; then
  86. launched=true
  87. break
  88. fi
  89. sleep 1
  90. let count=$count+1;
  91. done
  92. success
  93. echo
  94. return 0
  95. }
  96. stop() {
  97. echo -n $"Stopping $prog: "
  98. count=0;
  99. if [ -f $JBOSS_PIDFILE ]; then
  100. read kpid < $JBOSS_PIDFILE
  101. let kwait=$SHUTDOWN_WAIT
  102. # Try issuing SIGTERM
  103. kill -15 $kpid
  104. until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
  105. do
  106. sleep 1
  107. let count=$count+1;
  108. done
  109. if [ $count -gt $kwait ]; then
  110. kill -9 $kpid
  111. fi
  112. fi
  113. rm -f $JBOSS_PIDFILE
  114. success
  115. echo
  116. }
  117. status() {
  118. if [ -f $JBOSS_PIDFILE ]; then
  119. read ppid < $JBOSS_PIDFILE
  120. if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  121. echo "$prog is running (pid $ppid)"
  122. return 0
  123. else
  124. echo "$prog dead but pid file exists"
  125. return 1
  126. fi
  127. fi
  128. echo "$prog is not running"
  129. return 3
  130. }
  131. case "$1" in
  132. start)
  133. start
  134. ;;
  135. stop)
  136. stop
  137. ;;
  138. restart)
  139. $0 stop
  140. $0 start
  141. ;;
  142. status)
  143. status
  144. ;;
  145. *)
  146. ## If no parameters are given, print which are avaiable.
  147. echo "Usage: $0 {start|stop|status|restart|reload}"
  148. exit 1
  149. ;;
  150. esac