home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / server / Server-on-CD.iso / socd / usr / sbin / apachectl < prev    next >
Encoding:
Text File  |  2003-09-04  |  7.2 KB  |  246 lines

  1. #!/bin/sh
  2. #
  3. # Apache control script designed to allow an easy command line interface
  4. # to controlling Apache.  Written by Marc Slemko, 1997/08/23
  5. # The exit codes returned are:
  6. #    0 - operation completed successfully
  7. #    1 - 
  8. #    2 - usage error
  9. #    3 - httpd could not be started
  10. #    4 - httpd could not be stopped
  11. #    5 - httpd could not be started during a restart
  12. #    6 - httpd could not be restarted during a restart
  13. #    7 - httpd could not be restarted during a graceful restart
  14. #    8 - configuration syntax error
  15. #
  16. # When multiple arguments are given, only the error from the _last_
  17. # one is reported.  Run "apachectl help" for usage info
  18. #
  19. #
  20. # |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
  21. # --------------------                              --------------------
  22. # the path to your PID file
  23. PIDFILE=/var/run/httpd.pid
  24. #
  25. # the path to your httpd binary, including options if necessary
  26. HTTPD=/usr/sbin/httpd
  27. #
  28. # a command that outputs a formatted text version of the HTML at the
  29. # url given on the command line.  Designed for lynx, however other
  30. # programs may work.  
  31. LYNX="lynx -dump"
  32. #
  33. # the URL to your server's mod_status status page.  If you do not
  34. # have one, then status and fullstatus will not work.
  35. STATUSURL="http://localhost/server-status"
  36. #
  37. # --------------------                              --------------------
  38. # ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||
  39.  
  40. ERROR=0
  41. ARGV="$@"
  42. if [ "x$ARGV" = "x" ] ; then 
  43.     ARGS="help"
  44. fi
  45.  
  46. for ARG in $@ $ARGS
  47. do
  48.     # check for pidfile
  49.     if [ -f $PIDFILE ] ; then
  50.     PID=`cat $PIDFILE`
  51.     if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
  52.         STATUS="httpd (pid $PID) running"
  53.         RUNNING=1
  54.     else
  55.         STATUS="httpd (pid $PID?) not running"
  56.         RUNNING=0
  57.     fi
  58.     else
  59.     STATUS="httpd (no pid file) not running"
  60.     RUNNING=0
  61.     fi
  62.  
  63.     case $ARG in
  64.     start)
  65.     if [ $RUNNING -eq 1 ]; then
  66.         echo "$0 $ARG: httpd (pid $PID) already running"
  67.         continue
  68.     fi
  69.     if $HTTPD ; then
  70.         echo "$0 $ARG: httpd started"
  71.     else
  72.         echo "$0 $ARG: httpd could not be started"
  73.         ERROR=3
  74.     fi
  75.     ;;
  76.     startssl|sslstart|start-SSL)
  77.     if [ $RUNNING -eq 1 ]; then
  78.         echo "$0 $ARG: httpd (pid $PID) already running"
  79.         continue
  80.     fi
  81.     if $HTTPD -DSSL; then
  82.         echo "$0 $ARG: httpd started"
  83.     else
  84.         echo "$0 $ARG: httpd could not be started"
  85.         ERROR=3
  86.     fi
  87.     ;;
  88.     stop)
  89.     if [ $RUNNING -eq 0 ]; then
  90.         echo "$0 $ARG: $STATUS"
  91.         continue
  92.     fi
  93.     if kill $PID ; then
  94.         echo "$0 $ARG: httpd stopped"
  95.     else
  96.         echo "$0 $ARG: httpd could not be stopped"
  97.         ERROR=4
  98.     fi
  99.     ;;
  100.     restart)
  101.     if [ $RUNNING -eq 0 ]; then
  102.         echo "$0 $ARG: httpd not running, trying to start"
  103.         if $HTTPD ; then
  104.         echo "$0 $ARG: httpd started"
  105.         else
  106.         echo "$0 $ARG: httpd could not be started"
  107.         ERROR=5
  108.         fi
  109.     else
  110.         if $HTTPD -t >/dev/null 2>&1; then
  111.         if kill -HUP $PID ; then
  112.             echo "$0 $ARG: httpd restarted"
  113.         else
  114.             echo "$0 $ARG: httpd could not be restarted"
  115.             ERROR=6
  116.         fi
  117.         else
  118.         echo "$0 $ARG: configuration broken, ignoring restart"
  119.         echo "$0 $ARG: (run 'apachectl configtest' for details)"
  120.         ERROR=6
  121.         fi
  122.     fi
  123.     ;;
  124.     graceful)
  125.     if [ $RUNNING -eq 0 ]; then
  126.         echo "$0 $ARG: httpd not running, trying to start"
  127.         if $HTTPD ; then
  128.         echo "$0 $ARG: httpd started"
  129.         else
  130.         echo "$0 $ARG: httpd could not be started"
  131.         ERROR=5
  132.         fi
  133.     else
  134.         if $HTTPD -t >/dev/null 2>&1; then
  135.         if kill -USR1 $PID ; then
  136.             echo "$0 $ARG: httpd gracefully restarted"
  137.         else
  138.             echo "$0 $ARG: httpd could not be restarted"
  139.             ERROR=7
  140.         fi
  141.         else
  142.         echo "$0 $ARG: configuration broken, ignoring restart"
  143.         echo "$0 $ARG: (run 'apachectl configtest' for details)"
  144.         ERROR=7
  145.         fi
  146.     fi
  147.     ;;
  148.     status)
  149.     $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
  150.     ;;
  151.     fullstatus)
  152.     $LYNX $STATUSURL
  153.     ;;
  154.     configtest)
  155.     if $HTTPD -t; then
  156.         :
  157.     else
  158.         ERROR=8
  159.     fi
  160.     ;;
  161.     *)
  162.     echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)"
  163.     cat <<EOF
  164.  
  165. start      - start httpd
  166. startssl   - start httpd with SSL enabled
  167. stop       - stop httpd
  168. restart    - restart httpd if running by sending a SIGHUP or start if 
  169.              not running
  170. fullstatus - dump a full status screen; requires lynx and mod_status enabled
  171. status     - dump a short status screen; requires lynx and mod_status enabled
  172. graceful   - do a graceful restart by sending a SIGUSR1 or start if not running
  173. configtest - do a configuration syntax test
  174. help       - this screen
  175.  
  176. EOF
  177.     ERROR=2
  178.     ;;
  179.  
  180.     esac
  181.  
  182. done
  183.  
  184. exit $ERROR
  185.  
  186. ## ====================================================================
  187. ## The Apache Software License, Version 1.1
  188. ##
  189. ## Copyright (c) 2000 The Apache Software Foundation.  All rights
  190. ## reserved.
  191. ##
  192. ## Redistribution and use in source and binary forms, with or without
  193. ## modification, are permitted provided that the following conditions
  194. ## are met:
  195. ##
  196. ## 1. Redistributions of source code must retain the above copyright
  197. ##    notice, this list of conditions and the following disclaimer.
  198. ##
  199. ## 2. Redistributions in binary form must reproduce the above copyright
  200. ##    notice, this list of conditions and the following disclaimer in
  201. ##    the documentation and/or other materials provided with the
  202. ##    distribution.
  203. ##
  204. ## 3. The end-user documentation included with the redistribution,
  205. ##    if any, must include the following acknowledgment:
  206. ##       "This product includes software developed by the
  207. ##        Apache Software Foundation (http://www.apache.org/)."
  208. ##    Alternately, this acknowledgment may appear in the software itself,
  209. ##    if and wherever such third-party acknowledgments normally appear.
  210. ##
  211. ## 4. The names "Apache" and "Apache Software Foundation" must
  212. ##    not be used to endorse or promote products derived from this
  213. ##    software without prior written permission. For written
  214. ##    permission, please contact apache@apache.org.
  215. ##
  216. ## 5. Products derived from this software may not be called "Apache",
  217. ##    nor may "Apache" appear in their name, without prior written
  218. ##    permission of the Apache Software Foundation.
  219. ##
  220. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  221. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  222. ## OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  223. ## DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  224. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  225. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  226. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  227. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  228. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  229. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  230. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  231. ## SUCH DAMAGE.
  232. ## ====================================================================
  233. ##
  234. ## This software consists of voluntary contributions made by many
  235. ## individuals on behalf of the Apache Software Foundation.  For more
  236. ## information on the Apache Software Foundation, please see
  237. ## <http://www.apache.org/>.
  238. ##
  239. ## Portions of this software are based upon public domain software
  240. ## originally written at the National Center for Supercomputing Applications,
  241. ## University of Illinois, Urbana-Champaign.
  242. ##
  243.