{"id":83,"date":"2014-05-17T20:57:03","date_gmt":"2014-05-17T18:57:03","guid":{"rendered":"http:\/\/techblog.vindvejr.dk\/?p=83"},"modified":"2014-05-17T20:57:43","modified_gmt":"2014-05-17T18:57:43","slug":"httpd-pid-gone-missing","status":"publish","type":"post","link":"https:\/\/techblog.vindvejr.dk\/?p=83","title":{"rendered":"httpd.pid gone missing"},"content":{"rendered":"<p>For quite some time I&#8217;ve been having a problem with my httpd.pid file going missing every now and then. Whenever this happens, I can&#8217;t use the init script to start and stop the server anymore, which is pretty annoying. For some reason I had learned to live with this &#8211; I would just &#8216;killall httpd&#8217;, start the server again and the httpd.pid would be back for some time, until the problem would reappear.<\/p>\n<p>Finally I decided to do something about it. I added this small script to my hourly cron jobs:<\/p>\n<pre>\r\nif [ ! -e \"\/usr\/local\/apache2\/logs\/httpd.pid\" ]; then\r\n        echo \"httpd.pid missing\"\r\nfi\r\n<\/pre>\n<p>A few weeks later this trap was finally triggered &#8211; less than an hour after my daily logrotate, which produced this output:<\/p>\n<pre>\r\nStarting httpd: [  OK  ]\r\nStopping httpd: [  OK  ]\r\n(repeated a number of times...)\r\nStarting httpd: [  OK  ]\r\nStopping httpd: [FAILED]\r\nStarting httpd: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80\r\n(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80\r\nno listening sockets available, shutting down\r\nAH00015: Unable to open logs\r\n[FAILED]\r\nerror: error running postrotate script for \/usr\/local\/apache2\/logs\/*_log \r\n<\/pre>\n<p>This was not the first time I had seen this, but it was the first time I realized that the logrotate problem was causing the httpd.pid problem, and not the other way around.<\/p>\n<p>So I checked my \/etc\/logrotate.d\/apache config file:<\/p>\n<pre>\r\n\/usr\/local\/apache2\/logs\/*_log {\r\n    rotate 1024\r\n    size 4M\r\n    notifempty\r\n    postrotate\r\n        \/etc\/init.d\/httpd restart\r\n    endscript\r\n}\r\n<\/pre>\n<p>After a few minutes of reading the logrotate man page, I realized what was wrong (had a hunch, though): The restart between the <strong>postrotate\/endscript<\/strong> directives was performed for each logfile, i.e. multiple times, instead of just a single time after the last one was rotated. This in itself is pretty bad, but it would also happen asynchronously, thus create a mess. This problem was easily solved using the <strong>sharedscript<\/strong> directive. Also, a simple &#8220;reload&#8221; instead of &#8220;restart&#8221; is sufficient to make httpd reopen the logfiles, thus create new filehandles.<\/p>\n<p>After fixing these two problems, the file ended up like this:<\/p>\n<pre>\r\n\/usr\/local\/apache2\/logs\/*_log {\r\n    rotate 1024\r\n    size 4M\r\n    notifempty\r\n    sharedscripts\r\n    postrotate\r\n        \/etc\/init.d\/httpd reload\r\n    endscript\r\n}\r\n<\/pre>\n<p>I&#8217;m fully expecting this to solve the problem once and for all.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For quite some time I&#8217;ve been having a problem with my httpd.pid file going missing every now and then. Whenever this happens, I can&#8217;t use the init script to start and stop the server anymore, which is pretty annoying. For &hellip; <a href=\"https:\/\/techblog.vindvejr.dk\/?p=83\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83"}],"version-history":[{"count":3,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}