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).

user9517
  • 114,104
  • 20
  • 206
  • 289
Pascal Polleunus
  • 1,193
  • 2
  • 10
  • 14
  • 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 06 '12 at 09:44

3 Answers3

17

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

sudo service apache2 restart # no errors
service apache2 restart      # errors
6

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

Adam
  • 236
  • 4
  • 15
  • How would I do the reverse and reduce the Apache limit? – eri0o Nov 02 '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 02 '15 at 15:23
  • The actual answer on the question. +1 – Leo Skhrnkv Apr 09 '20 at 13:39
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
user3772170
  • 121
  • 1
  • 1
    `$ ulimit -n 8192` gives me `-bash: ulimit: open files: cannot modify limit: Operation not permitted` – Shardj Feb 26 '20 at 15:25