Discussion:
[ubuntu-us-mi] run apache and mysql as services at startup
Eric Beversluis
2011-09-18 16:20:24 UTC
Permalink
I've installed (and re-installed) apache and mysql using the Synaptic
Package Mgr on 11.04, but neither will run at startup, tho I can start
them manually.

I can't find any clear instructions on how to get them to run at
startup. Something on line says there should be a
'Systems-Administration-Services' option on my main menu, but it isn't
there. Other things say the installation should set them to run at
startup.

Does someone know exactly what I need to do to get them to run as
services?

Thanks.
Jeff Hanson
2011-09-18 23:40:11 UTC
Permalink
This post might be inappropriate. Click to display it.
Eric Beversluis
2011-09-19 00:49:07 UTC
Permalink
Here are some results. I don't know why this installation is giving me
so much grief. I have neither the technical knowledge nor the time to be
doing this kind of trouble-shooting. Should I just start over with a
fresh installation?

/etc/default has the ff for 'apache2' and nothing for 'mysql'(nor is
there a mysql file in /etc/rc2.d, but there is in /etc/init.d, which I
copy below).

/etc/default/apache2:
"
### htcacheclean settings ###

## run htcacheclean: yes, no, auto
## auto means run if /etc/apache2/mods-enabled/disk_cache.load exists
## default: auto
HTCACHECLEAN_RUN=auto

## run mode: cron, daemon
## run in daemon mode or as daily cron job
## default: daemon
HTCACHECLEAN_MODE=daemon

## cache size
HTCACHECLEAN_SIZE=300M

## interval: if in daemon mode, clean cache every x minutes
HTCACHECLEAN_DAEMON_INTERVAL=120

## path to cache
## must be the same as in CacheRoot directive
HTCACHECLEAN_PATH=/var/cache/apache2/mod_disk_cache

## additional options:
## -n : be nice
## -t : remove empty directories
HTCACHECLEAN_OPTIONS="-n"
"
=========
/etc/init.d/mysql (link):
"
#!/bin/sh -e
# upstart-job
#
# Symlink target for initscripts that have been converted to Upstart.

set -e

INITSCRIPT="$(basename "$0")"
JOB="${INITSCRIPT%.sh}"

if [ "$JOB" = "upstart-job" ]; then
if [ -z "$1" ]; then
echo "Usage: upstart-job JOB COMMAND" 1>&2
exit 1
fi

JOB="$1"
INITSCRIPT="$1"
shift
else
if [ -z "$1" ]; then
echo "Usage: $0 COMMAND" 1>&2
exit 1
fi
fi

COMMAND="$1"
shift


if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
ECHO=echo
else
ECHO=:
fi

$ECHO "Rather than invoking init scripts through /etc/init.d, use the
service(8)"
$ECHO "utility, e.g. service $INITSCRIPT $COMMAND"

case $COMMAND in
status)
$ECHO
$ECHO "Since the script you are attempting to invoke has been
converted to an"
$ECHO "Upstart job, you may also use the $COMMAND(8) utility, e.g.
$COMMAND $JOB"
$COMMAND "$JOB"
;;
start|stop)
$ECHO
$ECHO "Since the script you are attempting to invoke has been
converted to an"
$ECHO "Upstart job, you may also use the $COMMAND(8) utility, e.g.
$COMMAND $JOB"
if status "$JOB" 2>/dev/null | grep -q ' start/'; then
RUNNING=1
fi
if [ -z "$RUNNING" ] && [ "$COMMAND" = "stop" ]; then
exit 0
elif [ -n "$RUNNING" ] && [ "$COMMAND" = "start" ]; then
exit 0
fi
$COMMAND "$JOB"
;;
restart)
$ECHO
$ECHO "Since the script you are attempting to invoke has been
converted to an"
$ECHO "Upstart job, you may also use the stop(8) and then start(8)
utilities,"
$ECHO "e.g. stop $JOB ; start $JOB. The restart(8) utility is also
available."
if status "$JOB" 2>/dev/null | grep -q ' start/'; then
RUNNING=1
fi
if [ -n "$RUNNING" ] ; then
stop "$JOB"
fi
start "$JOB"
;;
reload|force-reload)
$ECHO
$ECHO "Since the script you are attempting to invoke has been
converted to an"
$ECHO "Upstart job, you may also use the reload(8) utility, e.g.
reload $JOB"
reload "$JOB"
;;
*)
$ECHO
$ECHO "The script you are attempting to invoke has been converted to
an Upstart" 1>&2
$ECHO "job, but $COMMAND is not supported for Upstart jobs." 1>&2
exit 1
esac
"
=========
TRYING 'sudo update-rc.d apache2 default', I get:
"
update-rc.d: warning: apache2 start runlevel arguments (none) do
not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: apache2 stop runlevel arguments (none) do not
match LSB Default-Stop values (0 1 6)
usage: update-rc.d [-n] [-f] <basename> remove
update-rc.d [-n] <basename> defaults [NN | SS KK]
update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .
update-rc.d [-n] <basename> disable|enable [S|2|3|4|5]
-n: not really
-f: force

The disable|enable API is not stable and might change in the
future.
"
=======
I went into /bin/init.d/apache2 (copied below) and uncommented the
"Default-Start" and "Default-Stop" lines. Now when I run 'sudo
update-rc.d apache2 default' I get:
?
update-rc.d: warning: /etc/init.d/apache2 missing LSB keyword
'default-start'

update-rc.d: warning: /etc/init.d/apache2 missing LSB keyword
'default-stop'

usage: update-rc.d [-n] [-f] <basename> remove
update-rc.d [-n] <basename> defaults [NN | SS KK]
update-rc.d [-n] <basename> start|stop NN runlvl [runlvl]
[...] .
update-rc.d [-n] <basename> disable|enable [S|2|3|4|5]
-n: not really
-f: force

The disable|enable API is not stable and might change in the future.
"
========
So in /etc/init.d/apache2 I changed "Default-Start" and "Default-Stop"
to "default-start" and "default-stop", but that gave the same result. No
apache starting at boot and no success with 'sudo update-rc.d apache2
default'.
=========
/bin/init.d/apache2:
"
#!/bin/sh
### BEGIN INIT INFO
# Provides: apache2
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
default-start: 2 3 4 5
default-stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop apache2 web server
### END INIT INFO

set -e

if [ -n "$APACHE_CONFDIR" ] ; then
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "$APACHE_CONFDIR}" ] ; then
DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
else
DIR_SUFFIX=
fi
elif [ "${0##*/apache2-}" != "$0" ] ; then
DIR_SUFFIX="-${0##*/apache2-}"
APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
else
DIR_SUFFIX=
APACHE_CONFDIR=/etc/apache2
fi
if [ -z "$APACHE_ENVVARS" ] ; then
APACHE_ENVVARS=$APACHE_CONFDIR/envvars
fi
export APACHE_CONFDIR APACHE_ENVVARS

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then
ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR"
fi
if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then
ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
fi


#edit /etc/default/apache2 to change this.
HTCACHECLEAN_RUN=auto
HTCACHECLEAN_MODE=daemon
HTCACHECLEAN_SIZE=300M
HTCACHECLEAN_DAEMON_INTERVAL=120
HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_disk_cache
HTCACHECLEAN_OPTIONS=""

APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD)
if [ -z "$APACHE_HTTPD" ] ; then
APACHE_HTTPD=/usr/sbin/apache2
fi
if [ ! -x $APACHE_HTTPD ] ; then
echo "No apache MPM package installed"
exit 0
fi

. /lib/lsb/init-functions

test -f /etc/default/rcS && . /etc/default/rcS

if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then
. /etc/default/apache2$DIR_SUFFIX
elif [ -f /etc/default/apache2 ] ; then
. /etc/default/apache2
fi

APACHE2CTL="$ENV /usr/sbin/apache2ctl"
HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"

PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)
if [ -z "$PIDFILE" ] ; then
echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2
exit 2
fi


check_htcacheclean() {
[ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1

[ "$HTCACHECLEAN_RUN" = "yes" ] && return 0

MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED)
[ "$HTCACHECLEAN_RUN" = "auto" \
-a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \
return 0

return 1
}

start_htcacheclean() {
if [ ! -d "$HTCACHECLEAN_PATH" ] ; then
echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2
return 1
fi
$HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
-i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
}

stop_htcacheclean() {
pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null ||
echo ...not running
}

pidof_apache() {
# if there is actually an apache2 process whose pid is in PIDFILE,
# print it and return 0.
if [ -e "$PIDFILE" ]; then
if pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then
return 0
fi
fi
return 1
}

apache_stop() {
if $APACHE2CTL configtest > /dev/null 2>&1; then
# if the config is ok than we just stop normaly
$APACHE2CTL stop 2>&1 | grep -v 'not running' >&2 ||
true
else
# if we are here something is broken and we need to try
# to exit as nice and clean as possible
PID=$(pidof_apache) || true

if [ "${PID}" ]; then
# in this case it is everything nice and dandy and we kill apache2
echo
log_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are
trying to kill it manually. This is almost certainly suboptimal, so
please make sure your system is working as you'd expect now!"
kill $PID
elif [ "$(pidof apache2)" ]; then
if [ "$VERBOSE" != no ]; then
echo " ... failed!"
echo "You may still have some apache2 processes running.
There are"
echo "processes named 'apache2' which do not match your pid
file,"
echo "and in the name of safety, we've left them alone.
Please review"
echo "the situation by hand."
fi
return 1
fi
fi
}

apache_wait_stop() {
# running ?
PIDTMP=$(pidof_apache) || true
if kill -0 "${PIDTMP:-}" 2> /dev/null; then
PID=$PIDTMP
fi

apache_stop

# wait until really stopped
if [ -n "${PID:-}" ]; then
i=0
while kill -0 "${PID:-}" 2> /dev/null; do
if [ $i = '60' ]; then
break;
else
if [ $i = '0' ]; then
echo -n " ... waiting "
else
echo -n "."
fi
i=$(($i+1))
sleep 1
fi
done
fi
}

case $1 in
start)
log_daemon_msg "Starting web server" "apache2"
if $APACHE2CTL start; then
if check_htcacheclean ; then
log_progress_msg htcacheclean
start_htcacheclean || log_end_msg 1
fi
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
if check_htcacheclean ; then
log_daemon_msg "Stopping web server" "htcacheclean"
stop_htcacheclean
log_progress_msg "apache2"
else
log_daemon_msg "Stopping web server" "apache2"
fi
if apache_wait_stop; then
log_end_msg 0
else
log_end_msg 1
fi
;;
graceful-stop)
if check_htcacheclean ; then
log_daemon_msg "Stopping web server" "htcacheclean"
stop_htcacheclean
log_progress_msg "apache2"
else
log_daemon_msg "Stopping web server" "apache2"
fi
if $APACHE2CTL graceful-stop; then
log_end_msg 0
else
log_end_msg 1
fi
;;
reload | force-reload | graceful)
if ! $APACHE2CTL configtest > /dev/null 2>&1; then
$APACHE2CTL configtest || true
log_end_msg 1
exit 1
fi
log_daemon_msg "Reloading web server config" "apache2"
if pidof_apache > /dev/null ; then
if $APACHE2CTL graceful $2 ; then
log_end_msg 0
else
log_end_msg 1
fi
fi
;;
restart)
if ! $APACHE2CTL configtest > /dev/null 2>&1; then
$APACHE2CTL configtest || true
log_end_msg 1
exit 1
fi
if check_htcacheclean ; then
log_daemon_msg "Restarting web server" "htcacheclean"
stop_htcacheclean
log_progress_msg apache2
else
log_daemon_msg "Restarting web server" "apache2"
fi
PID=$(pidof_apache) || true
if ! apache_wait_stop; then
log_end_msg 1 || true
fi
if $APACHE2CTL start; then
if check_htcacheclean ; then
start_htcacheclean || log_end_msg 1
fi
log_end_msg 0
else
log_end_msg 1
fi
;;
start-htcacheclean)
log_daemon_msg "Starting htcacheclean"
start_htcacheclean || log_end_msg 1
log_end_msg 0
;;
stop-htcacheclean)
log_daemon_msg "Stopping htcacheclean"
stop_htcacheclean
log_end_msg 0
;;
status)
PID=$(pidof_apache) || true
if [ -n "$PID" ]; then
echo "Apache2$DIR_SUFFIX is running (pid $PID)."
exit 0
else
echo "Apache2$DIR_SUFFIX is NOT running."
exit 1
fi
;;
*)
log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|
graceful-stop|restart|reload|force-reload|start-htcacheclean|
stop-htcacheclean|status}"
exit 1
;;
esac
"

=======
Post by Jeff Hanson
Check in /etc/default for config files for the servers. Many have
special "enable" entries for them that if not set will cause them to
refuse to start. The other location would be the rc.d directories
that control the init scripts. To change the entries (generally
symlinks with S## start, K## don't) use the "update-rc.d" command.
Note: normal runlevel is "2".
Post by Eric Beversluis
I've installed (and re-installed) apache and mysql using the Synaptic
Package Mgr on 11.04, but neither will run at startup, tho I can start
them manually.
I can't find any clear instructions on how to get them to run at
startup. Something on line says there should be a
'Systems-Administration-Services' option on my main menu, but it isn't
there. Other things say the installation should set them to run at
startup.
Does someone know exactly what I need to do to get them to run as
services?
Thanks.
--
ubuntu-us-mi mailing list
ubuntu-us-mi at lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-us-mi
Jeff Hanson
2011-09-19 04:19:16 UTC
Permalink
This post might be inappropriate. Click to display it.
Julia Christianson
2011-09-19 11:42:41 UTC
Permalink
Eric,

I haven't done much with services in Ubuntu, only Red Hat/Centos, so not
an expert here, but I did notice that you said

sudo update-rc.d apache2 default

but the syntax actually is

sudo update-rc.d apache2 defaults

('s' on the end of 'defaults'). So I'd suggest you put the scripts back
like they were and try update-rc.d with 'defaults'.

What's going on here: In order to get a service to start in a
particular runlevel, you need a file in the appropriate /etc/rc*.d
directory that starts with a capital S followed by a two-digit number
and the name of the service. This file is actually just a symlink to
the script that starts the service, e.g. /etc/rc2.d/S38httpd ->
/etc/init.d/httpd.

**BUT** (a) I only say rc2.d because someone just said that's the
default runlevel for Ubuntu (I never have been clear on that), (b) I
just made up '38'; the numbers indicate the order of execution and it
can be important, and (c) I'm not even sure that 'httpd' is the name of
the script in /etc/init.d/, all of which indicate it's better to get
something like update-rc.d to make that symlink for you.

-- Julia
jlay1984 at live.com ()
2011-09-20 12:01:11 UTC
Permalink
Sent from my HTC smartphone on the Now Network from Sprint!

----- Reply message -----
From: "Julia Christianson" <julia at nscjc.net>
To: "Ubuntu Michigan Local Community Team" <ubuntu-us-mi at lists.ubuntu.com>
Subject: [ubuntu-us-mi] run apache and mysql as services at startup
Date: Mon, Sep 19, 2011 7:42 am


Eric,

I haven't done much with services in Ubuntu, only Red Hat/Centos, so not an expert here, but I did notice that you said

sudo update-rc.d apache2 default

but the syntax actually is

sudo update-rc.d apache2 defaults

('s' on the end of 'defaults'). So I'd suggest you put the scripts back like they were and try update-rc.d with 'defaults'.

What's going on here: In order to get a service to start in a particular runlevel, you need a file in the appropriate /etc/rc*.d directory that starts with a capital S followed by a two-digit number and the name of the service. This file is actually just a symlink to the script that starts the service, e.g. /etc/rc2.d/S38httpd -> /etc/init.d/httpd.

**BUT** (a) I only say rc2.d because someone just said that's the default runlevel for Ubuntu (I never have been clear on that), (b) I just made up '38'; the numbers indicate the order of execution and it can be important, and (c) I'm not even sure that 'httpd' is the name of the script in /etc/init.d/, all of which indicate it's better to get something like update-rc.d to make that symlink for you.

-- Julia
--
ubuntu-us-mi mailing list
ubuntu-us-mi at lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-us-mi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-us-mi/attachments/20110920/dc1dcafd/attachment.html>
Loading...