Build JBoss as a RedhatLinux System Service

Source: Internet
Author: User
Tags jboss application server
Article Title: Make JBoss A RedhatLinux system service. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories. How can JBoss be started when a Linux system is started?
 
Use the V script of Linux. Although there are some differences between categories, it is usually similar to this:
 
/Etc/rc. d/init. d/-contains the start and stop scripts (other types:/etc/init. d /)
 
/Etc/rc. (x)/-contains the link for starting and stopping the script with the S or K prefix (start or kill)
 
Users of different levels have different operation levels.
 
Rc1.d? Single User Mode
 
Rc2.d? Enable single-user network mode
 
Rc3.d? Multi-User Mode-start in text mode
 
Rc4.d? Undefined
 
Rc5.d? Multi-user mode? Start with X Window
 
Rc6.d? Close
 
Now we start to work:
 
Create a jboss user and install jboss.
 
Create a script named/etc/rc. d/init. d/jboss
 
Create a link named/etc/rc3.d/S84jboss
 
Optional methods:/etc/rc5.d/S84jboss and/etc/rc4.d/S84jboss
 
Create a link named/etc/rc6.d/K15jboss
 
Create a K15 link on/etc/rc1.d,/etc/rc2.d,/etc/rc0.d
 
Note that the $ JBOSS_HOME directory can be read and written by "jboss" users. If you have any questions, click to view the UNIX File System license recommended by the JBoss application server.
 
Create script jboss:
 
JBoss 4.0.1 +, with prebaked init script, jboss_init_redhat.sh and jboss_init_suse.sh in the bin directory. you can copy one of these scripts to/etc/rc. d/init. d/jboss. Because I use redhat, copy jboss_init_redhat.sh and modify it to executable.
 
[Root @ vm2 ~] # Cp $ JBOSS_HOME/bin/jboss_init_redhat.sh/etc/rc. d/init. d/jboss
 
[Root @ vm2 ~] # Chmod 755/etc/rc. d/init. d/jboss
 
$ JBOSS_HOME cannot be written in this way during your operations. It represents the directory installed on your jboss, and you need to replace it.
 
Edit it in the vi Editor:
 
  
#! /Bin/sh
#
# $ Id: jboss_init_redhat.sh 46554 10: 29: 13Z dimitris $
#
# JBoss Control Script
#
# To use this script run it as root-it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# For RedHat systems. It assumes that JBoss lives in/usr/local/jboss,
# It's run by user 'jbos' and JDK binaries are in/usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# The following variables are set correctly before calling the script.

# Change to the installation directory of your local jboss
JBOSS_HOME =$ {JBOSS_HOME:-"/home/jboss/jboss-4.0.5.GA "}

# Change to your new jboss user
JBOSS_USER =$ {JBOSS_USER:-"jboss "}

# Change to local java path
JAVAPTH =$ {JAVAPTH:-"/home/jboss/jdk1.5.0 _ 14/bin "}

# The STARTUP configuration parameters have three values: 'decimal', 'default', and 'all'. all indicates cluster mode configuration.
JBOSS_CONF =$ {JBOSS_CONF:-"default "}

# Bind all NICs. If one is bound, write your IP address. It is used only when jboss4.2.0 + is used externally.
# JBOSS_HOST =$ {JBOSS_HOST:-"0.0.0.0 "}

# The script is disabled by default. It seems that it is not easy to use and I will not use it.
# Jbosp_=$ {jbosp_:-"$ JBOSS_HOME/bin/shutdown. jar: $ JBOSS_HOME/client/jnet. jar "}

# Disable the script when binding an Ip address to an external service in jboss4.2.0 +
# Jbosp_=$ {jbosp_:-"$ JBOSS_HOME/bin/shutdown. sh-S-s $ JBOSS_HOST "}

# Jboss close the script
Jbosp_=$ {jbosp_:-"$ JBOSS_HOME/bin/shutdown. sh-S "}

# This is started when jboss4.2.0 + is used for external services.
# JBOSSSH =$ {JBOSSSH:-"$ JBOSS_HOME/bin/run. sh-c $ JBOSS_CONF-B $ JBOSS_HOST "}

# Jboss startup
JBOSSSH =$ {JBOSSSH:-"$ JBOSS_HOME/bin/run. sh-c $ JBOSS_CONF "}

If ["$ JBOSS_USER" = "RUNASIS"]; then
SUBIT = ""
Else
SUBIT = "su-$ JBOSS_USER-c"
Fi

If [-n "$ JBOSS_CONSOLE"-! -D "$ JBOSS_CONSOLE"]; then
# Ensure the file exists
Touch $ JBOSS_CONSOLE
If [! -Z "$ SUBIT"]; then
Chown $ JBOSS_USER $ JBOSS_CONSOLE
Fi
Fi

If [-n "$ JBOSS_CONSOLE"-! -F "$ JBOSS_CONSOLE"]; then
Echo "WARNING: location for saving console log invalid: $ JBOSS_CONSOLE"
# Self-start log
# Echo "WARNING: ignoring it and using/dev/null"
Echo "WARNING: ignoring it and using $ JBOSS_HOME/jbossAutoStart. log"

# Self-start log
# JBOSS_CONSOLE = "/dev/null"
JBOSS_CONSOLE =$ {JBOSS_CONSOLE:-"$ JBOSS_HOME/jbossAutoStart. log "}
Fi

# Self-start log
# JBOSS_CONSOLE =$ {JBOSS_CONSOLE:-"/dev/null "}
JBOSS_CONSOLE =$ {JBOSS_CONSOLE:-"$ JBOSS_HOME/jbossAutoStart. log "}

JBOSS_CMD_START = "cd $ JBOSS_HOME/bin; $ JBOSSSH"
# This is the default one. It is not as easy as above.
# JBOSS_CMD_STOP =$ {JBOSS_CMD_STOP:-"java-classpath $ jbosin org. jboss. Shutdown -- shutdown-S "}
# My own method of disabling
JBOSS_CMD_STOP =$ {JBOSS_CMD_STOP:-"cd $ JBOSS_HOME/bin; $ jbopd "}

If [-z "'echo $ PATH | grep $ JAVAPTH '"]; then
Export PATH = $ PATH: $ JAVAPTH
Fi

If [! -D "$ JBOSS_HOME"]; then
Echo JBOSS_HOME does not exist as a valid directory: $ JBOSS_HOME
Exit 1
Fi
# This is the default console to print the startup script command. If it is uncomfortable, it will be disabled.
# Echo JBOSS_CMD_START = $ JBOSS_CMD_START

Case "$1" in
Start)
Echo "JBoss start .........."
Cd $ JBOSS_HOME/bin
If [-z "$ SUBIT"]; then
Eval $ JBOSS_CMD_START >$ {JBOSS_CONSOLE} 2> & 1 &
Else
$ SUBIT "$ JBOSS_CMD_START >$ {JBOSS_CONSOLE} 2> & 1 &"
Fi
;;
Stop)
Echo "JBoss stop ........."
If [-z "$ SUBIT"]; then
$ Jboss_assist_stop
Else
$ SUBIT "$ jboss_assist_stop"
Fi
;;
Restart)
Echo "JBoss restart ........"
$0 stop
Sleep 60
$0 start
;;
*)
Echo "usage: $0 (start | stop | restart | help )"
Esac

 
These scripts can send logs to/dev/null, but we still want to enter logs so that we can handle running errors. Therefore, we need to create a real file:
 
[Root @ vm2 ~] # Mkdir $ JBOSS_HOME/jbossAutoStart. log
 
[Root @ vm2 ~] # Chown-R jboss. jboss $ JBOSS_HOME/jbossAutoStart. log
 
Create link:
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc3.d/S84jboss
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc4.d/S84jboss
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc5.d/S84jboss
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc0.d/K15jboss
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc1.d/K15jboss
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc2.d/K15jboss
 
[Root @ vm2 ~] # Ln-s/etc/rc. d/init. d/jboss/etc/rc6.d/K15jboss
 
When you run the "service jboss start" command in Linux, it corresponds to the "S" link and "service jboss stop" command for the K link.
 
This is done.
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.