jboss-as-standalone.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/bin/sh
  2. #
  3. # JBoss standalone control script
  4. #
  5. # chkconfig: - 80 20
  6. # description: JBoss AS Standalone
  7. # processname: standalone
  8. # pidfile: /var/run/jboss-as/jboss-as-standalone.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-standalone.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_CONFIG" ]; then
  39. JBOSS_CONFIG=standalone.xml
  40. fi
  41. JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh
  42. prog='jboss-as'
  43. CMD_PREFIX=''
  44. if [ ! -z "$JBOSS_USER" ]; then
  45. if [ -r /etc/rc.d/init.d/functions ]; then
  46. CMD_PREFIX="daemon --user $JBOSS_USER"
  47. else
  48. CMD_PREFIX="su - $JBOSS_USER -c"
  49. fi
  50. fi
  51. start() {
  52. echo -n "Starting $prog: "
  53. if [ -f $JBOSS_PIDFILE ]; then
  54. read ppid < $JBOSS_PIDFILE
  55. if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  56. echo -n "$prog is already running"
  57. failure
  58. echo
  59. return 1
  60. else
  61. rm -f $JBOSS_PIDFILE
  62. fi
  63. fi
  64. mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
  65. cat /dev/null > $JBOSS_CONSOLE_LOG
  66. mkdir -p $(dirname $JBOSS_PIDFILE)
  67. chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
  68. #$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &
  69. #$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &
  70. if [ ! -z "$JBOSS_USER" ]; then
  71. if [ -r /etc/rc.d/init.d/functions ]; then
  72. daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &
  73. else
  74. su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &
  75. fi
  76. fi
  77. count=0
  78. launched=false
  79. until [ $count -gt $STARTUP_WAIT ]
  80. do
  81. grep 'JBAS015874:' $JBOSS_CONSOLE_LOG > /dev/null
  82. if [ $? -eq 0 ] ; then
  83. launched=true
  84. break
  85. fi
  86. sleep 1
  87. let count=$count+1;
  88. done
  89. success
  90. echo
  91. return 0
  92. }
  93. stop() {
  94. echo -n $"Stopping $prog: "
  95. count=0;
  96. if [ -f $JBOSS_PIDFILE ]; then
  97. read kpid < $JBOSS_PIDFILE
  98. let kwait=$SHUTDOWN_WAIT
  99. # Try issuing SIGTERM
  100. kill -15 $kpid
  101. until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
  102. do
  103. sleep 1
  104. let count=$count+1;
  105. done
  106. if [ $count -gt $kwait ]; then
  107. kill -9 $kpid
  108. fi
  109. fi
  110. rm -f $JBOSS_PIDFILE
  111. success
  112. echo
  113. }
  114. status() {
  115. if [ -f $JBOSS_PIDFILE ]; then
  116. read ppid < $JBOSS_PIDFILE
  117. if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  118. echo "$prog is running (pid $ppid)"
  119. return 0
  120. else
  121. echo "$prog dead but pid file exists"
  122. return 1
  123. fi
  124. fi
  125. echo "$prog is not running"
  126. return 3
  127. }
  128. case "$1" in
  129. start)
  130. start
  131. ;;
  132. stop)
  133. stop
  134. ;;
  135. restart)
  136. $0 stop
  137. $0 start
  138. ;;
  139. status)
  140. status
  141. ;;
  142. *)
  143. ## If no parameters are given, print which are avaiable.
  144. echo "Usage: $0 {start|stop|status|restart|reload}"
  145. exit 1
  146. ;;
  147. esac