7.5. Run the Application Server as a Service

Procedure 7.4. Run as a Service on Microsoft Windows

  1. Open a command prompt with elevated privileges.

    Navigate to C:\Windows\System32 and right-click on cmd.exe. Select Run as Administrator.
  2. Change to the Enterprise Application Platform directory where the service installation script is located.

    cd JBOSS_DIST\native\sbin
  3. Optional: Edit services.bat to pass parameters to the Application Server at start-up.

    Under :cmdStart, alter the following line:
    call "%SVCPATH%\run.bat" < .r.lock >> run.log 2>&1
    To run the 'default' profile binding to the 'localhost' address, change to the following: call "%SVCPATH%\run.bat" -c default -b localhost < .r.lock >> run.log 2>&1
    For a full list of parameters to run.bat see the Getting Started Guide.
  4. Run the service installation script.

    service.bat install
  5. Check that the service is installed.

    Under the Windows services list you will find this listed by the short name JBEAP5SVC and the long name JBoss EAP 5.

    Note

    To uninstall the service, issue the following command from a command prompt with elevated privileges: sc delete "JBEAP5SVC".

Procedure 7.5. Run as a Service on Red Hat Enterprise Linux

  1. Add a JBoss User

    With root privileges, use the adduser command with the -r parameter to create a system user account for use by the JBoss Enterprise Application Platform. Do this as the root user.
    [localhost]$ su -
    [localhost]# adduser -r jboss
  2. Assign ownership of files

    Use the chown and chgrp commands on the installation directory to change the owner and group of the JBoss Enterprise Application Platform files to the user created in the previous step.
    [localhost]# chown -R jboss jboss-eap-5.1
    [localhost]# chgrp -R jboss jboss-eap-5.1
  3. Navigate to the /bin directory.

    In a terminal, execute the following command to change into the directory containing the jboss_init_* scripts.
    [home]$ cd $JBOSS_HOME/bin
    [bin]$
  4. Edit jboss_init_redhat.sh

    The script jboss_init_redhat.sh in the bin directory is the script used to launch the server as a service. Append the following lines to the beginning of this script so that the first four lines below the initial comments look like those below.
    #!/bin/sh
    #chkconfig: 2345 85 15
    #description: JBoss Enterprise Application Platform
    #processname: jboss
    These lines are needed by the chkconfig command.
    Note that the chkconfig option specifies the runlevel, start priority, and stop priority. 2345 specifies the server will start only in runlevels 2, 3, 4, and 5.
  5. Set values in jboss_init_redhat.sh

    Edit jboss_init_redhat.sh in the bin directory so that the variables match the installation. The script variables are listed below.
    JBOSS_HOME
    This is the path of the JBoss Enterprise Application Platform's jboss-as directory. This value must be set here.
    The example sets it to /opt/jboss-eap-5.1/jboss-as.
    JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss-eap-5.1/jboss-as"}
    JBOSS_USER
    This is the user created previously for running the JBoss Enterprise Application Platform.
    The example sets it to the user name of jboss.
    JBOSS_USER=${JBOSS_USER:-"jboss"}
    JBOSS_CONF
    This is the name of the server configuration that the server will be using.
    The example sets it to default. The profiles available to use are contained in the /jboss-as/server/ directory.
    JBOSS_CONF=${JBOSS_CONF:-"default"}
    JBOSS_HOST
    JBOSS_HOST must be specified when binding the JBoss Enterprise Application Platform server to a specific IP address. This must be done before JBOSS_HOST is used by JBOSS_BIND_ADDR.
    This must be configured to make the server available on the network. The default configuration binds the server to the IP address of 127.0.0.1.
    The example sets it to 10.1.1.83
    #if JBOSS_HOST specified, use -b to bind jboss services to that address
    JBOSS_HOST=10.1.1.83                                
    JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
  6. Link script into init.d

    Create a symbolic link to jboss_init_redhat.sh in the directory /etc/init.d/. The name of the target of the symbolic link is the name of the new service.
    The example uses the name jboss_eap.
    [localhost]# ln -s /opt/jboss-eap-5.1/bin/jboss_init_redhat.sh /etc/init.d/jboss_eap
  7. Activate Service

    Use the command chkconfig with the --add parameter to add the new service to the system configuration.
    The example uses the service name of jboss_eap.
    [localhost]# chkconfig --add jboss_eap
  8. Configure Startup and Shutdown Behavior

    Use the command chkconfig with the on parameter to start the service at boot time, and stop it gracefully when the server hosting the application server is shut down or restarted.
    The example uses the service name of jboss_eap.
    [localhost]# chkconfig jboss_eap on
  9. Disable Service

    Use the command chkconfig with the off parameter to disable the jboss_eap service from starting when the server starts.
    [localhost]# chkconfig jboss_eap off