Advertisement
IchHabRecht

[BASH] CentOS service script for Apache HTTP Server

Jan 16th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.80 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # httpd          Start/Stop the the Apache HTTP Server
  4. #
  5. # chkconfig: - 85 15
  6. # description: The Apache HTTP Server is an efficient and extensible \
  7. #              server implementing the current HTTP standards.
  8.  
  9. ### BEGIN INIT INFO
  10. # Provides: httpd
  11. # Required-Start: $local_fs $remote_fs $network $named
  12. # Required-Stop: $local_fs $remote_fs $network
  13. # Should-Start: distcache
  14. # Short-Description: Start and stop Apache HTTP Server
  15. # Description: The Apache HTTP Server is an efficient and extensible \
  16. #              server implementing the current HTTP standards.
  17. ### END INIT INFO
  18.  
  19. # Source function library.
  20. . /etc/rc.d/init.d/functions
  21.  
  22. if [ -f /etc/sysconfig/httpd ]; then
  23.         . /etc/sysconfig/httpd
  24. fi
  25.  
  26. RETVAL=0
  27. prog="httpd"
  28.  
  29. # Start httpd in the C locale by default.
  30. HTTPD_LANG=${HTTPD_LANG-"C"}
  31.  
  32. # Path to the apachectl script, server binary, and short-form for messages.
  33. apachectl=${CTL-/usr/sbin/apachectl}
  34. exec=${PIDFILE-/usr/sbin/httpd}
  35. exec_args=$OPTIONS
  36. pidfile=${PIDFILE-/var/log/httpd/httpd.pid}
  37. lockfile=${LOCKFILE-/var/lock/subsys/httpd}
  38. STOP_TIMEOUT=${STOP_TIMEOUT-10}
  39.  
  40. start() {
  41.         echo -n $"Starting $prog: "
  42.         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $exec $exec_args
  43.         RETVAL=$?
  44.         echo
  45.         [ $RETVAL = 0 ] && touch ${lockfile}
  46.         return $RETVAL
  47. }
  48.  
  49. stop() {
  50.         echo -n $"Stopping $prog: "
  51.         killproc -p ${pidfile} -d ${STOP_TIMEOUT} $exec
  52.         RETVAL=$?
  53.         echo
  54.         [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
  55. }
  56.  
  57. reload() {
  58.         echo -n $"Reloading $prog: "
  59.         if ! LANG=$HTTPD_LANG $exec $exec_args -t >&/dev/null; then
  60.                 RETVAL=6
  61.                 echo $"not reloading due to configuration syntax error"
  62.                 failure $"not reloading $httpd due to configuration syntax error"
  63.         else
  64.                 # Force LSB behaviour from killproc
  65.                 LSB=1 killproc -p ${pidfile} $exec -HUP
  66.                 RETVAL=$?
  67.                 if [ $RETVAL -eq 7 ]; then
  68.                         failure $"httpd shutdown"
  69.                 fi
  70.         fi
  71.         echo
  72. }
  73.  
  74. case "$1" in
  75.   start)
  76.         start
  77.         ;;
  78.   stop)
  79.         stop
  80.         ;;
  81.   status)
  82.         status -p ${pidfile} $exec
  83.         RETVAL=$?
  84.         ;;
  85.   restart)
  86.         stop
  87.         start
  88.         ;;
  89.   condrestart|try-restart)
  90.         if status -p ${pidfile} $exec >&/dev/null; then
  91.                 stop
  92.                 start
  93.         fi
  94.         ;;
  95.   force-reload|reload)
  96.         reload
  97.         ;;
  98.   graceful|help|configtest|fullstatus)
  99.         $apachectl $@
  100.         RETVAL=$?
  101.         ;;
  102.   *)
  103.         echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
  104.         RETVAL=2
  105. esac
  106.  
  107. exit $RETVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement