Search code examples
phplinuxyiiupstart

Upstart a Yii console gives me error


I am trying to run a backend process and I am hitting into problem getting the upstart to run the yiic command.

I am using xampp server

Here is my upstart script:

#description     "Sample upstart"

#start on stopped
start on startup
stop on shutdown
respawn

chdir /opt/lampp/htdocs/my_project/protected
setuid mad
setgid www-data

script
    exec /opt/lampp/htdocs/my_project/protected/yiic project test
end script

So when i do

sudo start test-monitor

the upstart is starting and it it seems like it is firing a command to yii project as error is being caught in yii log file. The error in yii log file is:

2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver

However if I do the command manually:

./yiic project test

This are working fine. Can someone please help me.

Here is the codes for the yii console command:

public function actionTest(){
        try{
          while(1){
             TestManager::_MonitorTest();
             usleep(1000000);
          }
        }catch(Exception $e){
              Yii::log( $e->getMessage(), 'error', 'worker.*');
        }    
    }

Here is the log file of the upstart (It isn't the case as I have taken the sudo out):

sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified

Mysql connection is working fine and I have tested it


Solution

  • After some persistent tries and some configuration, I managed to solve the issue.

    Since the server was a xampp server, php is installed in xampp thus there is an environment issue. Thus the bin directory of the php has to be referenced in the upstart as such:

    This was the solve on the upstart script:

    script
      exec /opt/lampp/bin/php -f /opt/lampp/htdocs/my_project/protected/yiic.php project test
    end script