Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:08

0001 #!/bin/sh
0002 #
0003 # chkconfig: - 85 15
0004 #
0005 # description: Panda server webserver
0006 # processname: httpd
0007 # config: /etc/panda/panda_server-httpd.conf
0008 # config: /etc/sysconfig/httpd-pandasrv
0009 # pidfile: /var/run/panda/httpd-pandasrv.pid
0010 #
0011 # Copyright 2000-2004 The Apache Software Foundation
0012 #
0013 # Licensed under the Apache License, Version 2.0 (the "License");
0014 # you may not use this file except in compliance with the License.
0015 # You may obtain a copy of the License at
0016 #
0017 #     http://www.apache.org/licenses/LICENSE-2.0
0018 #
0019 # Unless required by applicable law or agreed to in writing, software
0020 # distributed under the License is distributed on an "AS IS" BASIS,
0021 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0022 # See the License for the specific language governing permissions and
0023 # limitations under the License.
0024 #
0025 #
0026 # Apache control script designed to allow an easy command line interface
0027 # to controlling Apache.  Written by Marc Slemko, 1997/08/23
0028 #
0029 # The exit codes returned are:
0030 #   XXX this doc is no longer correct now that the interesting
0031 #   XXX functions are handled by httpd
0032 #       0 - operation completed successfully
0033 #       1 -
0034 #       2 - usage error
0035 #       3 - httpd could not be started
0036 #       4 - httpd could not be stopped
0037 #       5 - httpd could not be started during a restart
0038 #       6 - httpd could not be restarted during a restart
0039 #       7 - httpd could not be restarted during a graceful restart
0040 #       8 - configuration syntax error
0041 #
0042 # When multiple arguments are given, only the error from the _last_
0043 # one is reported.  Run "apachectl help" for usage info
0044 #
0045 ARGV="$@"
0046 #
0047 # |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
0048 # --------------------                              --------------------
0049 #
0050 # virtual env activation
0051 @@virtual_env_setup@@
0052 
0053 # the path to application
0054 PROGNAME='python -u @@install_purelib@@/pandaserver/test/SchemaChecker.py'
0055 
0056 # the path to your httpd binary, including options if necessary
0057 HTTPD='/usr/sbin/httpd'
0058 
0059 # PID
0060 PID_OLD=/var/log/panda/panda_server_httpd.pid
0061 PID_NEW=/var/run/panda/panda_server_httpd.pid
0062 #
0063 # a command that outputs a formatted text version of the HTML at the
0064 # url given on the command line.  Designed for lynx, however other
0065 # programs may work.
0066 if [ -x /usr/bin/links ]; then
0067    LYNX="links -dump"
0068 elif [ -x /usr/bin/lynx ]; then
0069    LYNX="lynx -dump"
0070 else
0071    LYNX="none"
0072 fi
0073 
0074 #
0075 # the URL to your server's mod_status status page.  If you do not
0076 # have one, then status and fullstatus will not work.
0077 STATUSURL="http://localhost:25080/server-status"
0078 
0079 # Source /etc/sysconfig/httpd for $HTTPD setting, etc.
0080 if [ -r /etc/sysconfig/panda_server ]; then
0081    . /etc/sysconfig/panda_server
0082 fi
0083 
0084 ERROR=0
0085 if [ "x$ARGV" = "x" ] ; then
0086     ARGV="-h"
0087 fi
0088 
0089 
0090 # check if PanDA Schema is the correct one
0091 function check_schema() {
0092   return_string=`$PROGNAME`
0093   if [[ "$return_string" =~ .*OK ]]; then
0094     return 0
0095   else
0096     echo $return_string
0097     return 1
0098   fi
0099 }
0100 
0101 function check13() {
0102 # check for 1.3 configuration
0103 GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
0104 GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
0105 GONE="${GONE}AccessConfig|ResourceConfig)"
0106 if grep -Eiq "^[[:space:]]*($GONE)" /etc/httpd/conf/httpd.conf; then
0107   echo "$0: Apache 1.3 configuration directives found"
0108   echo "$0: please read /usr/share/doc/httpd-2.0.52/migration.html"
0109   exit 2
0110 fi
0111 }
0112 
0113 function checklynx() {
0114 if [ "$LYNX" = "none" ]; then
0115    echo "The 'links' package is required for this functionality."
0116    exit 8
0117 fi
0118 }
0119 
0120 function testconfig() {
0121 # httpd is denied terminal access in SELinux, so run in the
0122 # current context to get stdout from $HTTPD -t.
0123 if test -x /usr/sbin/selinuxenabled && /usr/sbin/selinuxenabled; then
0124   runcon -- `id -Z` $HTTPD $OPTIONS -t
0125 else
0126   $HTTPD $OPTIONS -t
0127 fi
0128 ERROR=$?
0129 }
0130 
0131 function check_pidfile () {
0132     if [ -r $PID_OLD ]; then
0133         COMSTR=`echo $HTTPD $OPTIONS -k $ARGV`
0134         COMSTR=`echo $COMSTR | sed -e 's/ //g'`
0135         PSOUT=`ps -f -p \`cat $PID_OLD\` | cat | tail -1`
0136         PSOUT=`echo $PSOUT | sed -e 's/ //g'`
0137         if [ ! `echo $PSOUT | grep $COMSTR` ]; then
0138             echo "check pid: deleting $PID_OLD"
0139             rm -rf $PID_OLD
0140             retval=0
0141         else
0142             echo "check pid: httpd is running"
0143             retval=1
0144         fi
0145     elif [ -r $PID_NEW ]; then
0146         COMSTR=`echo $HTTPD $OPTIONS -k $ARGV`
0147         COMSTR=`echo $COMSTR | sed -e 's/ //g'`
0148         PSOUT=`ps -f -p \`cat $PID_NEW\` | cat | tail -1`
0149         PSOUT=`echo $PSOUT | sed -e 's/ //g'`
0150         if [ ! `echo $PSOUT | grep $COMSTR` ]; then
0151             echo "check pid: deleting $PID_NEW"
0152             rm -rf $PID_NEW
0153             retval=0
0154         else
0155             echo "check pid: httpd is running"
0156             retval=1
0157         fi
0158     else
0159         echo "check_pid: no httpd"
0160         retval=0
0161     fi
0162     return "$retval"
0163 }
0164 
0165 function kill_remaining_httpd () {
0166     COMSTR=`echo $HTTPD $OPTIONS -k`
0167     COMSTR=`echo $COMSTR | sed -e 's/ //g'`
0168     USERID=`ps ax o user:16,cmd | awk '{out=gensub(/ /, "", "g", $0); print $1"\t"out}' | grep $COMSTR  | grep -v root | head -n1 | awk '{print $1}'`
0169     if [ -n "$USERID" ]; then
0170         echo trying to killall remaining httpd processes with uid=$USERID
0171         killall -q -v -s SIGKILL -u $USERID `basename $HTTPD`
0172     else
0173         echo all set as no remaining httpd
0174     fi
0175 }
0176 
0177 case $ARGV in
0178 restart|graceful)
0179     if $HTTPD -t >&/dev/null; then
0180        $HTTPD $OPTIONS -k $ARGV
0181        ERROR=$?
0182     else
0183        echo "apachectl: Configuration syntax error, will not run \"$ARGV\":"
0184        testconfig
0185     fi
0186     ;;
0187 start|stop)
0188     echo "$ARGV PanDA httpd"
0189     check13
0190     case $ARGV in
0191         start)
0192             check_schema
0193                 check_pidfile
0194     esac
0195     for itry in `seq 1 100`
0196     do
0197         echo $ARGV trying $itry
0198         $HTTPD $OPTIONS -k $ARGV
0199         ERROR=$?
0200             sleep 5
0201             if [ $ERROR = 0 ]; then
0202                 check_pidfile
0203                 retval=$?
0204                 case $ARGV in
0205                 start)
0206                     if [ "$retval" == 1 ]
0207                     then
0208                         echo $ARGV done
0209                         break
0210                     fi
0211                     ;;
0212                 stop)
0213                     if [ "$retval" == 0 ]
0214                         then
0215                             echo $ARGV done
0216                             break
0217                         fi
0218                         ;;
0219                 esac
0220             fi
0221             sleep 10
0222     done
0223     case $ARGV in
0224         stop)
0225             kill_remaining_httpd
0226     esac
0227     ;;
0228 startssl|sslstart|start-SSL)
0229     check13
0230     $HTTPD $OPTIONS -DSSL -k start
0231     ERROR=$?
0232     ;;
0233 configtest)
0234     testconfig
0235     ;;
0236 status)
0237     checklynx
0238     $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
0239     ;;
0240 fullstatus)
0241     checklynx
0242     $LYNX $STATUSURL
0243     ;;
0244 *)
0245     $HTTPD $OPTIONS $ARGV
0246     ERROR=$?
0247 esac
0248 
0249 exit $ERROR