Start apache service mix on linux boot

I'm running apache service mix 5.1.2.  I'd like to have it start up as service in ubuntu when I boot linux.  How can I accomplish this?
LVL 6
HyperBPPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
First you need a shell script that starts up the products.  If you look in /etc/init.d, you'll see many scripts used during the startup sequence to serve as examples of how to do this.

This is by far the biggest stumbling block -- writing a shell script that both (a) starts up the software as you want it started up, and (b) does it legally and acceptably according to the proper method.

You may find it easier to write individual scripts for each individual product and execute them in the proper order if there are interdependencies.  For this, the "provides" and "required-start" parameters are helpful.  update-rc.d (see bottom) will sort out the dependencies for you and start the products in the required order as long as the "required-start" parameters are set properly.

Below is the /etc/init.d/apache script from my own system:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          apache
# Required-Start:    $syslog networking
# Required-Stop:     $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     S 2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Apache
# Description:       Provides the Apache web server
### END INIT INFO
#
# apache        Start the apache HTTP server.
#
# The variables below should not normally be changed.  They are there to make the
# script more readable.

NAME=apache
# Don't use the Debian default; our install is custom
# DAEMON=/usr/sbin/$NAME
DAEMON=/usr/local/apache2/bin/httpd
# Don't use the Debian default; our install is custom
# PIDFILE=/var/run/$NAME.pid
PIDFILE=/usr/local/apache2/logs/httpd.pid
# Don't use the Debian default; our install is custom
# CONF=/etc/$NAME/httpd.conf
CONF=/usr/local/apache2/conf/httpd.conf
# Don't use the Debian default; our install is custom
# APACHECTL=/usr/sbin/${NAME}ctl
APACHECTL=/usr/local/apache2/bin/apachectl
# note: SSD is required only at startup of the daemon.
SSD=`which start-stop-daemon`
ENV="env -i LANG=C PATH=/bin:/usr/bin:/usr/local/bin"

trap "" 1

# Check that we're not being started by inetd
if egrep -q -i "^[[:space:]]*ServerType[[:space:]]+inet" $CONF
then
    exit 0
fi

test_config() {
    if [ ! -x $APACHECTL ]; then
        echo "$APACHECTL is not executable, exiting"
        exit 0
    fi

    # ensure we don't leak environment vars into apachectl
    APACHECTL="$ENV $APACHECTL"

    if ! $APACHECTL configtest 2> /dev/null
    then
        printf "Configuration syntax error detected. Not reloading.\n\n"
        $APACHECTL configtest
        exit 1
    fi
}

should_start() {
    if [ ! -x $DAEMON ]; then
        echo "apache is not executable, not starting"
        exit 0
    fi
}

case "$1" in
  start)
    should_start
    test_config
    echo "Starting web server: $NAME"
#   $ENV $SSD --start --pidfile $PIDFILE --exec $DAEMON > /dev/null
    $APACHECTL start
    ;;

  stop)
    echo "Stopping web server: $NAME"
#   start-stop-daemon --stop --pidfile $PIDFILE --oknodo
    $APACHECTL stop
    ;;

  reload | force-reload)
    test_config
    echo "Reloading $NAME configuration"
    start-stop-daemon --stop --pidfile $PIDFILE --signal USR1
    ;;

  restart)
    test_config
    echo "Restarting $NAME"
    if ! start-stop-daemon -q --stop --pidfile $PIDFILE --signal HUP; then
        $ENV $SSD --start --pidfile $PIDFILE --exec $DAEMON > /dev/null
    fi
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart}"
    exit 1
    ;;
esac

if [ $? -eq 0 ]; then
        exit 0
else
        echo " failed"
        exit 1
fi

Open in new window


Copy the script to /etc/init.d and and use chmod to make sure that it's executable.  Set the protection bits to 755.

Then use update-rc.d to add the script to the startup scripts.

update-rc.d (scriptfilename) defaults

Open in new window


After this comes more debugging.  It's probable that the script won't work the first, second or tenth time, and the only way to test it is by rebooting the system, looking at the syslog, and checking operation to see if it started correctly.

If you think this is a colossal hassle, you are correct.  debian (Ubuntu is based on debian) installs both the packages and the startup scripts for you if you use apt-get install ... but the resulting installation is the debian "stable" packages, not the latest.  If you want to use anything other than the debian distribution packages the only way to do it reliably is by rolling your own shell script.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.