IchHabRecht icon

[BASH] CentOS service script for Apache HTTP Server

IchHabRecht | PRO | 01/16/15 11:16:10 AM UTC | 0 ⭐ | 477 👁️ | Never ⏰ | []
Bash |

2.8 KB

|

None

|

0 👍

/

0 👎

#!/bin/sh
#
# httpd          Start/Stop the the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
#              server implementing the current HTTP standards.
 
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: Start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an efficient and extensible \
#              server implementing the current HTTP standards.
### END INIT INFO
 
# Source function library.
. /etc/rc.d/init.d/functions
 
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
 
RETVAL=0
prog="httpd"
 
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
 
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=${CTL-/usr/sbin/apachectl}
exec=${PIDFILE-/usr/sbin/httpd}
exec_args=$OPTIONS
pidfile=${PIDFILE-/var/log/httpd/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
STOP_TIMEOUT=${STOP_TIMEOUT-10}
 
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $exec $exec_args
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
 
stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $exec
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
 
reload() {
        echo -n $"Reloading $prog: "
        if ! LANG=$HTTPD_LANG $exec $exec_args -t >&/dev/null; then
                RETVAL=6
                echo $"not reloading due to configuration syntax error"
                failure $"not reloading $httpd due to configuration syntax error"
        else
                # Force LSB behaviour from killproc
                LSB=1 killproc -p ${pidfile} $exec -HUP
                RETVAL=$?
                if [ $RETVAL -eq 7 ]; then
                        failure $"httpd shutdown"
                fi
        fi
        echo
}
 
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $exec
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart|try-restart)
        if status -p ${pidfile} $exec >&/dev/null; then
                stop
                start
        fi
        ;;
  force-reload|reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac
 
exit $RETVAL

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎