]> git.sur5r.net Git - bacula/bacula/commitdiff
ebl fix #824 bug about runscript
authorEric Bollengier <eric@eb.homelinux.org>
Fri, 20 Apr 2007 20:36:47 +0000 (20:36 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Fri, 20 Apr 2007 20:36:47 +0000 (20:36 +0000)
     use RunsOnSuccess and RunsOnFailure with Before script (like before, but it's more clear)

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4573 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/lib/runscript.c
bacula/src/lib/runscript.h

index e01c1da5e246ba91bd2ffed5bdbbb85352b68c6d..1390af1edf77aff7d8fa641ebde1d607d5c476ce 100644 (file)
@@ -105,6 +105,14 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
    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;
@@ -114,28 +122,33 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
       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()) {
index d75a7b4b474f06f25f591ad0f35a02bf6fb98a00..42b1c898d9e80d5ea3d1737aef88777b27289b77 100644 (file)
@@ -45,7 +45,7 @@
  * 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);
  */
 
@@ -74,7 +74,7 @@ public:
    /* 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);