{"id":291,"date":"2012-06-06T09:17:54","date_gmt":"2012-06-06T13:17:54","guid":{"rendered":"http:\/\/digitallibraryworld.com\/?p=291"},"modified":"2012-06-06T09:59:52","modified_gmt":"2012-06-06T13:59:52","slug":"supervisor-cannot-start-nagios-api-automatically-upon-restart-status-dat-file-not-found","status":"publish","type":"post","link":"https:\/\/heisbudi.com\/?p=291","title":{"rendered":"Supervisor cannot start nagios-api automatically upon restart. Status.dat file not found"},"content":{"rendered":"<p>Ok. Being new to linux and all, this took a while for me to figure out, but I finally did. So, I have a debian running <a title=\"Nagios Core\" href=\"http:\/\/www.nagios.org\/projects\/nagioscore\" target=\"_blank\">Nagios Core<\/a> monitoring system. My former co-worker also set the system up to use <a title=\"Nagios API\" href=\"https:\/\/github.com\/xb95\/nagios-api\">Nagios API<\/a>, so that we can create a custom page that shows up the status of all our system.<\/p>\n<p>Briefly, this is how the API is supposed to work:<\/p>\n<p>There is a python script called <strong>nagios-api<\/strong> that you need to run so that the api would run as an application server on a certain port. This API takes advantage of a status file dump called status.dat, configured in <strong>\/etc\/nagios3\/nagios.cfg<\/strong>,\u00a0updated peridocally by Nagios. <a title=\"Supervisord\" href=\"http:\/\/supervisord.org\">Supervisor<\/a>(A linux process manager) would start this script every time the server starts. The configuration file is as follow:<\/p>\n<pre>\r\n<div id=\"_mcePaste\">[program:nagapi]<\/div>\r\n<div id=\"_mcePaste\">directory = \/home\/nagapi<\/div>\r\n<div id=\"_mcePaste\">user = api<\/div>\r\n<div id=\"_mcePaste\">command = \/bin\/bash -c \"source \/home\/nagapi\/.virtualenvs\/nagapi\/bin\/activate; \/home\/nagapi\/nagios-api\/nagios-api\"<\/div>\r\n<div id=\"_mcePaste\">stdout_logfile = \/home\/nagapi\/supervisor_nagios-api_stdout.log<\/div>\r\n<div id=\"_mcePaste\">stderr_logfile = \/home\/nagapi\/supervisor_nagios-api_stderr.log<\/div><\/pre>\n<h3><span style=\"text-decoration: underline;\"><span style=\"color: #ff0000;\"><strong>Problem I was experiencing<\/strong><\/span><\/span><\/h3>\n<p><span style=\"color: #000000;\">Every time I restart the server, the following would happen:<\/span><\/p>\n<pre><span style=\"color: #000000;\"><!--more--><\/span><\/pre>\n<ul>\n<li>The API did not start automatically<\/li>\n<li>Checking the status of supervisor by running\u00a0<span style=\"color: #008000;\">sudo supervisorctl status<\/span> resulted in:\n<pre>nagapi                        EXITED     Jun 06 04:39 AM<\/pre>\n<\/li>\n<li>The supervisor error file listed in the conf file above(<span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;\">supervisor_nagios-api_stderr.log)<\/span> mentioned the following\n<pre>nagios-api: error: Status file not found: \/var\/cache\/nagios3\/status.dat<\/pre>\n<\/li>\n<\/ul>\n<p>So, I went and checked to see if the file existed. AND IT DID EXIST!!! So, maybe it was permission issue. I checked, and IT DID have the right permission at the parent folder level, because i know this file gets updated periodically. I then tried to start the process manually, just to make sure that I was not crazy, by running\u00a0<span style=\"color: #008000;\">sudo supervisorctl start nagapi<\/span>. The prompt indicated :<\/p>\n<pre>nagapi: started<\/pre>\n<p>The service started with no problem!! I was on the verge of slapping my monitor in its face. What was the file not found about?????? Why can&#8217;t Supervisor start my service???<\/p>\n<h3><span style=\"color: #0000ff;\">Solution<\/span><\/h3>\n<p>It turns out that logs really don&#8217;t lie. After a restart takes place, it takes some time for Nagios daemon to create dump file. Supervisor was trying to use the file status.dat file before it gets created by Nagios. So, this explains why Supervisor was not able to run the api, but I was able to manually start it. All I had to do was be patient. So, I added a start delay timer in my <a title=\"Supervisor COnfig\" href=\"http:\/\/supervisord.org\/configuration.html\" target=\"_blank\">supervisor config<\/a> file for the API. The config file now looks like:<\/p>\n<pre>\r\n<div id=\"_mcePaste\">[program:nagapi]<\/div>\r\n<div id=\"_mcePaste\">directory = \/home\/nagapi<\/div>\r\n<div id=\"_mcePaste\">user = api<\/div>\r\n<div id=\"_mcePaste\">command = \/bin\/bash -c \"source \/home\/nagapi\/.virtualenvs\/nagapi\/bin\/activate; \/home\/nagapi\/nagios-api\/nagios-api\"<\/div>\r\n<div id=\"_mcePaste\">startsecs = 60<\/div>\r\n<div id=\"_mcePaste\">stdout_logfile = \/home\/nagapi\/supervisor_nagios-api_stdout.log<\/div>\r\n<div id=\"_mcePaste\">stderr_logfile = \/home\/nagapi\/supervisor_nagios-api_stderr.log<\/div><\/pre>\n<div data-counters='1' data-style='square' data-size='regular' data-url='https:\/\/heisbudi.com\/?p=291' data-title='Supervisor cannot start nagios-api automatically upon restart. Status.dat file not found' class='linksalpha_container linksalpha_app_3'><a href='\/\/www.linksalpha.com\/share?network='facebook' class='linksalpha_icon_facebook'><\/a><a href='\/\/www.linksalpha.com\/share?network='twitter' class='linksalpha_icon_twitter'><\/a><a href='\/\/www.linksalpha.com\/share?network='googleplus' class='linksalpha_icon_googleplus'><\/a><a href='\/\/www.linksalpha.com\/share?network='mail' class='linksalpha_icon_mail'><\/a><\/div><div data-position='' data-url='https:\/\/heisbudi.com\/?p=291' data-title='Supervisor cannot start nagios-api automatically upon restart. Status.dat file not found' class='linksalpha_container linksalpha_app_7'><a href='\/\/www.linksalpha.com\/share?network='facebook' class='linksalpha_icon_facebook'><\/a><a href='\/\/www.linksalpha.com\/share?network='twitter' class='linksalpha_icon_twitter'><\/a><a href='\/\/www.linksalpha.com\/share?network='googleplus' class='linksalpha_icon_googleplus'><\/a><a href='\/\/www.linksalpha.com\/share?network='mail' class='linksalpha_icon_mail'><\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>Ok. Being new to linux and all, this took a while for me to figure out, but I finally did. So, I have a debian running Nagios Core monitoring system. My former co-worker also set the system up to use Nagios API, so that we can create a custom page that shows up the status <a class=\"read-more\" href=\"https:\/\/heisbudi.com\/?p=291\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,22,25],"tags":[],"_links":{"self":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts\/291"}],"collection":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291"}],"version-history":[{"count":9,"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":296,"href":"https:\/\/heisbudi.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions\/296"}],"wp:attachment":[{"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heisbudi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}