Linux – Httpd restart “Address already in use” error

centos5httpdlinuxrpm

I have an .rpm, which I created. In its %post part, I do some stuff, and in the end of this script, i call service httpd restart. It gives the following error:

+ service httpd restart
Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:81
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:81
no listening sockets available, shutting down
Unable to open logs
[FAILED]

I got this from the rpm verbose installing (-vv). So I know its about httpd restart itself, nothing else. The according to netstat only one process (httpd) is listening on port 81.

$ sudo netstat -nlp | grep 81
tcp      0      0 :::81        :::*      LISTEN      29670/httpd

I don't understand, why running http FAILS at stop, and FAILS again in start.

Any ideas how to solve this?

Best Answer

The init.d scripting (invoked by the service command) depending on implementation is not as smart as you think it might be. What I see in many of these implementations, the execution of the "start" socks away the process number of the original httpd process (i.e. the one that runs as root). Then when you execute the 'stop' process, it is simply killing off (with the appropriate signal number) the root httpd process.

Sometimes, slave processes get orphaned and do not get killed (because they might be broken and not responding appropriately to the parents' signal). If this is the case, then the port is still attached by the slave processes and executing a 'restart' or a 'start' will fail.

What you need to do is to do a "ps -aef | grep httpd | grep -v grep" to find the broken slave processes, and kill them off directly (using the kill -9 pid#). There may well be more than one broken process.

Once all of the broken processes have been kilt, then you can 'start' up the apache server again.

Related Topic