cron.sh not working

Discussion in 'General' started by mahafue, Jan 14, 2017.

  1. mahafue

    mahafue New Member

    Hey guys,

    I'm using ISPConfig 3.1 in a Multiserver Setup.
    On one server the cron.sh is not really working, I think. Logs aren't rotate, Trafficusage not in the Database, ... .
    I created a small script (999-test.php) and put it in '/usr/local/ispconfig/server/lib/classes/cron.d/'. The script should only write a file into a web-log folder but nothin happens. In cron.log it will be shown.

    Code:
    Included cronjob_test from /usr/local/ispconfig/server/lib/classes/cron.d/999-test.php -> will now run job.
    Called run() for class cronjob_test
    Job has schedule: * * * * *
    Called onPrepare() for class cronjob_test
    Called onBeforeRun() for class cronjob_test
    Jobs next run is 1484386349
    Date compare of 1484386349 and 1484386349 is 0
    Jobs next run is now 2017-01-14 09:33:0
    Called onRun() for class cronjob_test
    Called onAfterRun() for class cronjob_test
    Called onCompleted() for class cronjob_test
    run job (cronjob_test) done.
    Code:
    <?php
    
    class cronjob_test extends cronjob {
    
        // job schedule
        protected $_schedule = '* * * * *';
    
        /* this function is optional if it contains no custom code */
        public function onPrepare() {
            global $app;
    
            parent::onPrepare();
        }
    
        /* this function is optional if it contains no custom code */
        public function onBeforeRun() {
            global $app;
    
            return parent::onBeforeRun();
        }
    
        public function onRunJob() {
            global $app, $conf;
    
            touch('/var/log/ispconfig/httpd/marcohanisch.de/test.log');
               
            parent::onRunJob();
        }
    
        /* this function is optional if it contains no custom code */
        public function onAfterRun() {
            global $app;
    
            parent::onAfterRun();
        }
    
    }
    
    ?>
    Whats going wrong on my machine?

    Thanks
    Marco
     
    Last edited: Jan 14, 2017
  2. florian030

    florian030 Well-Known Member HowtoForge Supporter

    can you run
    php -r "touch ('/var/log/ispconfig/httpd/marcohanisch.de/test.log');"
    witout any errors?
    you can also trigger an action if touch() fails. if(!touch('log')) do_something
     
  3. mahafue

    mahafue New Member

    Hi,
    thanks for your answer.
    Yes, no problems running this snippet from terminal
     
  4. florian030

    florian030 Well-Known Member HowtoForge Supporter

    And you did not see the log with the current timestamp?
    You can debug your class using php /usr/local/ispconfig/server/cron_debug.php --cronjob=999-test.inc.php
     
  5. mahafue

    mahafue New Member

    Hey Florian,

    thank you for your answer. I found the problem... For a reason not known to me the table "sys_cron" was not available. After I have created the table directly on the MySQL Server, every Job is working fine... Hmm.. :)

    I found in some jobs '$_run_at_new == true' at the top. Have taken it to my test job, after that it worked without any problems.
    I have read something through the documentation and encountered the usage of this table...
    https://fossies.org/dox/ISPConfig-3.1.1p1/cronjob_8inc_8php_source.html

    Sometimes it is easier than you think.

    Marco
     

Share This Page