]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/runscript.h
Eliminate dependency on man2html.
[bacula/bacula] / bacula / src / lib / runscript.h
1 /*
2  * Bacula RUNSCRIPT Structure definition for FileDaemon and Director
3  * Eric Bollengier May 2006
4  * Version $Id$
5  */
6 /*
7    Copyright (C) 2006-2006 Kern Sibbald
8
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License
11    version 2 as amended with additional clauses defined in the
12    file LICENSE in the main source directory.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
17    the file LICENSE for additional details.
18
19  */
20
21
22 #ifndef __RUNSCRIPT_H_
23 #define __RUNSCRIPT_H_ 1
24
25 /* Usage:
26  *
27  * #define USE_RUNSCRIPT
28  * #include "lib/runscript.h"
29  * 
30  * RUNSCRIPT *script = new_runscript();
31  * script->set_command("/bin/sleep 20");
32  * script->on_failure = true;
33  * script->when = SCRIPT_After;
34  * 
35  * script->run("Label");
36  * free_runscript(script);
37  */
38
39 /* 
40  * RUNSCRIPT->when can take following bit values:
41  */
42 enum {
43    SCRIPT_Never  = 0,
44    SCRIPT_After  = (1<<0),      /* AfterJob */
45    SCRIPT_Before = (1<<1),      /* BeforeJob */
46    SCRIPT_Any    = SCRIPT_Before | SCRIPT_After
47 };
48
49 /*
50  * Structure for RunScript ressource
51  */
52 class RUNSCRIPT {
53 public:
54    POOLMEM *command;            /* command string */
55    POOLMEM *target;             /* host target */
56    char level;                  /* Base|Full|Incr...|All (NYI) */
57    bool on_success;             /* executre command on job success (After) */
58    bool on_failure;             /* executre command on job failure (After) */
59    bool abort_on_error;         /* abort job on error (Before) */
60    int  when;                   /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/
61    /* TODO : drop this with bacula 1.42 */
62    bool old_proto;              /* used by old 1.3X protocol */
63
64    int run(JCR *job, const char *name="");
65    bool can_run_at_level(int JobLevel) { return true;};        /* TODO */
66    void set_command(const POOLMEM *cmd);
67    void set_target(const POOLMEM *client_name);
68    void reset_default(bool free_string = false);
69    bool is_local();             /* true if running on local host */
70    void debug();
71 };
72
73 /* create new RUNSCRIPT (set all value to 0) */
74 RUNSCRIPT *new_runscript();           
75
76 /* create new RUNSCRIPT from an other */
77 RUNSCRIPT *copy_runscript(RUNSCRIPT *src);
78
79 /* launch each script from runscripts*/
80 int run_scripts(JCR *jcr, alist *runscripts, const char *name); 
81
82 /* free RUNSCRIPT (and all POOLMEM) */
83 void free_runscript(RUNSCRIPT *script);
84
85 /* foreach_alist free RUNSCRIPT */
86 void free_runscripts(alist *runscripts); /* you have to free alist */
87
88 #endif /* __RUNSCRIPT_H_ */