AIX: rc.httpd

Script for controlling IBM HTTP Server (or Apache) on AIX

#!/usr/bin/ksh

#======================================

#

# rc.httpd for Apache on AIX

# (c) 2o1o LGee,

#

#======================================

# set -x

# Initial version. Please report bugs, requests!

# === TODO: ===

# - don't stop/start if already done - apachectl doesn't use stderr for it

### vars

daemon=$(basename "$0" | sed 's/^rc//')

x_serverroot="/usr/IBM/HTTPServer"

x_envvars="$x_serverroot/bin/envvars"

x_httpdconf="$x_serverroot/conf/httpd.conf"

# x_httpdconf="$x_serverroot/conf/httpd.conf_20100705"

# x_httpdconf="/root/temp/httpd.conf_20100705"

x_pidfile="$x_serverroot"/$(awk '/^PidFile/ {print $2}' $x_httpdconf)

# x_extraopts="-DSSL"

# x_extraopts="-e warn"

x_scriptname="$0"

### base sanity checks and setup

if ! [ -d "$x_serverroot" ]; then

echo "ERROR: ServerRoot $x_serverroot is not a directory"

exit 1

fi

if ! [ -f "$x_httpdconf" ]; then

echo "ERROR: Config file $x_httpdconf doesn't exist"

exit 1

fi

# from the original apachectl script

if [ -f $x_envvars ]; then

. $x_envvars

fi

# from the original apachectl script

ULIMIT_MAX_FILES="ulimit -S -n unlimited"

if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then

$ULIMIT_MAX_FILES

fi

### main

case "$1" in [0,0/1989]

start)

# $x_serverroot/bin/apachectl -f $x_httpdconf -k start "$x_extraopts" \

$x_serverroot/bin/httpd -f $x_httpdconf -k start $x_extraopts \

&& echo "Starting $daemon: OK" \

|| echo "Starting $daemon: ERROR"

;;

stop)

# $x_serverroot/bin/apachectl -f $x_httpdconf -k stop \

$x_serverroot/bin/httpd -f $x_httpdconf -k stop \

&& echo "Stopping $daemon: OK" \

|| echo "Stopping $daemon: ERROR"

;;

restart)

"$x_scriptname" stop \

&& "$x_scriptname" start \

&& echo " Restarting $daemon: OK" \

|| echo " Restarting $daemon: ERROR"

;;

# There seems to be a problem with restart - the master process segfaults

# $x_serverroot/bin/httpd -f $x_httpdconf -k restart

testconf)

# $x_serverroot/bin/apachectl -f $x_httpdconf -t >/dev/null \

$x_serverroot/bin/httpd -f $x_httpdconf -t >/dev/null \

&& echo "Testing $daemon: OK" \

|| echo "Testing $daemon: ERROR"

;;

reload)

# $x_serverroot/bin/apachectl -f $x_httpdconf -k graceful \

$x_serverroot/bin/httpd -f $x_httpdconf -k graceful \

&& echo "Stopping $daemon: OK" \

|| echo "Stopping $daemon: ERROR"

;;

status)

# No PID file = no httpd

if ! [ -f "$x_pidfile" ]; then

echo "Checking $daemon: not running (no PID file)"

# PID file but no matching process = no httpd

elif [ empty$(ps -p $(<$x_pidfile) -o pid=) = "empty" ]; then

echo "Checking $daemon: not running (but there is a stale PID file)"

# There is something matching the PID in the PID file = httpd is running

else

echo "Checking $daemon: running (pid = $(cat $x_pidfile))"

fi

;;

*)

echo "Usage: $daemon [start|stop|status|reload|restart|testconf]"

;;

esac

### end