]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/runscript.h
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / lib / runscript.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2006-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Bacula RUNSCRIPT Structure definition for FileDaemon and Director
22  * Eric Bollengier May 2006
23  */
24
25
26 #ifndef __RUNSCRIPT_H_
27 #define __RUNSCRIPT_H_ 1
28
29 #include "protos.h"
30
31 /* Usage:
32  *
33  * #define USE_RUNSCRIPT
34  * #include "lib/runscript.h"
35  *
36  * RUNSCRIPT *script = new_runscript();
37  * script->set_command("/bin/sleep 20");
38  * script->on_failure = true;
39  * script->when = SCRIPT_After;
40  *
41  * script->run("LabelBefore");  // the label must contain "Before" or "After" special keyword
42  * free_runscript(script);
43  */
44
45 /*
46  * RUNSCRIPT->when can take following bit values:
47  */
48 enum {
49    SCRIPT_Never  = 0,
50    SCRIPT_After  = (1<<0),      /* AfterJob */
51    SCRIPT_Before = (1<<1),      /* BeforeJob */
52    SCRIPT_AfterVSS = (1<<2),    /* BeforeJob and After VSS */
53    SCRIPT_Any    = SCRIPT_Before | SCRIPT_After
54 };
55
56 enum {
57    SHELL_CMD   = '|',
58    CONSOLE_CMD = '@'
59 };
60
61 /*
62  * Structure for RunScript ressource
63  */
64 class RUNSCRIPT {
65 public:
66    POOLMEM *command;            /* command string */
67    POOLMEM *target;             /* host target */
68    int  when;                   /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/
69    int  cmd_type;               /* Command type -- Shell, Console */
70    char level;                  /* Base|Full|Incr...|All (NYI) */
71    bool on_success;             /* execute command on job success (After) */
72    bool on_failure;             /* execute command on job failure (After) */
73    bool fail_on_error;         /* abort job on error (Before) */
74    /* TODO : drop this with bacula 1.42 */
75    bool old_proto;              /* used by old 1.3X protocol */
76    job_code_callback_t job_code_callback;
77                                 /* Optional callback function passed to edit_job_code */
78    alist *commands;             /* Use during parsing */
79    bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
80    bool can_run_at_level(int JobLevel) { return true;};        /* TODO */
81    void set_command(const char *cmd, int cmd_type = SHELL_CMD);
82    void set_target(const char *client_name);
83    void reset_default(bool free_string = false);
84    bool is_local();             /* true if running on local host */
85    void debug();
86
87    void set_job_code_callback(job_code_callback_t job_code_callback);
88 };
89
90 /* create new RUNSCRIPT (set all value to 0) */
91 RUNSCRIPT *new_runscript();
92
93 /* create new RUNSCRIPT from an other */
94 RUNSCRIPT *copy_runscript(RUNSCRIPT *src);
95
96 /* launch each script from runscripts*/
97 int run_scripts(JCR *jcr, alist *runscripts, const char *name);
98
99 /* free RUNSCRIPT (and all POOLMEM) */
100 void free_runscript(RUNSCRIPT *script);
101
102 /* foreach_alist free RUNSCRIPT */
103 void free_runscripts(alist *runscripts); /* you have to free alist */
104
105 extern DLL_IMP_EXP bool (*console_command)(JCR *jcr, const char *cmd);
106
107 #endif /* __RUNSCRIPT_H_ */