Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache shutdown - Couldn't grab mutex

For some reasons unknow to me, Apache is crashing.

This is the apache log at the moment of the crash:

[Sat Jun 02 02:38:05.196006 2018] [mpm_prefork:emerg] [pid 1122] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.196006 2018] [mpm_prefork:emerg] [pid 1116] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.198767 2018] [mpm_prefork:emerg] [pid 1115] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.199523 2018] [mpm_prefork:emerg] [pid 3924] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.204189 2018] [mpm_prefork:emerg] [pid 1937] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.207362 2018] [mpm_prefork:emerg] [pid 1120] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:06.057310 2018] [core:alert] [pid 1099] AH00050: Child 1115 returned a Fatal error... Apache is exiting!
[Sat Jun 02 02:38:06.057483 2018] [:emerg] [pid 1099] AH02818: MPM run failed, exiting

The last thing I did on the server lately was to install certbot to general HTTPS certificates for my sites.

like image 887
Preciel Avatar asked Jun 02 '18 01:06

Preciel


3 Answers

While Sean solution is valid, I learned another way to solve this problem.

First, you should know that this problem is related to using Certbot and SSL certificates on Ubuntu.

Now, to solve the problem without doing anything you're unsure of, simply do this (as root or with sudo):

  1. Create the following file: /etc/apache2/conf-available/mutex.conf
  2. Add Mutex file:${APACHE_LOCK_DIR} default inside the newly created file
  3. Enable new configuration file with a2enconf mutex
  4. Restart Apache with systemctl restart apache2 or systemctl reload apache2

But hey, it's already enabled by default! Why make a file just for that?

I though the same when I found this solution.

By one wonder or another, it seems that once your start using SSL certificates, this configuration line is somehow "ignored".
Thus, Apache fail to find the lock dir for the mutex file.

Just adding (remove comment) this line into /etc/apache2/apache2.conf isn't working either.
You have to specifically create a configuration file and enable it.
Else it won't solve the problem.

like image 125
Preciel Avatar answered Oct 23 '22 10:10

Preciel


I was experiencing the same error on Ubuntu 17.10 with Apache 2.4.27.

It appears to have to do with Apache talking to the OS about file locking. When I went into /etc/apache2/apache2.conf and added Mutex flock to the Mutex section (near the ServerRoot section), it seems to have solved the problem.

Unfortunately, all I can say is that this uses the flock() function (a system call?) to handle file locking. Per https://httpd.apache.org/docs/2.4/mod/core.html#mutex

So it's a bit of a black magic fix in that I personally am not familiar enough with Apache's file locking behavior to say why it works, and I can only say it works because the Apache crash seems to have stopped, but only thus far. Nevertheless, it may help you and seems fairly low-risk.

like image 30
Sean Hogge Avatar answered Oct 23 '22 09:10

Sean Hogge


Below steps worked out for me in my case.

  1. Connect to the server via SSH

  2. Edit the /etc/apache2/apache2.conf file. Below command I used nano editor and you can use your favorite editor

sudo nano /etc/apache2/apache2.conf

  1. Search for "Mutex" section

  2. Add the below line,

Mutex posixsem

  1. Save and close the file.

  2. Check the configuration before restarting Apache service by running the command,

sudo apachectl configtest

  1. Restart the Apache service if everything is fine with above check,

sudo service apache2 restart

Hope this helps someone.

like image 5
Muniraj Avatar answered Oct 23 '22 09:10

Muniraj