How to install JBoss AS 7 as a Linux service

JBoss AS7 自启动配置
本文介绍如何配置 JBoss AS7 在 Linux 系统上随系统启动自启动的方法。通过创建并设置 /etc/rc.d/init.d/jbossas7 脚本,以及相应的运行级别链接,可以实现在特定运行级别下自动启动和关闭 JBoss AS7 服务。

See also: Start JBoss AS On Linux Boot - applies to JBoss AS 4, 5 and 6

 

 

This assumes you have JBoss AS 7 unzipped under /sw/AS7 .

The following operations are supposed to be done as the root user.

(Any improvements welcome.)

 

1) Create a script /etc/rc.d/init.d/jbossas7

 

Use $JBOSS_HOME/bin/init.d/jboss-as-standalone.sh (recommended).

 

  1. cp $JBOSS_HOME/bin/init.d/jboss-as-standalone.sh /etc/rc.d/init.d/jbossas7  

 

Or, if you're into something simpler, you can use this script:

 

  1. #!/bin/bash### BEGIN INIT INFO  
  2. # Provides:          jbossas7  
  3. # Required-Start:    $local_fs $remote_fs $network $syslog  
  4. # Required-Stop:     $local_fs $remote_fs $network $syslog  
  5. # Default-Start:     2 3 4 5  
  6. # Default-Stop:      0 1 6  
  7. # Short-Description: Start/Stop JBoss AS 7  
  8. ### END INIT INFO  
  9. # chkconfig: 35 92 1  
  10.   
  11. ## Include some script files in order to set and export environmental variables  
  12. ## as well as add the appropriate executables to $PATH.  
  13. [ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh  
  14. [ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh  
  15.   
  16. JBOSS_HOME=/sw/AS7  
  17.   
  18. AS7_OPTS="$AS7_OPTS -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true"   ## See AS7-1625  
  19. AS7_OPTS="$AS7_OPTS -Djboss.bind.address.management=0.0.0.0"  
  20. AS7_OPTS="$AS7_OPTS -Djboss.bind.address=0.0.0.0"  
  21.   
  22. case "$1" in  
  23.     start)  
  24.         echo "Starting JBoss AS 7..."  
  25.         #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS           ##  If running as user "jboss"  
  26.         #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS   ## Ubuntu  
  27.         ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS &  
  28.     ;;  
  29.     stop)  
  30.         echo "Stopping JBoss AS 7..."  
  31.         #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown            ##  If running as user "jboss"  
  32.         #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown     ## Ubuntu  
  33.         ${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown  
  34.     ;;  
  35.     *)  
  36.         echo "Usage: /etc/init.d/jbossas7 {start|stop}"; exit 1;  
  37.     ;;  
  38. esac  
  39.   
  40. exit 0  

 

There are 3 variants of start/stop comand under "echo "Starting JBoss AS 7..."

  • If you want to run JBoss AS 7 under different user, use the first line.
  • On Ubuntu, use the second line.
  • If you are okay with running it under root, use the script as is.

 

Then make the script executable:
  1. chmod +x /etc/rc.d/init.d/jbossas7  

 

2) Create links to it from respective runlevel dirs:

  1. chkconfig --add jbossas7  

 

...or the same, but manually:

 

  1. ## Start when entering to multi-user mode.  
  2. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc3.d/S84jbossas7  
  3. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc5.d/S84jbossas7  
  4. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc4.d/S84jbossas7  
  5.   
  6. ## Kill on shutdown or when switching to single-user mode.  
  7. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc6.d/K15jbossas7  
  8. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc0.d/K15jbossas7  
  9. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc1.d/K15jbossas7  
  10. ln -s /etc/rc.d/init.d/jbossas7 /etc/rc2.d/K15jbossas7  

 

For further info, see Wikipedia on Init or Red Hat docs on SysV.

3) Test

Try:

  1. service jbossas7 start  
  2. service jbossas7 stop  

You should see the server startup and shutdown log messages.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值