LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Automatic Startup of Apache (http://www.linuxquestions.org/questions/linux-general-1/automatic-startup-of-apache-232379/)

m2azer 09-19-2004 02:08 AM

Automatic Startup of Apache
 
hello,

i am trying to get Apache to start automatically:
cp /usr/local/apache2/bin/apachect1 /etc/init.d/
then when i do /sbin/chkconfig --add apachect1
i get "service apachect1 does not suppoort chkconfig"
did anyone run into that before please let me know?
thanks alot

gypsy_rabbi 09-19-2004 06:28 AM

Short answer: the Apache daemon's name is httpd (apachectl is just a script that calls httpd with the appropriate arguments).

Slightly longer answer: In Fedora there's already an init script called /etc/init.d/httpd. This calls apachectl, which in turn calls the actual httpd daemon, so you don't need to add that to the list of services.

Instead, you can say:
/sbin/chkconfig --level 345 httpd on
(assuming you want Apache to run in runlevels 3, 4, and 5)

Or if you say system-config-services you'll get Fedora's service-control UI which will let you see what all your services are doing all at once.

m2azer 09-19-2004 01:16 PM

i don't have httpd script under /etc/init.d niether do i have it on the Service Configuration window.

thanks

gypsy_rabbi 09-19-2004 01:19 PM

How did you install Apache?

m2azer 09-19-2004 02:47 PM

i compiled the source code apache 2.0.51
./configure --enable-so --enable-rewrite --enable-deflate --enable-speling --enable-ssl --enable-usertrack

Path to installation is /usr/local/apache2

when i run /sbin/chkconfig --add /usr/local/apach2/bin/apachect1
this is the error:
error reading info on service /usr/local/apache2/: no such file or directory

Note: i had apache on when i installed fedora the RPM one and i uninstalled and i used to have httpd service as you mentioned but not anymore

thanks for your reply

gypsy_rabbi 09-19-2004 04:02 PM

A script in /etc/init.d needs to have chkconfig and description lines (as described in chkconfig's man page -- see the fifth and sixth lines in the code below) in order to get onto chkconfig's list.

I'm including the contents of Fedora's /etc/init.d/httpd below. You'll need to edit it to point the paths at your installation rather than Fedora's default, and add other options that you want (probably change start to startssl if you want it to run SSL-enabled, and so on).

Once you've done all that, you'll need to say
/sbin/chkconfig --add httpd

All that's if you want to do it right :). If you want a quick-and-dirty solution you can add a call to apachectl in /etc/rc.d/rc.local

I assume you're doing all this because you need something that's not in Fedora's default install?

Hope this helps.



Code:

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

# check for 1.3 configuration
check13 () {
        CONFFILE=/etc/httpd/conf/httpd.conf
        GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
        GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
        GONE="${GONE}AccessConfig|ResourceConfig)"
        if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
                echo
                echo 1>&2 " Apache 1.3 configuration directives found"
                echo 1>&2 " please read /usr/share/doc/httpd-2.0.50/migration.html"
                failure "Apache 1.3 config directives test"
                echo
                exit 1
        fi
}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        check13 || exit 1
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
        echo -n $"Reloading $prog: "
        check13 || exit 1
        killproc $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f ${pidfile} ] ; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $OPTIONS $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
        exit 1
esac

exit $RETVAL


jgt 09-20-2004 08:39 AM

m2azer: I suggest you to try, when it be possible, to install new software using RPM packages. This will avoid to experience this issues and you will have the choice to upgrade them using rpm -F command.


All times are GMT -5. The time now is 10:51 AM.