Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # WildFly control script
  4. #
  5. # chkconfig: - 80 20
  6. # description: WildFly startup script
  7. # processname: wildfly
  8. # pidfile: /var/run/wildfly/wildfly.pid
  9. # config: /etc/default/wildfly.conf
  10. #
  11. export RELINQUISH_LOG4J_CONTROL=true
  12. export LC_ALL=ru_RU.UTF-8
  13. # Source function library.
  14. . /etc/init.d/functions
  15.  
  16. # Load Java configuration.
  17. [ -r /etc/java/java.conf ] && . /etc/java/java.conf
  18. export JAVA_HOME
  19.  
  20. # Load JBoss AS init.d configuration.
  21. if [ -z "$JBOSS_CONF" ]; then
  22. JBOSS_CONF="/etc/default/wildfly12.conf"
  23. fi
  24.  
  25. [ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"
  26.  
  27. # Set defaults.
  28.  
  29. if [ -z "$JBOSS_HOME" ]; then
  30. JBOSS_HOME=/opt/wildfly-12.0.0.Final
  31. fi
  32. export JBOSS_HOME
  33.  
  34. if [ -z "$JBOSS_PIDFILE" ]; then
  35. JBOSS_PIDFILE=/var/run/wildfly/wildfly12.pid
  36. fi
  37. export JBOSS_PIDFILE
  38.  
  39. if [ -z "$JBOSS_CONSOLE_LOG" ]; then
  40. JBOSS_CONSOLE_LOG=/var/log/wildfly12/console.log
  41. fi
  42.  
  43. if [ -z "$STARTUP_WAIT" ]; then
  44. STARTUP_WAIT=30
  45. fi
  46.  
  47. if [ -z "$SHUTDOWN_WAIT" ]; then
  48. SHUTDOWN_WAIT=30
  49. fi
  50.  
  51. if [ -z "$JBOSS_LOCKFILE" ]; then
  52. JBOSS_LOCKFILE=/var/lock/subsys/wildfly
  53. fi
  54.  
  55. # Startup mode of wildfly
  56. if [ -z "$JBOSS_MODE" ]; then
  57. JBOSS_MODE=standalone
  58. fi
  59.  
  60. # Startup mode script
  61. if [ "$JBOSS_MODE" = "standalone" ]; then
  62. JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh
  63. if [ -z "$JBOSS_CONFIG" ]; then
  64. JBOSS_CONFIG=standalone.xml
  65. fi
  66. else
  67. JBOSS_SCRIPT=$JBOSS_HOME/bin/domain.sh
  68. if [ -z "$JBOSS_DOMAIN_CONFIG" ]; then
  69. JBOSS_DOMAIN_CONFIG=domain.xml
  70. fi
  71. if [ -z "$JBOSS_HOST_CONFIG" ]; then
  72. JBOSS_HOST_CONFIG=host.xml
  73. fi
  74. fi
  75.  
  76. prog='wildfly'
  77.  
  78. start() {
  79. echo -n "Starting $prog: "
  80. if [ -f $JBOSS_PIDFILE ]; then
  81. read ppid < $JBOSS_PIDFILE
  82. if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  83. echo -n "$prog is already running"
  84. failure
  85. echo
  86. return 1
  87. else
  88. rm -f $JBOSS_PIDFILE
  89. fi
  90. fi
  91. mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
  92. cat /dev/null > $JBOSS_CONSOLE_LOG
  93.  
  94. mkdir -p $(dirname $JBOSS_PIDFILE)
  95. chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
  96.  
  97. if [ ! -z "$JBOSS_USER" ]; then
  98. if [ "$JBOSS_MODE" = "standalone" ]; then
  99. if [ -r /etc/rc.d/init.d/functions ]; then
  100. daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG $JBOSS_OPTS >> $JBOSS_CONSOLE_LOG 2>&1 &
  101. else
  102. su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG $JBOSS_OPTS" >> $JBOSS_CONSOLE_LOG 2>&1 &
  103. fi
  104. else
  105. if [ -r /etc/rc.d/init.d/functions ]; then
  106. 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 $JBOSS_OPTS >> $JBOSS_CONSOLE_LOG 2>&1 &
  107. else
  108. 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 $JBOSS_OPTS" >> $JBOSS_CONSOLE_LOG 2>&1 &
  109. fi
  110. fi
  111. fi
  112.  
  113. count=0
  114. launched=false
  115.  
  116. until [ $count -gt $STARTUP_WAIT ]
  117. do
  118. grep 'WFLYSRV0025:' $JBOSS_CONSOLE_LOG > /dev/null
  119. if [ $? -eq 0 ] ; then
  120. launched=true
  121. break
  122. fi
  123. sleep 1
  124. let count=$count+1;
  125. done
  126.  
  127. touch $JBOSS_LOCKFILE
  128. success
  129. echo
  130. return 0
  131. }
  132.  
  133. stop() {
  134. echo -n $"Stopping $prog: "
  135. count=0;
  136.  
  137. if [ -f $JBOSS_PIDFILE ]; then
  138. read kpid < $JBOSS_PIDFILE
  139. let kwait=$SHUTDOWN_WAIT
  140.  
  141. # Try issuing SIGTERM
  142. kill -15 $kpid
  143. until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
  144. do
  145. sleep 1
  146. let count=$count+1;
  147. done
  148.  
  149. if [ $count -gt $kwait ]; then
  150. kill -9 $kpid
  151. fi
  152. fi
  153. rm -f $JBOSS_PIDFILE
  154. rm -f $JBOSS_LOCKFILE
  155. success
  156. echo
  157. }
  158.  
  159. status() {
  160. if [ -f $JBOSS_PIDFILE ]; then
  161. read ppid < $JBOSS_PIDFILE
  162. if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
  163. echo "$prog is running (pid $ppid)"
  164. return 0
  165. else
  166. echo "$prog dead but pid file exists"
  167. return 1
  168. fi
  169. fi
  170. echo "$prog is not running"
  171. return 3
  172. }
  173.  
  174. case "$1" in
  175. start)
  176. start
  177. ;;
  178. stop)
  179. stop
  180. ;;
  181. restart)
  182. $0 stop
  183. $0 start
  184. ;;
  185. status)
  186. status
  187. ;;
  188. *)
  189. ## If no parameters are given, print which are avaiable.
  190. echo "Usage: $0 {start|stop|status|restart|reload}"
  191. exit 1
  192. ;;
  193. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement