Tushar M. Patel
Tushar M. Patel

Reputation: 83

How to start my cron job on startup of alfresco server?

How can I start my scheduler on startup of Alfresco server? Liferay provide onstartup server event. Is there any similar kind of functionality available in the Alfresco where can I start my Cron job on start of Alfresco server?

Upvotes: 1

Views: 1219

Answers (3)

Piergiorgio Lucidi
Piergiorgio Lucidi

Reputation: 466

Another good way to to this is to extend the AbstractModuleComponent implementing the method executeInternal and in the Spring configuration set the executeOnlyOnce to false. In this way your custom code will be executed every time Alfresco starts.

Below an example of a Spring configuration:

<bean id="initJobsComponent" class="com.sourcesense.alfresco.component.InitJobsComponent" parent="module.baseComponent" >
    <property name="moduleId" value="myModuleId" />
    <property name="name" value="initComponent" />
    <property name="description" value="You description" />
    <property name="sinceVersion" value="1.0" />
    <property name="appliesFromVersion" value="1.0" />
    <property name="executeOnceOnly" value="false"/>
</bean>

Your Java class must extend AbstractModuleComponent:

public class InitJobsComponent extends AbstractModuleComponent {

...

@Override
protected void executeInternal() throws Throwable {

//put here your custom code    

}

... }

Hope this helps.

Upvotes: 1

Andreas Steffan
Andreas Steffan

Reputation: 6159

It does not make sense to use cron or a similar service if you want to run custom code at startup time. Add your custom Spring managed bean derived from org.springframework.extensions.surf.util.AbstractLifecycleBean to a file tomcat/shared/classes/alfresco/extension/startup-context.xml (or equivalent). Put your code in the onBootstrap method.

Upvotes: 3

Bertrand Cebador
Bertrand Cebador

Reputation: 86

To fit your need you could launch execution of your job by appending it to alfresco launch script.

Edit : /etc/init.d/alfresco

Put into "start" section your job, example:

    case $1 in
    start)
   sh YOUR_CRON_JOB
    [....]
    ;;

Upvotes: 0

Related Questions