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)
Christoph Galuschka 9c1bf5
#	  Christoph Galuschka <tigalch@tigalch.org>
Karanbir Singh 2dd0be
# Filename: 1_lamp_check.sh
Christoph Galuschka c04e6a
# Version: 0.2
Christoph Galuschka 9c1bf5
# Last Updated: Saturday, 09 November 2013 2:23
Karanbir Singh 2dd0be
# Description: A simple Bash script to start LAMP daemons (httpd, mysqld), and confirm PHP is working.
Karanbir Singh 2dd0be
Christoph Galuschka a76c03
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
Christoph Galuschka 9c1bf5
# 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
Christoph Galuschka 9c1bf5
        t_Log "Attempting startup of '$D'"
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
        $SERVICE $D start &>/dev/null
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
        RETVAL=$?
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
        if [ $RETVAL -ne 0 ]; then
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
                t_Log "FAIL: service startup for '$D' failed ($RETVAL)"
Christoph Galuschka 9c1bf5
                exit $FAIL
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
        fi
Christoph Galuschka 4a2a33
Christoph Galuschka 9c1bf5
        # See if our process exists
Christoph Galuschka 9c1bf5
        PIDS=$(pidof $D)
Karanbir Singh 2dd0be
Christoph Galuschka 9c1bf5
        if [ -z "$PIDS" ]; then
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
                t_Log "FAIL: couldn't find '$D' in the process list."
Christoph Galuschka 9c1bf5
                exit $FAIL
Christoph Galuschka 9c1bf5
        fi
Christoph Galuschka 9c1bf5
Christoph Galuschka 9c1bf5
        echo "OK"
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
Christoph Galuschka 9c1bf5
        t_Log "FAIL: php_info() check failed ($RETVAL)"
Karanbir Singh 2dd0be
Christoph Galuschka 2e276f
fi
Christoph Galuschka 2e276f
Christoph Galuschka 2e276f
t_CheckExitStatus $RETVAL