12

The server is running fine -- or at least it seems to -- but there's always the following error:

apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)

It happens with Apache 2.2.22-9 on Debian Wheezy.

# apache2ctl configtest

/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
Syntax OK

# service apache2 reload

[....] Reloading web server config: apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
. ok

# service apache2 restart

[....] Restarting web server: apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
... waiting /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
. ok

# service apache2 status

Apache2 is running (pid 32045).

  • 1
    Have a look at what you have in /etc/security/limits.conf and /etc/security/limits.d. It seems that you have APACHE_ULIMIT_MAX_FILES (see it in /usr/sbin/apache2ctl) variable set to something larger than the limit in that files. – HUB Aug 6 '12 at 9:44
16

This might help:- http://ubuntuforums.org/showthread.php?p=11950245#post11950245

sudo service apache2 restart # no errors
service apache2 restart      # errors
  • Thanks, I already saw that but it doesn't help. Using sudo or not doesn't change anything, I have the same error. – Pascal Polleunus Aug 26 '12 at 15:00
  • 1
    Worked for me! Totally forgot sudo. – ThomasReggi Nov 15 '12 at 16:19
  • 2
    +1 magic sudo always does the trick – bicycle Sep 11 '13 at 0:06
  • even worst, I have docker setup where this is appering, works on my home computer, but not on the server .. in the container with no difference between them... makes no sense to me – superhero Aug 24 '15 at 17:47
5

The problem stems from /usr/sbin/apache2ctl (on Debian). Check it out:

~$ grep ULIMIT /usr/sbin/apache2ctl
ULIMIT_MAX_FILES="${APACHE_ULIMIT_MAX_FILES:-ulimit -n 8192}"
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
    $ULIMIT_MAX_FILES

Here it is setting the number of open files allowed to 8192. Or trying to and failing, in your case.

So to avoid getting an error when apache2ctl does that, adjust your system's settings in the /etc/security/limits.conf file by adding these two lines:

*               soft    nofile          8192
*               hard    nofile          8192

I didn't increase it to more than necessary (8192) because I don't know what else it will impact. However this gets rid of the warning.

Not sure if you will need to reboot your system after that, because there is a dynamic element to the ulimits which I am not familiar with. However you can test easily enough to find out what your current ulimit num of files is:

ulimit -n

You might want to read where I found it: stackoverflow - setting ulimit

  • How would I do the reverse and reduce the Apache limit? – eri0o Nov 2 '15 at 13:05
  • Seeing that the script I posted in the answer is direct out of the apache2ctl script which is installed by apache, then you will have to go to that script file and change it, assuming you have the access right and assuming you're willing to repeat the action with every Apache upgrade. – Adam Nov 2 '15 at 15:23
2

1.Check and modify the value of ulimit in your host machine. Add the values in the file /etc/profile then make it take effect.

ulimit -u 10240
ulimit -n 8192     #This configuration is what we most needed
ulimit -d unlimited
ulimit -m unlimited
ulimit -s unlimited
ulimit -t unlimited
ulimit -v unlimited

source /etc/profile

or you can:

sudo sh -c 'printf "\nulimit -HSn 999999\n" >> /etc/sysconfig/docker'

2.Restart docker service and make the configuration to be effective.

sudo service docker restart

3.Test the ulimit in the container.

ulimit -n

This is my test result!

Tips:Maybe you can also try the command as below(prerequisite: ulimit in the host machine should be larger than 8192 ),but I am failed.

docker run --privileged -it -p xxxx:80 --ulimit data=8192 linode/lamp /bin/bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.