-/*
- *
- * Bacula Director daemon -- this is the main program
- *
- * Kern Sibbald, March MM
- *
- * Version $Id$
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ *
+ * Bacula Director daemon -- this is the main program
+ *
+ * Kern Sibbald, March MM
+ *
+ * Version $Id$
+ */
#include "bacula.h"
#include "dird.h"
/* Forward referenced subroutines */
void terminate_dird(int sig);
-static int check_resources();
+static bool check_resources();
+static bool check_catalog();
static void dir_sql_query(JCR *jcr, const char *cmd);
/* Exported subroutines */
int FDConnectTimeout;
int SDConnectTimeout;
char *configfile = NULL;
+void *start_heap;
/* Globals Imported */
extern int r_first, r_last; /* first and last resources */
*
*/
#if defined(HAVE_WIN32)
+/* For Win32 main() is in src/win32 code ... */
#define main BaculaMain
#endif
char *uid = NULL;
char *gid = NULL;
+ start_heap = sbrk(0);
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
if (debug_level <= 0) {
debug_level = 1;
}
- Dmsg1(0, "Debug level = %d\n", debug_level);
+ Dmsg1(10, "Debug level = %d\n", debug_level);
break;
case 'f': /* run in foreground */
Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
}
+ drop(uid, gid); /* reduce privileges if requested */
+
+ if (!check_catalog()) {
+ Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
+ }
+
if (test_config) {
terminate_dird(0);
}
create_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
read_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
- drop(uid, gid); /* reduce priveleges if requested */
#if !defined(HAVE_WIN32)
signal(SIGHUP, reload_config);
init_job_server(director->MaxConcurrentJobs);
+// init_device_resources();
+
Dmsg0(200, "wait for next job\n");
/* Main loop -- call scheduler to get next job to run */
while ( (jcr = wait_for_next_job(runjob)) ) {
return 0;
}
+/*
+ * This allows the message handler to operate on the database
+ * by using a pointer to this function. The pointer is
+ * needed because the other daemons do not have access
+ * to the database. If the pointer is
+ * not defined (other daemons), then writing the database
+ * is disabled.
+ */
static void dir_sql_query(JCR *jcr, const char *cmd)
{
if (!jcr || !jcr->db) {
exit(1);
}
already_here = true;
+ stop_watchdog();
generate_daemon_event(NULL, "Exit");
write_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs));
free_config_resources();
term_ua_server();
term_msg(); /* terminate message handler */
- stop_watchdog();
cleanup_crypto();
close_memory_pool(); /* release free memory in pool */
sm_dump(false);
* **** FIXME **** this routine could be a lot more
* intelligent and comprehensive.
*/
-static int check_resources()
+static bool check_resources()
{
bool OK = true;
JOB *job;
for (i=0; job_items[i].name; i++) {
if (job_items[i].flags & ITEM_REQUIRED) {
if (!bit_is_set(i, job->hdr.item_present)) {
- Jmsg(NULL, M_FATAL, 0, _("\"%s\" directive in Job \"%s\" resource is required, but not found.\n"),
+ Jmsg(NULL, M_ERROR_TERM, 0, _("\"%s\" directive in Job \"%s\" resource is required, but not found.\n"),
job_items[i].name, job->name());
OK = false;
}
}
} /* End loop over Job res */
+
+ /* Loop over Consoles */
+ CONRES *cons;
+ foreach_res(cons, R_CONSOLE) {
+ /* tls_require implies tls_enable */
+ if (cons->tls_require) {
+ if (have_tls) {
+ cons->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ OK = false;
+ continue;
+ }
+ }
+
+ if (!cons->tls_certfile && cons->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Console \"%s\" in %s.\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+
+ if (!cons->tls_keyfile && cons->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Console \"%s\" in %s.\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+
+ if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable && cons->tls_verify_peer) {
+ Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\" or \"TLS CA"
+ " Certificate Dir\" are defined for Console \"%s\" in %s."
+ " At least one CA certificate store is required"
+ " when using \"TLS Verify Peer\".\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+ /* If everything is well, attempt to initialize our per-resource TLS context */
+ if (OK && (cons->tls_enable || cons->tls_require)) {
+ /* Initialize TLS context:
+ * Args: CA certfile, CA certdir, Certfile, Keyfile,
+ * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
+ cons->tls_ctx = new_tls_context(cons->tls_ca_certfile,
+ cons->tls_ca_certdir, cons->tls_certfile,
+ cons->tls_keyfile, NULL, NULL, cons->tls_dhfile, cons->tls_verify_peer);
+
+ if (!cons->tls_ctx) {
+ Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
+ cons->name(), configfile);
+ OK = false;
+ }
+ }
+
+ }
+
+ /* Loop over Clients */
+ CLIENT *client;
+ foreach_res(client, R_CLIENT) {
+ /* tls_require implies tls_enable */
+ if (client->tls_require) {
+ if (have_tls) {
+ client->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ OK = false;
+ continue;
+ }
+ }
+
+ if ((!client->tls_ca_certfile && !client->tls_ca_certdir) && client->tls_enable) {
+ Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
+ " or \"TLS CA Certificate Dir\" are defined for File daemon \"%s\" in %s.\n"),
+ client->name(), configfile);
+ OK = false;
+ }
+
+ /* If everything is well, attempt to initialize our per-resource TLS context */
+ if (OK && (client->tls_enable || client->tls_require)) {
+ /* Initialize TLS context:
+ * Args: CA certfile, CA certdir, Certfile, Keyfile,
+ * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
+ client->tls_ctx = new_tls_context(client->tls_ca_certfile,
+ client->tls_ca_certdir, client->tls_certfile,
+ client->tls_keyfile, NULL, NULL, NULL,
+ true);
+
+ if (!client->tls_ctx) {
+ Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
+ client->name(), configfile);
+ OK = false;
+ }
+ }
+ }
+
+ UnlockRes();
+ if (OK) {
+ close_msg(NULL); /* close temp message handler */
+ init_msg(NULL, director->messages); /* open daemon message handler */
+ }
+ return OK;
+}
+
+static bool check_catalog()
+{
+ bool OK = true;
+
/* Loop over databases */
CAT *catalog;
foreach_res(catalog, R_CATALOG) {
catalog->db_port, catalog->db_socket,
catalog->mult_db_connections);
if (!db || !db_open_database(NULL, db)) {
+ Pmsg2(000, _("Could not open Catalog \"%s\", database \"%s\".\n"),
+ catalog->name(), catalog->db_name);
Jmsg(NULL, M_FATAL, 0, _("Could not open Catalog \"%s\", database \"%s\".\n"),
catalog->name(), catalog->db_name);
if (db) {
Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
+ Pmsg1(000, "%s", db_strerror(db));
+ db_close_database(NULL, db);
}
OK = false;
continue;
create_pool(NULL, db, pool, POOL_OP_UPDATE); /* update request */
}
+ /* Loop over all pools for updating RecyclePool */
+ foreach_res(pool, R_POOL) {
+ update_pool_recyclepool(NULL, db, pool);
+ }
+
STORE *store;
foreach_res(store, R_STORAGE) {
STORAGE_DBR sr;
}
db_close_database(NULL, db);
}
-
- /* Loop over Consoles */
- CONRES *cons;
- foreach_res(cons, R_CONSOLE) {
- /* tls_require implies tls_enable */
- if (cons->tls_require) {
- if (have_tls) {
- cons->tls_enable = true;
- } else {
- Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
- OK = false;
- continue;
- }
- }
-
- if (!cons->tls_certfile && cons->tls_enable) {
- Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Console \"%s\" in %s.\n"),
- cons->name(), configfile);
- OK = false;
- }
-
- if (!cons->tls_keyfile && cons->tls_enable) {
- Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Console \"%s\" in %s.\n"),
- cons->name(), configfile);
- OK = false;
- }
-
- if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable && cons->tls_verify_peer) {
- Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\" or \"TLS CA"
- " Certificate Dir\" are defined for Console \"%s\" in %s."
- " At least one CA certificate store is required"
- " when using \"TLS Verify Peer\".\n"),
- cons->name(), configfile);
- OK = false;
- }
- /* If everything is well, attempt to initialize our per-resource TLS context */
- if (OK && (cons->tls_enable || cons->tls_require)) {
- /* Initialize TLS context:
- * Args: CA certfile, CA certdir, Certfile, Keyfile,
- * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
- cons->tls_ctx = new_tls_context(cons->tls_ca_certfile,
- cons->tls_ca_certdir, cons->tls_certfile,
- cons->tls_keyfile, NULL, NULL, cons->tls_dhfile, cons->tls_verify_peer);
-
- if (!cons->tls_ctx) {
- Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
- cons->name(), configfile);
- OK = false;
- }
- }
-
- }
-
- /* Loop over Clients */
- CLIENT *client;
- foreach_res(client, R_CLIENT) {
- /* tls_require implies tls_enable */
- if (client->tls_require) {
- if (have_tls) {
- client->tls_enable = true;
- } else {
- Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
- OK = false;
- continue;
- }
- }
-
- if ((!client->tls_ca_certfile && !client->tls_ca_certdir) && client->tls_enable) {
- Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
- " or \"TLS CA Certificate Dir\" are defined for File daemon \"%s\" in %s.\n"),
- client->name(), configfile);
- OK = false;
- }
-
- /* If everything is well, attempt to initialize our per-resource TLS context */
- if (OK && (client->tls_enable || client->tls_require)) {
- /* Initialize TLS context:
- * Args: CA certfile, CA certdir, Certfile, Keyfile,
- * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */
- client->tls_ctx = new_tls_context(client->tls_ca_certfile,
- client->tls_ca_certdir, client->tls_certfile,
- client->tls_keyfile, NULL, NULL, NULL,
- true);
-
- if (!client->tls_ctx) {
- Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"),
- client->name(), configfile);
- OK = false;
- }
- }
- }
-
- UnlockRes();
- if (OK) {
- close_msg(NULL); /* close temp message handler */
- init_msg(NULL, director->messages); /* open daemon message handler */
- }
+ /* Set type in global for debugging */
+ set_db_type(db_get_type());
return OK;
}