# Apache Crash in FreeBSD Jail



## overmind (Jun 12, 2014)

Hi,

I've just configured a jail on FreeBSD 9.2 AMD64. In that jail I run a web server with Apache. Every morning I have to start Apache since is not running. I assume It crashes at night, maybe when cron runs? The other useful information is that my SSH connection to that jail is also killed (ssh to real machine is not killed). Maybe somehow jail crashes and restart but Apache does not restart even if when I run /etc/rc.d/jail start, it knows how to start Apache (right when jail is starting).

Do you know what could be the problem, maybe somebody had this issue before? I had no such problem with jail in FreeBSD 8.x.


----------



## junovitch@ (Jun 12, 2014)

Odd, is there anything useful in /var/log/messages or Apache's log files?


----------



## overmind (Jun 16, 2014)

I have no errors in log files. I think I did not explained the issue properly. Apache is in fact not crashing but instead of displaying my webpage it prints the following message in web browser:


```
Apache is functioning normally
```

After an Apache restart, the page is displayed properly until next night when the problem will appear again.


----------



## junovitch@ (Jun 17, 2014)

That is odd.  Can you post your access.log and error.log for the time periods relevant?  Namely I'm looking to see that the client is attempting to access the index.html default page during both periods.  

Secondly. you mentioned sshd crashing as well.  Are you running Apache on the host system as well as the jail?  If the service in a jail is not running and you have not added specific configuration to stop services on the host from listening on all addresses, the connections "fall through" of sorts from the address of a jail to the host.  If the jail service is running on that address, it takes precedence over the service listening on all addresses on the host.


----------



## overmind (Jun 23, 2014)

The message:


```
Apache is functioning normally
```

was from the server outside of Jail that runs Apache. I've configured the server outside the Jail to only serve Apache on the other IPs, not on Jail IP. Now instead of this message our Apache from virtual machine will not respond. So the problem is every night at 22.00 houts I found Apache stopped. I've found no info in access.log and error.log regarding this issue. This is weird, I'll keep looking.

*Update:* I've added the following line to /etc/rc.conf file of the host machine:


```
rpcbind_enable="NO"
```

Hope this will solve the problem.


----------



## overmind (Jun 23, 2014)

overmind said:
			
		

> The message:
> 
> 
> ```
> ...


----------



## overmind (Jun 23, 2014)

It did not solve the problem. I've finally found an info in httpd-errors.log:


```
[Tue Jun 24 00:31:00.441030 2014] [mpm_prefork] [pid 65094] AH00169: caught SIGTERM, shutting down
```


----------



## junovitch@ (Jun 24, 2014)

rpcbind doesn't deal with binding to ports.  It's one of the services used to provide NFS.  By any change does that log message occur at the same time every day?  Is the a cron job running that could be doing this?


----------



## overmind (Jun 24, 2014)

junovitch said:
			
		

> rpcbind doesn't deal with binding to ports.  It's one of the services used to provide NFS.  By any change does that log message occur at the same time every day?  Is the a cron job running that could be doing this?



It crashes every night at 00.31 AM:


```
[Sun Jun 22 00:31:00.348064 2014] [mpm_prefork] [pid 62646] AH00169: caught SIGTERM, shutting down
[Mon Jun 23 00:31:00.292049 2014] [mpm_prefork] [pid 30622] AH00169: caught SIGTERM, shutting down
[Tue Jun 24 00:31:00.441030 2014] [mpm_prefork] [pid 65094] AH00169: caught SIGTERM, shutting down
```

At first *I* did not notice this error because I thought was from the times I've restarted Apache.

Here is my cron file from Jail machine:


```
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD: releng/9.2/etc/crontab 194170 2009-06-14 06:37:19Z brian $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
#
#minute	hour	mday	month	wday	who	command
#
*/5	*	*	*	*	root	/usr/libexec/atrun
#
# Save some entropy so that /dev/random can re-seed on boot.
*/11	*	*	*	*	operator /usr/libexec/save-entropy
#
# Rotate log files every hour, if necessary.
0	*	*	*	*	root	newsyslog
#
# Perform daily/weekly/monthly maintenance.
1	3	*	*	*	root	periodic daily
15	4	*	*	6	root	periodic weekly
30	5	1	*	*	root	periodic monthly
#
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
# UTC time.  See adjkerntz(8) for details.
1,31	0-5	*	*	*	root	adjkerntz -a
```

Should I remove adjkerntz line from crontab file?


----------



## junovitch@ (Jun 24, 2014)

I usually comment out the adjkerntz line in my jails just because it sometimes makes extra noise in the log since it can't actually do any thing inside the jail.  It shouldn't really matter but at the same time it shouldn't hurt anything to comment it out.  It shouldn't effect anything in this case since nothing happened when it ran at a minute past the hour.  It just so happens to be at 31 minutes past.  Honestly I'm a bit baffled right now and I haven't done enough serious Apache work to know what to recommend next.


----------



## overmind (Aug 21, 2014)

It seems DirectAdmin's Apache from base machine (and not jail restarts Apache every night in order to rotate logs. When Apache is restarted on base machine it stops on the virtual machine.

I don't know if it is a Directadmin issue or that when I try to restart an Apache web server on a FreeBSD machine  (without DirectAdmin) it will stop an Apache instance on a virtual machine. I'll try wihout DirectAdmin.


----------



## junovitch@ (Aug 21, 2014)

Does DirectAdmin do something crazy like `pkill apache` and then start it?  That seems like a very odd issue if it just starts and stops the service using the normal OS means.


----------

