Creating an application resource apache2

Learn more about the commands or scripts to define an application resource.

When you define an application resource apache2, three commands or scripts must be provided by the user to:
  • Start the application.

  • Stop the application.

  • Query the status of the application.

These commands and scripts can be different ones. You can gather these functions into a single script, which has a command line parameter to select start, stop, or status actions. These scripts are often user-written. For more information about requirements for scripts, see IBM.Application resource class.

In this example, use the script
/cluster/scripts/apache2 
The script has the following content for a Linux® system:
#!/bin/bash

OPSTATE_ONLINE=1
OPSTATE_OFFLINE=2

Action=${1}

case ${Action} in
        start)
		        /usr/sbin/apache2ctl start >/dev/null 2>&1
		        logger -i -t "SAM-apache" "Apache started"
		        RC=0
		        ;;
	stop)
		        /usr/sbin/apache2ctl stop >/dev/null 2>&1
		        logger -i -t "SAM-apache" "Apache stopped"
		        RC=0
		        ;;
	status)
		        ps ax |grep -v "grep"|grep "/usr/sbin/httpd">/dev/null
		        if [ $? == 0 ]
		        then
			        RC=${OPSTATE_ONLINE}
		        else
			        RC=${OPSTATE_OFFLINE}
		        fi
		        ;;
esac
exit $RC
Note: The script must be accessible on all nodes with the same directory path. Distribute the script to the nodes where the web server runs before you create the RSCT web server resource. The existence of the start/stop/status script is checked on each node.
The RSCT resource definitions for application resource apache2 are created with the mkrsrc command. All resource characteristics can be passed as command line parameters, but the mkrsrc command also accepts a definition file in plain text format.
The second approach with a definition file named apache2.def is used, as in the following example:
PersistentResourceAttributes:
   Name="apache2" 
   StartCommand="/cluster/scripts/apache2 start"
   StopCommand="/cluster/scripts/apache2 stop"
   MonitorCommand="/cluster/scripts/apache2 status"
   MonitorCommandPeriod=5                               
   MonitorCommandTimeout=5                         
   NodeNameList={"node01","node02","node03"}       
   StartCommandTimeout=10                             
   StopCommandTimeout=10                              
   UserName="root"                                         
   ResourceType=1                                  
The resource definition can now be created with the mkrsrc command by specifying the location and name of the definition file.
mkrsrc -f apache2.def IBM.Application   
The command does not return any output upon successful execution. You can display the floating resource representation of apache2 by entering the lsrsrc command:
lsrsrc -s "Name='apache2' && ResourceType=1" IBM.Application
Resource Persistent Attributes for IBM.Application
resource 1: 
			Name                  = "apache2" 
			ResourceType          = 1 
			AggregateResource     = "0x3fff 0xffff 0x00000000 0x000000000x00000000 0x00000000" 
			StartCommand          = "/cluster/scripts/apache2 start" 
			StopCommand           = "/cluster/scripts/apache2 stop" 
			MonitorCommand        = "/cluster/scripts/apache2 status" 
			MonitorCommandPeriod  = 5 
			MonitorCommandTimeout = 5 
			StartCommandTimeout   = 10 
			StopCommandTimeout    = 10 
			UserName              = "root" 
			RunCommandsSync       = 1 
			ProtectionMode        = 0 
			HealthCommand         = "" 
			HealthCommandPeriod   = 10 
			HealthCommandTimeout  = 5 
			InstanceName          = "" 
			InstanceLocation      = "" 
			SetHealthState        = 0 
			MovePrepareCommand    = "" 
			MoveCompleteCommand   = "" 
			MoveCancelCommand     = "" 
			CleanupList           = {} 
			CleanupCommand        = "" 
			CleanupCommandTimeout = 10 
			ProcessCommandString  = ""
			ResetState            = 0 
			ReRegistrationPeriod  = 0 
			CleanupNodeList       = {} 
			MonitorUserName       = "" 
			ActivePeerDomain      = "SA_Domain" 
			NodeNameList          = {"node01","node02”,”node03"}

Make sure that the web server is not started by any other mechanism in your operating system environment, that is, your run-level settings in Linux. Do not define the resource when the application is already started and in use.

For more information about the displayed resource attributes in the command output, see IBM.Application resource class.