Results 1 to 10 of 38

Thread: Install jboss as daemon (autostart at boot)

Threaded View

  1. #1
    Join Date
    Jul 2006
    Location
    Sweden
    Beans
    52
    Distro
    Ubuntu 11.04 Natty Narwhal

    Install jboss as daemon (autostart at boot)

    Alterative

    Here is an alternative solution, since this guide is quite outdated (though it should still work). Thank you Monti

    Quote Originally Posted by monti View Post
    I've created a fairly robust init script for JBoss here: https://jira.jboss.org/jira/browse/JBPAPP-3194

    The /etc/init.d/jboss script doesn't need editing, all configuration is done in /etc/default/jboss

    All feedback is welcome.

    The actual guide

    Introduction

    This guide will let you run jboss as a daemon, that means you'll have a jboss instance that starts a computer boot. When you download jboss you get some example init scripts for different distributions but none for ubuntu. I did however get it to work with minor changes to the red hat init script. This is how I did it, there might be some better way and if you find better solutions than the ones in this guide please let me now and I'll post them here.

    At the end of this tutorial you will have (if everything goes as planned) a jboss instance running that starts at computer boot with the help of a daemon script in /etc/init.d/. To keep things tidy jboss will have a separate user called jboss as process owner.

    Ubuntu versions tested

    Ubuntu 7.10 32 bit Server Version
    Ubuntu 7.10 32 bit Desktop Version

    Step 1: Install suns jdk

    There have been problems reported with jboss and java 6 in the past. I don't know if there still is compatibility issues but to be safe I use java 5.

    Code:
    sudo apt-get install sun-java5-jdk
    Step 2: create the jboss user

    The reason to use a separate user account for jboss is to control the permissions of the jboss instance. You don't want jboss running as root with unlimited access to the whole system. There is no password created for the jboss user, and you probably don't need one either (unless you actually want to login as the jboss user).

    Code:
    sudo mkdir /home/jboss
    sudo useradd -s /bin/bash -d /home/jboss jboss
    sudo chown jboss:jboss /home/jboss/
    Step 3: Download jboss

    Go to http://labs.jboss.com/jbossas/downloads/ and get the latest stable version of jboss (4.2.2.GA when this guide was written). Download it to your home directory.
    Now you have a file in ~/jboss-4.2.2.GA.zip

    I used unzip to extract the archive, to install it run
    Code:
    sudo apt-get install unzip
    but feel free to extract it with what ever program you feel fit.

    sidenote:
    When I installed jboss on my server I installed it in the /opt/folder instead of /home/jboss/. Where ever you decide to put jboss make sure the jboss user has read and write permission to the jboss folder and it's subfiles/-folders.

    Move it to jboss home and extract it. To make a future upgrade of jboss a little easier a symlinc to jboss home is created. When you decide to upgrade jboss you'll just have to edit the symlinc to point to the new version.

    Code:
    cd ~
    sudo mv jboss-4.2.2.GA.zip /home/jboss/jboss-4.2.2.GA.zip
    sudo chown jboss:jboss /home/jboss/jboss-4.2.2.GA.zip
    sudo su jboss
    cd ~
    unzip jboss-4.2.2.GA.zip
    ln -s jboss-4.2.2.GA jboss
    exit
    Step 5:Get the init scriptt

    All the changes to the red hat init script is in the setup section in the beginning of the script. If you followed my guide to the letter you can download my version of the script thats attached to this post. If you installed java or jboss in other directories it's probably easier to edit the script your self.

    Option 1: download my script

    Download the scriptattached to this post to your home folder then run this to move it to the correct folder.

    Code:
    sudo mv ~/jboss/jboss_init.sh /etc/init.d/jboss
    End option 1


    Option 2: edit the original red hat script yourself.

    Copy the red hat init script to the init.d directory and rename it.

    Code:
    sudo cp /home/jboss/jboss/bin/jboss_init_redhat.sh /etc/init.d/jboss
    This is all the changes I made to the scipt, nothing fancy, just som variables for jboss that needs to be set correct.

    Code:
    #define where jboss is - this is the directory containing directories log, bin, conf etc
    
    JBOSS_HOME=${JBOSS_HOME:-"/home/jboss/jboss"}
    
    #define the user under which jboss will run, or use 'RUNASIS' to run as the current user
    
    JBOSS_USER=${JBOSS_USER:-"jboss"}
    
    #make sure java is in your path
    
    JAVAPTH=${JAVAPTH:-"/usr/lib/jvm/java-1.5.0-sun"}
    
    #configuration to use, usually one of 'minimal', 'default', 'all'
    
    JBOSS_CONF=${JBOSS_CONF:-"default"}
    
    #the host where jboss should answer. o.o.o.o means answer all calls. set this to yourhost.com
    
    JBOSS_HOST=${JBOSS_HOST:-"0.0.0.0"}
    
    # Uncomment this line to store the console output, otherwise it's sent to /dev/null
     (good for debugging)
    # JBOSS_CONSOLE=${JBOSS_CONSOLE:-"$JBOSS_HOME/server/$JBOSS_CONF/log/console.log"}
    End option 2


    Step 6: Install the init script

    Make your script owned by root and executable.
    Create run level shortcuts for the script.

    Code:
    sudo chown root:root /etc/init.d/jboss
    sudo chmod ug+x /etc/init.d/jboss
    sudo update-rc.d jboss defaults
    To start jboss you type

    Code:
    sudo /etc/init.d/jboss start
    If everything has gone as planned you should now have a functional installation of jboss that will start itself on computer boot.

    Step 7: Redirecting traffic from port 80 to jboss port 8080 (Optional)

    The default port for jboss is 8080 but the standard port for http traffic is 80. Port 80 is however a restricted port and can only be bound by root. To get around this little pickle you can redirect the incoming traffic on port 80 to 8080, the same goes for the https traffic on port 443 to jboss 8443. Here's a way to do that.

    Code:
    iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080 
    iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080 
    iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443 
    iptables -t nat -A PREROUTING -p udp -m udp --dport 443 -j REDIRECT --to-ports 8443
    This forward script was originally found here, http://www.2nrds.com/port-forwarding-in-linux

    Remove
    If you found a better way to do this or if you just don't want this installed anymore here's what you do.

    Warning! All files will be removed from your sytem.

    Remove the init daemon script
    Code:
    sudo /etc/init.d/jboss stop
    sudo update-rc.d jboss remove
    sudo rm /etc/init.d/jboss
    Remove jboss files and user
    Code:
    sudo userdel jboss
    sudo rm -r /home/jboss
    Remove java
    Code:
    sudo apt-get remove sun-java5-jdk
    Remove unzip
    Code:
    sudo apt-get remove unzip

    End

    That's all for me. This is my first ubuntu guide and my knowledge about linux is a bit limited. So if you think I made some bad decisions in this setup please let me know and we can make this guide better together.
    Attached Files Attached Files
    Last edited by CuBone; February 10th, 2011 at 08:36 PM. Reason: Minor scriptchanges suggested by codelion

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •