Blame tests/r_lamp/1_lamp_check.sh

Karanbir Singh 2dd0be
#!/bin/bash
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
# Author: Steve Barnes (steve@echo.id.au)
Karanbir Singh 2dd0be
# Filename: 1_lamp_check.sh
Karanbir Singh 2dd0be
# Version: 0.1
Karanbir Singh 2dd0be
# Last Updated: Saturday, 30 April 2011 2:23 PM AEST
Karanbir Singh 2dd0be
# Description: A simple Bash script to start LAMP daemons (httpd, mysqld), and confirm PHP is working.
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
readonly DAEMONS=( httpd mysqld )
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
readonly SERVICE=/sbin/service
Karanbir Singh 2dd0be
readonly PHP_BIN=/usr/bin/php
Karanbir Singh 2dd0be
readonly PHP_CHECK=/tmp/check.php
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
# Make sure we cleanup after ourselves.
Karanbir Singh 2dd0be
trap "/bin/rm -f $PHP_CHECK" EXIT
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
t_Log "Running $0 - starting LAMP daemon startup test"
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
# Iterate through our daemons, start each and check for the presence of each process
Karanbir Singh 2dd0be
for D in "${DAEMONS[@]}"
Karanbir Singh 2dd0be
do
Karanbir Singh 2dd0be
	t_Log "Attempting startup of '$D'"
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
	$SERVICE $D start &>/dev/null
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
	RETVAL=$?
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
	if [ $RETVAL -ne 0 ]; then
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
		t_Log "FAIL: service startup for '$D' failed ($RETVAL)"
Karanbir Singh 2dd0be
		exit $FAIL
Karanbir Singh 2dd0be
		
Karanbir Singh 2dd0be
	fi
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
	# See if our process exists
Karanbir Singh 2dd0be
	PIDS=$(pidof $D)
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
	if [ -z "$PIDS" ]; then
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
		t_Log "FAIL: couldn't find '$D' in the process list."
Karanbir Singh 2dd0be
		exit $FAIL
Karanbir Singh 2dd0be
	fi
Karanbir Singh 2dd0be
	
Karanbir Singh 2dd0be
	echo "OK"
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
done
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
# Finally, a basic check to see if PHP is working correctly.
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
t_Log "Performing php script check..."
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
cat <<EOL > $PHP_CHECK
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
return phpinfo();
Karanbir Singh 2dd0be
?>
Karanbir Singh 2dd0be
EOL
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
RETVAL=$PHP_BIN $PHP_CHECK &>/dev/null
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
if [ $RETVAL -ne 0 ]; then
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
	t_Log "FAIL: php_info() check failed ($RETVAL)"
Karanbir Singh 2dd0be
	exit $FAIL
Karanbir Singh 2dd0be
Karanbir Singh 2dd0be
fi