Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Paste Description for Someone

/etc/init.d/apache2

Someone
Tuesday, March 20th, 2007 at 7:20:16pm UTC 

  1. #!/bin/bash -e
  2. #
  3. # apache2              This init.d script is used to start apache2.
  4. #                     It basically just calls apache2ctl.
  5.  
  6. ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
  7.  
  8. #edit /etc/default/apache2 to change this.
  9. NO_START=0
  10.  
  11. set -e
  12. if [ -x /usr/sbin/apache2 ] ; then
  13.         HAVE_APACHE2=1
  14. else
  15.         exit 0
  16. fi
  17.  
  18. . /lib/lsb/init-functions
  19.  
  20. test -f /etc/default/rcS && . /etc/default/rcS
  21. test -f /etc/default/apache2 && . /etc/default/apache2
  22. if [ "$NO_START" != "0" -a "$1" != "stop" ]; then
  23.         [ "$VERBOSE" != "no" ] && log_warning_msg "Not starting apache2 - edit /etc/default/apache2 and change NO_START to be 0.";
  24.         exit 0;
  25. fi
  26.  
  27. APACHE2="$ENV /usr/sbin/apache2"
  28. APACHE2CTL="$ENV /usr/sbin/apache2ctl"
  29.  
  30. apache_stop() {
  31.         PID=""
  32.         PIDFILE=""
  33.         AP_CONF=/etc/apache2/apache2.conf
  34.  
  35.         # apache2 allows more than PidFile entry in the config but only the
  36.         # last found in the config is used; we attempt to follow includes
  37.         # here, but only first-level includes are supported, not nested ones
  38.  
  39.         for i in $AP_CONF `awk '$1 ~ /^\s*[Ii]nclude$/ && $2 ~ /^\// {print $2}' $AP_CONF`; do
  40.                 PIDFILE=`grep -i ^PidFile $i | tail -n 1 | awk '{print $2}'`
  41.                 if [ -e "$PIDFILE" ]; then
  42.                         PID=`cat $PIDFILE`
  43.                 fi
  44.         done
  45.        
  46.         errors=`$APACHE2 -t 2>&1`
  47.         if [ $? = 0 ]; then
  48.                 # if the config is ok than we just stop normaly
  49.  
  50.                 if [ -n "$PID" ]
  51.                 then
  52.                         $APACHE2CTL stop
  53.  
  54.                         CNT=0
  55.                         while [ 1 ]
  56.                         do
  57.                                 CNT=$(expr $CNT + 1)
  58.                
  59.                                 [ ! -d /proc/$PID ] && break
  60.  
  61.                                 if [ $CNT -gt 60 ]
  62.                                 then
  63.                                         if [ "$VERBOSE" != "no" ]; then
  64.                                                 echo " ... failed!"
  65.                                                 echo "Apache2 failed to honor the stop command, please investigate the situation by hand."
  66.                                         fi
  67.                                         return 1
  68.                                 fi
  69.  
  70.                                 sleep 1
  71.                         done
  72.                 else
  73.                         if [ "$VERBOSE" != "no" ]; then
  74.                                 echo -n " ... no pidfile found! not running?"
  75.                         fi
  76.                 fi
  77.  
  78.         else
  79.                 [ "$VERBOSE" != "no" ] && echo "$errors"
  80.  
  81.                 # if we are here something is broken and we need to try
  82.                 # to exit as nice and clean as possible
  83.  
  84.                 # if pidof is null for some reasons the script exits automagically
  85.                 # classified as good/unknown feature
  86.                 PIDS=`pidof apache2` || true
  87.  
  88.                 REALPID=0
  89.                 # if there is a pid we need to verify that belongs to apache2
  90.                 # for real
  91.                 for i in $PIDS; do
  92.                         if [ "$i" = "$PID" ]; then
  93.                                 # in this case the pid stored in the
  94.                                 # pidfile matches one of the pidof apache
  95.                                 # so a simple kill will make it
  96.                                 REALPID=1
  97.                         fi
  98.                 done
  99.  
  100.                 if [ $REALPID = 1 ]; then
  101.                         # in this case everything is nice and dandy
  102.                         # and we kill apache2
  103.                         kill $PID
  104.                 else
  105.                         # this is the worst situation... just kill all of them
  106.                         #for i in $PIDS; do
  107.                         #       kill $i
  108.                         #done
  109.                         # Except, we can't do that, because it's very, very bad
  110.                         if [ "$PIDS" ] && [ "$VERBOSE" != "no" ]; then
  111.                                 echo " ... failed!"
  112.                                 echo "You may still have some apache2 processes running.  There are"
  113.                               echo "processes named 'apache2' which do not match your pid file,"
  114.                                 echo "and in the name of safety, we've left them alone.  Please review"
  115.                                 echo "the situation by hand."
  116.                         fi
  117.                         return 1
  118.                 fi
  119.         fi
  120. }
  121.  
  122. # Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
  123. case $1 in
  124.         start)
  125.                 [ -f /etc/apache2/httpd.conf ] || touch /etc/apache2/httpd.conf
  126.                 # ssl_scache shouldn't be here if we're just starting up.
  127.                 [ -f /var/run/apache2/ssl_scache ] && rm -f /var/run/apache2/*ssl_scache*
  128.                 # /var/run and /var/lock could be on a tmpfs
  129.                 [ ! -d /var/run/apache2 ] && mkdir /var/run/apache2
  130.                 [ ! -d /var/lock/apache2 ] && mkdir /var/lock/apache2
  131.                 # Make sure /var/lock/apache2 has the correct permissions
  132.                 chown www-data /var/lock/apache2
  133.  
  134.                 log_begin_msg "Starting apache 2.0 web server..."
  135.                 if $APACHE2CTL startssl; then
  136.                         log_end_msg 0
  137.                 else
  138.                         log_end_msg 1
  139.                 fi
  140.         ;;
  141.         stop)
  142.                 log_begin_msg "Stopping apache 2.0 web server..."
  143.                 if apache_stop; then
  144.                         log_end_msg 0
  145.                 else
  146.                         log_end_msg 1
  147.                 fi
  148.         ;;
  149.         reload)
  150.                 log_begin_msg "Reloading apache 2.0 configuration..."
  151.                 if $APACHE2CTL graceful $2 ; then
  152.                         log_end_msg 0
  153.                 else
  154.                         log_end_msg 1
  155.                 fi
  156.         ;;
  157.         restart | force-reload)
  158.                 log_begin_msg "Forcing reload of apache 2.0 web server..."
  159.                 if ! apache_stop; then
  160.                         log_end_msg 1
  161.                 fi
  162.                 if $APACHE2CTL startssl; then
  163.                         log_end_msg 0
  164.                 else
  165.                         log_end_msg 1
  166.                 fi
  167.         ;;
  168.         status)
  169.                 exit 4
  170.         ;;
  171.         *)
  172.                 echo "Usage: /etc/init.d/apache2 start|stop|restart|reload|force-reload" >&2
  173.                 exit 2
  174.         ;;
  175. esac

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right