Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

WSO2 Carbon and any Carbon-based product can be run as a Linux service as described in the following sections:

Table of Contents

Prerequisites

Install JDK and set up the JAVA_HOME environment variable. For more information, see Installation Prerequisites.

Setting up CARBON_HOME

Extract the WSO2 product that you want to run as a Linux service and set the environment variable CARBON_HOME to the extracted product directory location.

Running the product as a Linux service

...

To run the product as a service, create a startup script and add it to the boot sequence. The basic structure of the startup script has three parts (i.e., start, stop and restart) as follows:

Code Block
#!/bin/bash
 
case “$1″ in
start)
   echo “Starting Service”
;;
stop)
   echo “Stopping Service”
;;
restart)
   echo “Restarting Service”
;;
*)
   echo $”Usage: $0 {start|stop|restart}”
exit 1
esac

For example, given below is a startup script written for WSO2 Application Server 5.2.0:

Code Block
languagejava
#! /bin/sh
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_07"

startcmd='/opt/WSO2/wso2as-5.2.0/bin/wso2server.sh start > /dev/null &'
restartcmd='/opt/WSO2/wso2as-5.2.0/bin/wso2server.sh restart > /dev/null &'
stopcmd='/opt/WSO2/wso2as-5.2.0/bin/wso2server.sh stop > /dev/null &'

case "$1" in
start)
   echo "Starting WSO2 Application Server ..."
   su -c "${startcmd}" user1
;;
restart)
   echo "Re-starting WSO2 Application Server ..."
   su -c "${restartcmd}" user1
;;
stop)
   echo "Stopping WSO2 Application Server ..."
   su -c "${stopcmd}" user1
;;
*)
   echo "Usage: $0 {start|stop|restart}"
exit 1
esac

In the above script, the server is started as a user by the name user1 rather than the root user. For example, su -c "${startcmd}" user1 

 

...

Add the script to /etc/init.d/ directory.

Info

If you want to keep the scripts in a location other than /etc/init.d/ folder, you can add a symbolic link to the script in /etc/init.d/ and keep the actual script in a separate location. Say your script name is appserver and it is in /opt/WSO2/ folder, then the commands for adding a link to /etc/init.d/ is as follows:

  • Make executable: sudo chmod a+x /opt/WSO2/appserver

  • Add a link to /etc/init.d/: sudo ln -snf /opt/WSO2/appserver /etc/init.d/appserver

Install the startup script to respective runlevels using the command update-rc.d. For example, give the following command for the sample script shown in step1:

Code Block
sudo update-rc.d appserver defaults 

...

runlevel is a mode of operation in Linux (or any Unix-style operating system). There are several runlevels in a Linux server and each of these runlevels is represented by a single digit integer. Each runlevel designates a different system configuration and allows access to a different combination of processes. 

...

Include Page
SHARED:Installing as a Linux Service
SHARED:Installing as a Linux Service