Subsys lock problem with CentOS 6.2 and Apache

While I was improving my LAMP module I ran in to a problem with Apache 2.2.15 on CentOS 6.2.
Apache wasn’t working with my new module so I decided to install it normally via yum and see what’s going on.
Got it installed just fine with:
yum install httpd

Ran sudo service httpd restart.
All went fine.

But now when I checked status:

service httpd status
httpd dead but subsys locked


Tried to delete the lock:
sudo rm -f /var/lock/subsys/httpd

Didn’t help. It’s still giving the same lock message. The Apache actually works as it’s serving my web pages but the service status is not working as it should. And this is a problem with my Puppet LAMP module.

UPDATE: As pointed out in the comments, here’s another related error message that you might get when you try to restart httpd:

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

I have also tried rebooting the box and updating packages with yum update but didn’t help.

I started examining httpd.conf and noticed that the PidFile variable was set to run/httpd.pid by default.
Changed it to point to /var/run:

PidFile /var/run/httpd.pid

And also changed the variable in /etc/sysconfig/httpd:

PIDFILE=/var/run/httpd.pid

Killed the httpd processes:
killall -9 httpd

Removed the lock:
sudo rm -f /var/lock/subsys/httpd

Restarted apache:
sudo service httpd restart

And now it works:

service httpd status
httpd (pid 14331) is running...

Now I wanted to test this again to confirm that this solution works so I restored my virtualbox snapshot from the time when apache was not installed on the CentOS. Installed it again same way with yum. Checked httpd status and it was stopped. Restarted the httpd service and it went OK. Checked the status now presuming that it would complain about the lock again:
httpd (pid 13298) is running…

It’s working!?!

It was the exact same setup when it was complaining about that lock. But now it worked right away. No idea what’s going on here.
Well as that didn’t confirm anything I had to try again:

Restored the VM snapshot. This is CentOS 6.2, installed on virtualbox from liveCD. Firewall disabled, sshd enabled.
Installed apache:
sudo yum install -y httpd

Status check:

service httpd status
httpd is stopped

Started apache:

sudo service httpd start
Starting httpd:    [ OK ]

Status check:

service httpd status
httpd dead but subsys locked

Changed the pidfile variable in /etc/httpd/conf/httpd.conf from this:

PidFile run/httpd.pid

To this:

PidFile /var/run/httpd.pid

Changed the pidfile variable in /etc/sysconfig/httpd from this:

#PIDFILE=/var/run/httpd/httpd.pid

To this:

PIDFILE=/var/run/httpd.pid

Killed httpd processes:
killall -9 httpd

Removed any httpd locks:
sudo rm -f /var/lock/subsys/httpd

Restarted apache:

sudo service httpd restart
Stopping httpd:    [ FAILED ]
Starting httpd:    [ OK ]

Status check:

service httpd status
httpd (pid 6009) is running...

Finally confirmed that it’s working!

Oh and I will publish the improved LAMP puppet module as soon as I have time to test it.

About these ads

9 responses to “Subsys lock problem with CentOS 6.2 and Apache

  1. Michal August 30, 2012 at 5:45 pm

    I have same version of CentOS, same version of Apache and same damn problem. Weird thing is that initally it was working fine. Then I started configuring httpd.conf and suddenly this error although I didn’t change PidFile … To make this post more google friendly add this error message – that’s how I was looking for solution but it didn’t work ;-)

    Cheers mate!

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

    • Henri Siponen August 30, 2012 at 6:02 pm

      Thanks for your reply Michal. I’ll add the error message to the original post :) I hope you got your Apache working in the end.

  2. Dani Chao March 9, 2013 at 5:05 am

    Hi,
    Initially, this solution worked fine. But when I reboot, the problem occurred again : (
    What should I do? There is no more for changing to “PidFile /var/run/httpd.pid”…..

    Thank you.

    • Henri Siponen March 10, 2013 at 11:05 am

      Difficult to say as I can’t reproduce the error. It’s working for me still after several reboots. Check your /etc/sysconfig/httpd once more and make sure the the pidfile is /var/run/httpd.pid and not /var/run/httpd/httpd.pid and that it isn’t commented out (# in front).

  3. Rafael Sobrevilla March 23, 2013 at 1:37 am

    Thank very much!! I was search this solution for few days

  4. Andrew April 13, 2013 at 5:16 pm

    Whoa, this fixed my problem! Thanks for the post. Make sure to uncomment out the line /etc/sysconfig/httpd because it didn’t work before I did that.

  5. Pedro Henrique Ximenes July 25, 2013 at 11:31 pm

    Thanks a lot!

  6. lucasireal July 28, 2013 at 5:35 am

    tankyou man
    that really help! :D

  7. shaheer January 8, 2014 at 3:17 am

    Hi there,
    You can always use ‘sudo service httpd start | stop | status’ to check/configure for the apache service.
    The problem would be, here we use ‘service httpd status’ as normal user, who doesn’t have privilege to check. Better add the particular user to the service admin group(under root), or check as root user(or bypass using sudo command).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: