# Apache started twice after reboot



## olsen (Jul 13, 2010)

Hello,

Today I discovered an odd problem on one of my servers. After reboot, Apache is started twice:


```
# tail /var/log/httpd/httpd-error.log
[Tue Jul 13 07:02:19 2010] [notice] caught SIGTERM, shutting down
[Tue Jul 13 07:02:28 2010] [notice] caught SIGTERM, shutting down
[Tue Jul 13 07:05:04 2010] [notice] Digest: generating secret for digest authentication ...
[Tue Jul 13 07:05:04 2010] [notice] Digest: done
[Tue Jul 13 07:05:05 2010] [notice] Apache/2.2.15 (FreeBSD) DAV/2 PHP/5.2.13 with Suhosin-Patch configured -- resuming normal operations
[Tue Jul 13 07:05:06 2010] [notice] Digest: generating secret for digest authentication ...
[Tue Jul 13 07:05:06 2010] [notice] Digest: done
[Tue Jul 13 07:05:07 2010] [warn] pid file /var/run/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Tue Jul 13 07:05:07 2010] [notice] Apache/2.2.15 (FreeBSD) DAV/2 PHP/5.2.13 with Suhosin-Patch configured -- resuming normal operations
```
This causes twice the normal amount of httpd processes to be started. `apachectl stop` will only stop the processes started in the last round, so I need to use [cmd=]killall httpd[/cmd] and then [cmd=]apachectl start[/cmd] for a normal amount of processes to be started.

Anyone have any idea how to fix this so that Apache is only started once after a reboot?

---

What I have tried so far:

Setting 
	
	



```
apache22_enable="NO"
```
 in /etc/rc.conf causes apache not to start at all (as expected).

/usr/local/etc/apache22/httpd.conf is the exact same as on a few other servers that don't have this problem.

I also tried to recompile apache and all its dependencies, but that didn't help.

/var/log/messages shows nothing related to this.

---


```
# pkg_info -rx apache
Information for apache-2.2.15_9:

Depends on:
Dependency: expat-2.0.1_1
Dependency: perl-5.10.1_1
Dependency: pcre-8.02
Dependency: gdbm-1.8.3_3
Dependency: db42-4.2.52_5
Dependency: libiconv-1.13.1_1
Dependency: apr-ipv6-devrandom-gdbm-db42-1.4.2.1.3.9_1
```
---


```
# uname -v
FreeBSD 7.3-RELEASE-p2 #0: Mon Jul 12 19:23:19 UTC 2010     [email]root@amd64-
builder.daemonology.net[/email]:/usr/obj/usr/src/sys/GENERIC
```

---

Help on this would be greatly appreaciated!


----------



## Alt (Jul 13, 2010)

Show your /usr/local/etc/rc.d/apache*


----------



## olsen (Jul 13, 2010)

Here it comes:


```
# cat /usr/local/etc/rc.d/apache22
#!/bin/sh
#
# $FreeBSD: ports/www/apache22/files/apache22.in,v 1.7 2010/03/27 00:15:10 dougb Exp $
#

# PROVIDE: apache22
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable apache22:
# apache22_enable (bool):      Set to "NO" by default.
#                             Set it to "YES" to enable apache22
# apache22_profiles (str):     Set to "" by default.
#                              Define your profiles here.
# apache22limits_enable (bool):Set to "NO" by default.
#                             Set it to yes to run `limits $limits_args`
#                             just before apache starts.
# apache22_flags (str):        Set to "" by default.
#                             Extra flags passed to start command.
# apache22limits_args (str):   Default to "-e -C daemon"
#                             Arguments of pre-start limits run.
# apache22_http_accept_enable (bool): Set to "NO" by default.
#                             Set to yes to check for accf_http kernel
#                             module on start up and load if not loaded.
# apache22_fib (str):         Set an altered default network view for apache

. /etc/rc.subr

name="apache22"
rcvar=`set_rcvar`

start_precmd="apache22_prestart"
restart_precmd="apache22_checkconfig"
reload_precmd="apache22_checkconfig"
reload_cmd="apache22_graceful"
graceful_cmd="apache22_graceful"
gracefulstop_cmd="apache22_gracefulstop"
configtest_cmd="apache22_checkconfig"
command="/usr/local/sbin/httpd"
_pidprefix="/var/run/httpd"
pidfile="${_pidprefix}.pid"
required_files=/usr/local/etc/apache22/httpd.conf

[ -z "$apache22_enable" ]       && apache22_enable="NO"
[ -z "$apache22limits_enable" ] && apache22limits_enable="NO"
[ -z "$apache22limits_args" ]   && apache22limits_args="-e -C daemon"
[ -z "$apache22_http_accept_enable" ] && apache22_http_accept_enable="NO"
[ -z "$apache22_fib" ] && apache22_fib="NO"

apache22_accf() {

  if checkyesno apache22_http_accept_enable; then
    /sbin/kldstat -v | grep accf_http > /dev/null 2>&1 || /sbin/kldload accf_http || return ${?}
    /sbin/kldstat -v | grep accf_data > /dev/null 2>&1 || /sbin/kldload accf_data || return ${?}
  else
    apache22_flags="${apache22_flags} -DNOHTTPACCEPT"
  fi
}

load_rc_config $name

if [ -n "$2" ]; then
        profile="$2"
        if [ "x${apache22_profiles}" != "x" ]; then
                pidfile="${_pidprefix}.${profile}.pid"
                eval apache22_configfile="\${apache22_${profile}_configfile:-}"
                if [ "x${apache22_configfile}" = "x" ]; then
                        echo "You must define a configuration file (apache22_${profile}_configfile)"
                        exit 1
                fi
                required_files="${apache22_configfile}"
                eval apache22_enable="\${apache22_${profile}_enable:-${apache22_enable}}"
                eval apache22_flags="\${apache22_${profile}_flags:-${apache22_flags}}"
                eval apache22_http_accept_enable="\${apache22_${profile}_http_accept_enable:-${apache22_http_accept_enable}}"
                eval apache22limits_enable="\${apache22limits_${profile}_enable:-${apache22limits_enable}}"
                eval apache22limits_args="\${apache22limits_${profile}_args:-${apache22limits_args}}"
                eval apache22_fib="\${apache22_${profile}_fib:-${apache22_fib}}"
                apache22_flags="-f ${apache22_configfile} -c \"PidFile ${pidfile}\" ${apache22_flags}"
        else
                echo "$0: extra argument ignored"
        fi
else
        if [ "x${apache22_profiles}" != "x" -a "x$1" != "x" ]; then
                for profile in ${apache22_profiles}; do
                        eval _enable="\${apache22_${profile}_enable}"
                        case "x${_enable:-${apache22_enable}}" in
                        x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee])
                                continue
                                ;;
                        x[Yy][Ee][Ss])
                                ;;
                        *)
                                if test -z "$_enable"; then
                                        _var=apache22_enable
                                else
                                        _var=apache22_"${profile}"_enable
                                fi
                                echo "Bad value" \
                                    "'${_enable:-${apache22_enable}}'" \
                                    "for ${_var}. " \
                                    "Profile ${profile} skipped."
                                continue
                                ;;
                        esac
                        echo "===> apache22 profile: ${profile}"
                        /usr/local/etc/rc.d/apache22 $1 ${profile}
                        retcode="$?"
                        if [ "0${retcode}" -ne 0 ]; then
                                failed="${profile} (${retcode}) ${failed:-}"
                        else
                                success="${profile} ${success:-}"
                        fi
                done
                exit 0
        fi
fi

if [ "${1}" != "stop" ] ; then \
        apache22_accf
fi

apache22_requirepidfile()
{
    apache22_checkconfig

        if [ ! "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then
                echo "${name} not running? (check $pidfile)."
                exit 1
        fi
}

apache22_checkconfig()
{
        if test -f /usr/local/sbin/envvars
        then
                . /usr/local/sbin/envvars
        fi

        echo "Performing sanity check on apache22 configuration:"
        eval ${command} ${apache22_flags} -t
}

apache22_graceful() {
        apache22_requirepidfile

        echo "Performing a graceful restart"
        eval ${command} ${apache22_flags} -k graceful
}

apache22_gracefulstop() {
        apache22_requirepidfile

        echo "Performing a graceful stop"
        eval ${command} ${apache22_flags} -k graceful-stop
}

apache22_precmd()
{
        apache22_checkconfig

        if checkyesno apache22limits_enable
        then
                eval `/usr/bin/limits ${apache22limits_args}` 2>/dev/null
        else
                return 0
        fi

}

apache22_checkfib () {
        sysctl net.fibs >/dev/null 2>&1
        ret=$?
        [ $ret -gt 0 ] && return 0
        if [ "x$apache22_fib" != "xNO" ]
        then
                command="setfib -F ${apache22_fib} ${command}"
        else
                return  0
        fi
}

apache22_prestart() {
        apache22_checkfib
        apache22_precmd
}

extra_commands="reload graceful gracefulstop configtest"
run_rc_command "$1"
```


----------



## DutchDaemon (Jul 13, 2010)

*Format your posts!*


----------



## Alt (Jul 13, 2010)

Maybe you have a copy of startscript in rc.d ? watchdog in cron?


----------



## olsen (Jul 15, 2010)

Alt said:
			
		

> Maybe you have a copy of startscript in rc.d ? watchdog in cron?



No, nothing like that. I wish it was that simple.


----------



## Alt (Jul 16, 2010)

You can modify scripts then, to log how many times it started and other info.. Really strange problem


----------



## olsen (Jul 16, 2010)

I found the problem. The previous server administrator had placed a startup script for apache under /etc/rc.d/ :q


----------



## Alt (Jul 16, 2010)

I bet he was a linuxoid


----------

