Mikko Kortelainen

IBM Websphere Application Server 5.1 init script for Linux

WAS does not seem to install any default init scripts, so I created one. You can configure it to start and stop multiple application servers by listing them all in the APPSERVERS variable (separated by spaces).

#!/bin/sh
# chkconfig: 35 99 10
# description: Starts and stops Websphere Application Server

. /lib/lsb/init-functions

# Please edit these variables to match your environment. You may list one or more
# application servers separated by spaces in the APPSERVERS variable.

OWNER=wasadmin
USERNAME=wasuser
PASSWORD=secret
APPSERVERS="Appserver1"

WASDIR=/opt/WebSphere/AppServer
DMGRDIR=/opt/WebSphere/DeploymentManager
LOCKDIR=/var/lock/subsys

DMGRLOCK="$LOCKDIR/WAS_deploymentmgr"
NODEAGENTLOCK="$LOCKDIR/WAS_nodeagent"

# Don't edit beyond this point.

start_dmgr() {
  MSG="Starting WAS Deployment Manager"
  [[ ! -e $DMGRLOCK ]] \
      && su - $OWNER -c "$DMGRDIR/bin/startManager.sh -user $USERNAME -password $PASSWORD" \
      && touch $DMGRLOCK \
      && log_success_msg $MSG \
      || log_failure_msg $MSG
}

stop_dmgr() {
  MSG="Stopping WAS Deployment Manager"
  [[ -e $DMGRLOCK ]] \
    && [[ -e "$DMGRDIR/bin/stopManager.sh" ]] \
      && su - $OWNER -c "$DMGRDIR/bin/stopManager.sh -user $USERNAME -password $PASSWORD" \
      && rm -f $DMGRLOCK \
      && log_success_msg $MSG \
      || log_failure_msg $MSG
}

start_nodeagent() {
  MSG="Starting WAS Node Agent"
  [[ ! -e $NODEAGENTLOCK ]] \
    && su - $OWNER -c "$WASDIR/bin/startNode.sh -user $USERNAME -password $PASSWORD" \
    && touch $NODEAGENTLOCK \
    && log_success_msg $MSG \
    || log_failure_msg $MSG
}

stop_nodeagent() {
  MSG="Starting WAS Node Agent"
  [[ -e $NODEAGENTLOCK ]] \
    && su - $OWNER -c "$WASDIR/bin/stopNode.sh -user $USERNAME -password $PASSWORD" \
    && rm -f $NODEAGENTLOCK \
    && log_success_msg $MSG \
    || log_failure_msg $MSG
}

start_appservers() {
  for WAS in $APPSERVERS
  do
    MSG="Starting WAS: $WAS"
    LOCK="$LOCKDIR/WAS_$WAS"
    [[ ! -e $LOCK ]] \
      && su - $OWNER -c "$WASDIR/bin/startServer.sh $WAS -user $USERNAME -password $PASSWORD" \
      && touch $LOCK \
      && log_success_msg $MSG \
      || log_failure_msg $MSG
  done
}

stop_appservers() {
  for WAS in $APPSERVERS
  do
    MSG="Stopping WAS: $WAS"
    LOCK="$LOCKDIR/WAS_$WAS"
    [[ -e $LOCK ]] \
      && su - $OWNER -c "$WASDIR/bin/stopServer.sh $WAS -user $USERNAME -password $PASSWORD" \
      && rm -f $LOCK \
      && log_success_msg $MSG \
      || log_failure_msg $MSG
  done
}


case "$1" in
  'start')   [[ -e "$DMGRDIR/bin/startManager.sh" ]] && start_dmgr
             start_nodeagent
             start_appservers ;;
  'stop')    stop_appservers
             stop_nodeagent
             [[ -e "$DMGRDIR/bin/startManager.sh" ]] && stop_dmgr ;;
  'restart') stop_appservers
             stop_nodeagent
             [[ -e "$DMGRDIR/bin/startManager.sh" ]] && stop_dmgr
             sleep 5
             [[ -e "$DMGRDIR/bin/startManager.sh" ]] && start_dmgr
             start_nodeagent
             start_appservers ;;
  'status')  [[ -e $DMGRLOCK ]] \
               && echo WAS Deployment Manager is running (lockfile $DMGRLOCK) \
               || echo WAS Deployment Manager is stopped (no lockfile)
             [[ -e $NODEAGENTLOCK ]]
               && echo WAS Node Agent is running (lockfile $NODEAGENTLOCK) \
               || echo WAS Node Agent is stopped (no lockfile)
             for WAS in $APPSERVERS
             do
               LOCK="$LOCKDIR/WAS_$WAS"
               [[ -e $LOCK ]] \
                 && echo WAS $WAS is running (lockfile $LOCK) \
                 || echo WAS $WAS is stopped (no lockfile)
             done
             $WASDIR/bin/serverStatus.sh -all -user $USERNAME -password $PASSWORD
             ;;
  *)         echo "Usage: was (start|stop|restart|status)"
             exit 1 ;;
esac