I have created a web application based around Nagios and everything is working fine except that when the Nagios process there is a delay before all the data is written from the program at startup into the mysql database.
I have found that there is a table called programstatus that is empty when the program is restarting but once complete contains one and only one record.
I had built some logic into the main layout file that did
if(ProgramStatus::model()->count() == 0) echo "Site down"; //this is just for example I will use a renderpartial in reality yii::app()->end(); end if
This works but doesnt seem the correct way to do this. I have tried the Yii method of using ‘catchAllRequest’ in the config/main.php file
'catchAllRequest' => (Programstatus::model()->count() == 0) ? array('site/maintenance') : null,
However this causes problem because yii isn’t initialized yet and I get errors like
include(Programstatus.php): failed to open stream: No such file or directory
and if I use php to include the file I then get issues with the database connection
Uncaught exception 'CDbException' with message 'Active Record requires a "db" CDbConnection application component.
I think I understand why this is happening but is there a better way to achieve my goal elegantly.