bool runit;
bool status;
+ int when;
+
+ if (strstr(label, "Before")) {
+ when = SCRIPT_Before;
+ } else {
+ when = SCRIPT_After;
+ }
+
if (runscripts == NULL) {
Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n");
return 0;
Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command));
runit=false;
- if ((script->when & SCRIPT_Before) && (jcr->JobStatus == JS_Created)) {
- Dmsg0(200, "runscript: Run it because SCRIPT_Before\n");
- runit = true;
+ if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
+ if ( (script->on_success && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
+ ||
+ (script->on_failure && job_canceled(jcr))
+ )
+ {
+ Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n", script->command,
+ script->on_success,
+ script->on_failure,
+ jcr->JobStatus );
+
+ runit = true;
+ }
}
- if ((script->when & SCRIPT_Before) && (jcr->JobStatus == JS_Running)) {
- Dmsg0(200, "runscript: Run it because SCRIPT_Before\n");
- runit = true;
- }
-
- if (script->when & SCRIPT_After) {
- if ( (script->on_success && (jcr->JobStatus == JS_Terminated))
- ||
- (script->on_failure && job_canceled(jcr))
- )
- {
- Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command,
- script->on_success,
- script->on_failure,
- jcr->JobStatus );
- runit = true;
- }
+ if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
+ if ( (script->on_success && (jcr->JobStatus == JS_Terminated))
+ ||
+ (script->on_failure && job_canceled(jcr))
+ )
+ {
+ Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command,
+ script->on_success,
+ script->on_failure,
+ jcr->JobStatus );
+ runit = true;
+ }
}
if (!script->is_local()) {
* script->on_failure = true;
* script->when = SCRIPT_After;
*
- * script->run("Label");
+ * script->run("LabelBefore"); // the label must contain "Before" or "After" special keyword
* free_runscript(script);
*/
/* TODO : drop this with bacula 1.42 */
bool old_proto; /* used by old 1.3X protocol */
- int run(JCR *job, const char *name="");
+ int run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
bool can_run_at_level(int JobLevel) { return true;}; /* TODO */
void set_command(const POOLMEM *cmd);
void set_target(const POOLMEM *client_name);