Monday, June 8, 2015

How to install setup maven repository in jboss brms bpmsuite rhel7 centos7


This is quite simple thing.
If you are going to start jboss brms fresh instance without installing maven in your machine, you cannot start the server and it will ask you to set M2_HOME (M2_HOME is not set, cannot start kie workbench)
First you have to install apache maven in your machine,
Download the zip file from http://maven.apache.org/download.cgi site.
Then unzip the file,

#unzip apache-maven-bin.zip
 
Copy the extracted file to /opt/ like below and create a link to usr/bin/,

#cp apache-maven/ /opt/maven
#ln -s /opt/maven/bin/mvn /usr/bin/mvn
 
Now you have to setup environment variables using below commands.

#vi /etc/profile.d/maven.sh
 
Add the following contents:

#!/bin/bash
M2_HOME=/opt/maven
PATH=$M2_HOME/bin:$PATH
export M2_HOME
export PATH
export CLASSPATH=.
 
Save and close the file and give privileges using below command

#chmod +x /etc/profile.d/maven.sh
 
Run below command to make variables permanent,

#source /etc/profile.d/maven.sh

Now you have successfully installed maven in your machine,
Check maven version using below command

#mvn –-version

Note that if it says about permission problem in mvn, go to the directory location and give +x permissions to the file and again try to view version.

Now you have maven and you can start jboss brms without problems. But before starting the server you need to map jboss-brms-bpmsuite-<version>-maven-repository repository to your maven installation settings file.

First download brms repository from Redhat site.

By default there is no setting.xml file in your fresh maven installation location in ~/.m2

Create settings.xml file and insert below sample maven profile details to the settings.xml,

#cd ~/.m2
#vi settings.xml

Add below code,

<profile>
<id>jboss-brms-bpmsuite-repository</id>
<repositories>
<repository>
<id>jboss-brms-bpmsuite-repository</id>
<url>file://<repository_location></url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-brms-bpmsuite-plugin-repository</id>
<url>file://<repository_location></url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<!-- Optionally, make the repository active by default -->
<activeProfile>jboss-brms-bpmsuite-repository</activeProfile>
</activeProfiles>

After done this configuration, you have successfully installed the jboss brms and can run and access brms server without problems.

Thursday, June 4, 2015

How to write systemd service to start stop wso2 server in RHEL7 CentOS7



In rhel7/centos7 we use systemd services.

One of the major changes in RHEL  / CentOS 7.0 is the swtich to systemd, a system and service manager, that replaces SysV and Upstart used in previous releases of Red Hat Enterprise Linux. 

Ex.
#systemctl start myservice.service

Here I explain how to write systemd service in rhel7 to work with any wso2 (carbon) server.
Before creating systemd service we have create a service call file in your wso2Home/bin directory (if not exist a service file),

#cd <wso2HOME>/bin
#vi myService.sh

Then add below code to the file,

#!bin/sh
USER="user"           
PRODUCT_CODE="DSS"                               
CARBON_HOME="wso2HOME"               
LOCK_FILE="${CARBON_HOME}/wso2carbon.lck"
PID_FILE="${CARBON_HOME}/wso2carbon.pid"
CMD="${CARBON_HOME}/bin/wso2server.sh"  
JAVA_HOME="/opt/jdk1.7.0_60"          

export JAVA_HOME=$JAVA_HOME

# Status the service
status() {
 if [ -f $PID_FILE ]
     then
  PID=`cat $PID_FILE`
  ps -fp $PID > /dev/null 2>&1
  PIDVAL=$?
     else
  PIDVAL=3
 fi

 if [ $PIDVAL -eq 0 ]
     then
  echo "WSO2 $PRODUCT_CODE server is running ..."
     else
  echo "WSO2 $PRODUCT_CODE server is stopped."
 fi
 return $PIDVAL
}

# Start the service
start() {
 if [ -f $PID_FILE ]
     then
  PID=`cat $PID_FILE`
  ps -fp $PID > /dev/null 2>&1
  PIDVAL=$?
     else
  PIDVAL=3
 fi

 if [ $PIDVAL -eq 0 ]
     then
        echo "WSO2 $PRODUCT_CODE server is running ..."
     else
        echo -n "Starting WSO2 $PRODUCT_CODE server: "
        touch $LOCK_FILE
        su - $USER -c "$CMD start > /dev/null 2>&1 &"
        sleep 5
        if [ -f $PID_FILE ]
     then
   PID=`cat $PID_FILE`
   ps -fp $PID > /dev/null 2>&1
   PIDVAL=$?
   if [ $PIDVAL -eq 0 ]
       then
    echo "success"
       else
    echo "failure"
   fi
     else
   echo "failure"
   PIDVAL=2
        fi
 fi
 echo
 return $PIDVAL
}

# Restart the service
restart() {
 echo -n "Restarting WSO2 $PRODUCT_CODE server: "
 touch $LOCK_FILE
 su - $USER -c "$CMD restart > /dev/null 2>&1 &"
 sleep 15
 if [ -f $PID_FILE ]
     then
  PID=`cat $PID_FILE`
  ps -fp $PID > /dev/null 2>&1
  PIDVAL=$?
  if [ $PIDVAL -eq 0 ]
      then
   echo "success"
      else
   echo "failure"
  fi
     else
  echo "failure"
  PIDVAL=2
 fi
 echo
 return $PIDVAL
}

# Stop the service
stop() {
 if [ -f $PID_FILE ]
     then
  PID=`cat $PID_FILE`
  ps -fp $PID > /dev/null 2>&1
  PIDVAL=$?
  if [ $PIDVAL -eq 0 ]
      then
   echo -n "Stopping WSO2 $PRODUCT_CODE server: "
   su - $USER -c "$CMD stop > /dev/null 2>&1 &"
   rm -f $LOCK_FILE
   sleep 10
   PID=`cat $PID_FILE`
   ps -fp $PID > /dev/null 2>&1
   PIDVAL=$?
   if [ $PIDVAL -eq 0 ]
       then
    echo "failure"
    PIDVAL=2
       else
    echo "success"
    PIDVAL=0
   fi
      else
         echo "WSO2 $PRODUCT_CODE server is not running."
         PIDVAL=0
  fi
     else
        echo "WSO2 $PRODUCT_CODE server is not running."
        PIDVAL=0
 fi
 echo
 return $PIDVAL
}

### main logic ###
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
status)
    status
    ;;
restart|reload|condrestart)
    restart
    ;;
*)
   echo $"Usage: $0 {start|stop|restart|reload|status}"
   exit 1
esac
exit $?

Change first 7 lines with your data. Reffere exmples in comments.

Now let’s create systemd service,

Systemd services are located in /etc/systemd/system directory.go to the directory,

#cd /etc/systemd/system

Create a file with .service extention(this will be service you are going to use),

#vi myservice.service

Then add below code to your created file,

[Unit]
Description=Wso2 Identity Server
After=syslog.target network.target

[Service]
Type=oneshot
ExecStart=/<wso2serverHOME>/bin/myService.sh start
ExecStop=/<wso2serverHOME>/bin/ myService.sh stop
RemainAfterExit=yes
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=multi-user.target

That’s all. Now you have successfully created the systemd service.

Check the service using below commands and accessing wso2 product consoles,

#systemctl start myservice.service
#systemctl start myservice.service

** note that if you face any error starting stopping the service, check privileges granted to the service.