Page 1 of 1

Cron job does not start

PostPosted:Fri Feb 22, 2013 2:14 pm
by openkm@sitc.nl
Hi there,

I'm using version 6.2.1 build 7659 on OpenSuse 12.1.

For some reason my cron jobs do not start, they do run when I press the flash image but they won't start at the scheduled time see settings below:

FileBackup 05 * * * * application/x-bsh TopLevelFileBackup.bsh mymail@myprovider.nl

Do you any of you have an idea where the cause of this problem could lay, I searched the internet and did not find similar problems.

Thanks in advance
Harry

Re: Cron job does not start

PostPosted:Mon Feb 25, 2013 10:43 am
by jllort
Have you test the script .bsh into scripting view, goes right there ? I suggest print some outputs to see what happes or add some log ( here there's some looger http://wiki.openkm.com/index.php/Folders_deep )

Re: Cron job does not start

PostPosted:Mon Feb 25, 2013 5:19 pm
by openkm@sitc.nl
I don quite get what you mean, I tested the script by pressing the flash icon in the cron view. The script was executed succesful so it appears to be correct. Just to be sure I placed a very simple script in a second cron entry which also was not executed.

It seems that due to some installation/config error the crontab is not triggered but I can't find out what is it, there's no warning or error related to that in the logs either.

Re: Cron job does not start

PostPosted:Tue Feb 26, 2013 6:43 pm
by jllort
sincerally there's no mistery, if you declare correctly will be executed correctly ( you can force execution from administration with flash icon ), sure you tested in scripting view ? if you want can share here and we will take a look on it.

Re: Cron job does not start

PostPosted:Wed Feb 27, 2013 12:48 pm
by openkm@sitc.nl
Here's the script I'm using:
Code: Select all
import com.openkm.core.*;
import com.openkm.util.impexp.*;
import com.openkm.module.db.stuff.DbSessionManager;
import com.openkm.util.FileUtils;


StringWriter out = new StringWriter();

RepositoryExporter.exportDocuments(null, "/okm:root/", new File("/home/sugarcrm/docbackup/"), false, false, out, new TextInfoDecorator("/okm:root/"));

print("All documents copied");
BTW: Scripting view shows proper results, I'm pretty sure it's just cron not starting the script but don't know where to look for that problem.

Re: Cron job does not start

PostPosted:Sat Mar 02, 2013 10:53 am
by jllort
Whne you export from crontab you need a token not null because you should not be logged at the moment crontab is executing. You should use systemToken like
Code: Select all
String systemToken = DbSessionManager.getInstance().getSystemToken();

Re: Cron job does not start

PostPosted:Tue Mar 05, 2013 7:19 am
by openkm@sitc.nl
So I changed the script to:
Code: Select all
import com.openkm.core.*;
import com.openkm.util.impexp.*;
import com.openkm.module.db.stuff.DbSessionManager;
import com.openkm.util.FileUtils;

String systemToken = DbSessionManager.getInstance().getSystemToken();
StringWriter out = new StringWriter();
RepositoryExporter.exportDocuments(systemToken, "/okm:root/", new File("/home/sugarcrm/docbackup/"), false, false, out, new TextInfoDecorator("/okm:root/"));

print("All documents copied");
Now pressing the flash sign results in receiving an email:
Code: Select all
Sourced file: inline evaluation of: ``import com.openkm.core.*; import com.openkm.util.impexp.*; import com.openkm.m . . . '' : Method Invocation RepositoryExporter.exportDocuments : at Line: 11 : in file: inline evaluation of: ``import com.openkm.core.*; import com.openkm.util.impexp.*; import com.openkm.m . . . '' : RepositoryExporter .exportDocuments ( systemToken , "/okm:root/" , new File ( "/home/sugarcrm/docbackup/" ) , false , false , out , new TextInfoDecorator ( "/okm:root/" ) ) Target exception: java.lang.NullPointerException
Which means that an script that contains some kind of error will result in an email. Note that it is still not executed automatically which is my real problem here.

I'm still pretty convinced that the cron task is simply not started automatically else I would receive an email containing the error. Right or not?

Is there a simple check to see if cron works normally?

Regards,
Harry

Re: Cron job does not start

PostPosted:Wed Mar 06, 2013 9:44 pm
by jllort
Several observations:
1- I suggest change "/okm:root/" to "/okm:root" ( without / at ends
2- Ensure user who's executing openkm ( which is running tomcat ) has grants to write under the folder /home/sugarcrm/docbackup/ ( I think this could be the reason of get null -> you can try print file object to be sure about it);

Re: Cron job does not start

PostPosted:Thu Mar 07, 2013 6:50 am
by openkm@sitc.nl
Ok, let's not focus on the script because if it contains an error it still would be executed to the point where it crashes and the results would be shown in the email.

To test the cron execution I followed the wiki again and implemented the example (http://wiki.openkm.com/index.php/Crontab).

I added the BeanShell sample with a bash script, note that the example on the wiki contains an error:
Code: Select all
for (int i=0; i<5; i++) {
  print("Iteration: " + i + "<br/>);
}
In the print statement the closing quote is missing. Adding this script with error in the following cron setup did nothing:

TEST 45 * * * * application/x-bsh TESTCRON.bsh mymail@mydomain

I would expect an email at 45 minutes past each hour with the scripting error which I did not get.
Pressing the flash sign does result in an email so it appears to me that the settings are correct otherwise OpenKM would not be able to send the mail.

So far nothing new as I stated from the beginning that I supect cron from just not being triggered but:

Once I've corrected the error, so now the code looks like:
Code: Select all
for (int i=0; i<5; i++) {
  print("Iteration: " + i + "<br/>");
}
It does nothing automatically so same behavior as before and if I start it with the flash sign it does NOT send an email. So the email is only send in case an error occurs and not if output is generated, this is weird.

So please focus on the cron mechanism as I now showed that it can't be the script.

Thanks in advance,
Harry

Re: Cron job does not start

PostPosted:Fri Mar 08, 2013 6:00 pm
by jllort
I suggest upgrade to lastest openkm version 6.2.2 i do not know if version 6.2.1 have some problem on it ( is strange ). To test in deep use a crontab wih 1-2 minutes not 45. In mail put your mail address if there's some error should be sent a mail to your account.

If not goes right after update, place here the script and I will test in on my community environment.

Re: Cron job does not start

PostPosted:Tue Mar 12, 2013 5:46 pm
by pavila
Please, try a recent nightbuild from http://integration.openkm.com/6.2/ because we want to make a release soon and need feedback from users.

Re: Cron job does not start

PostPosted:Thu Apr 25, 2013 1:51 pm
by openkm@sitc.nl
Dear responders,
Just upgraded to 6.2.3 which solved the cron issue, My script results in an error but that's a different story ;-).

Thanks for you support, consider this problem to be solved.

Cheers,
Harry