* Bacula Director daemon -- this is the main program
*
* Kern Sibbald, March MM
+ *
+ * Version $Id$
*/
/*
Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
extern void term_ua_server();
extern int do_backup(JCR *jcr);
extern void backup_cleanup(void);
-extern void start_UA_server(int port);
+extern void start_UA_server(char *addr, int port);
extern void run_job(JCR *jcr);
extern void init_job_server(int max_workers);
init_stack_dump();
my_name_is(argc, argv, "bacula-dir");
+ init_msg(NULL, NULL); /* initialize message handler */
daemon_start_time = time(NULL);
memset(&last_job, 0, sizeof(last_job));
configfile = bstrdup(CONFIG_FILE);
}
- init_msg(NULL, NULL); /* initialize message handler */
parse_config(configfile);
if (!check_resources()) {
- Emsg1(M_ABORT, 0, "Please correct configuration file: %s\n", configfile);
+ Jmsg(NULL, M_ERROR_TERM, 0, "Please correct configuration file: %s\n", configfile);
}
- my_name_is(0, (char **)NULL, director->hdr.name); /* set user defined name */
-
- FDConnectTimeout = director->FDConnectTimeout;
- SDConnectTimeout = director->SDConnectTimeout;
-
-
if (test_config) {
terminate_dird(0);
- exit(0);
}
+ my_name_is(0, NULL, director->hdr.name); /* set user defined name */
+
+ FDConnectTimeout = director->FDConnectTimeout;
+ SDConnectTimeout = director->SDConnectTimeout;
+
if (background) {
daemon_start();
init_stack_dump(); /* grab new pid */
}
- signal(SIGHUP, reload_config);
+ /* Create pid must come after we are a daemon -- so we have our final pid */
+ create_pid_file(director->pid_directory, "bacula-dir", director->DIRport);
+
+/* signal(SIGHUP, reload_config); */
init_console_msg(working_directory);
+ set_thread_concurrency(director->MaxConcurrentJobs * 2 +
+ 4 /* UA */ + 4 /* sched+watchdog+jobsvr+misc */);
+
Dmsg0(200, "Start UA server\n");
- start_UA_server(director->DIRport);
+ start_UA_server(director->DIRaddr, director->DIRport);
start_watchdog(); /* start network watchdog thread */
/* Main loop -- call scheduler to get next job to run */
while ((jcr = wait_for_next_job(runjob))) {
run_job(jcr); /* run job */
- if (runjob) /* command line, run a single job? */
+ if (runjob) { /* command line, run a single job? */
break; /* yes, terminate */
+ }
}
terminate_dird(0);
- exit(0); /* for compiler */
}
/* Cleanup and then exit */
exit(1);
}
already_here = TRUE;
+ delete_pid_file(director->pid_directory, "bacula-dir",
+ director->DIRport);
stop_watchdog();
signal(SIGCHLD, SIG_IGN); /* don't worry about children now */
term_scheduler();
}
free_config_resources();
term_ua_server();
- close_memory_pool(); /* free memory in pool */
term_msg(); /* terminate message handler */
+ close_memory_pool(); /* release free memory in pool */
sm_dump(False);
- exit(0);
+ exit(sig != 0);
}
/*
Dmsg0(200, "check_resources()\n");
if (!check_resources()) {
- Emsg1(M_ABORT, 0, _("Please correct configuration file: %s\n"), configfile);
+ Jmsg(NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
}
/* Reset globals */
job = (JOB *)GetNextRes(R_JOB, NULL);
director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
if (!director) {
- Emsg1(M_WARNING, 0, _("No Director resource defined in %s\n\
+ Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in %s\n\
Without that I don't know who I am :-(\n"), configfile);
OK = FALSE;
+ } else {
+ if (!director->working_directory) {
+ Jmsg(NULL, M_FATAL, 0, _("No working directory specified. Cannot continue.\n"));
+ OK = FALSE;
+ }
+ working_directory = director->working_directory;
+ if (!director->messages) { /* If message resource not specified */
+ director->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
+ if (!director->messages) {
+ Jmsg(NULL, M_FATAL, 0, _("No Messages resource defined in %s\n"), configfile);
+ OK = FALSE;
+ }
+ }
+ if (GetNextRes(R_DIRECTOR, (RES *)director) != NULL) {
+ Jmsg(NULL, M_FATAL, 0, _("Only one Director resource permitted in %s\n"),
+ configfile);
+ OK = FALSE;
+ }
}
- if (GetNextRes(R_DIRECTOR, (RES *)director) != NULL) {
- Emsg1(M_WARNING, 0, _("Only one Director resource permitted in %s\n"),
- configfile);
- OK = FALSE;
- }
- if (!director->working_directory) {
- Emsg0(M_WARNING, 0, _("No working directory specified. Cannot continue.\n"));
- OK = FALSE;
- }
- working_directory = director->working_directory;
+
if (!job) {
- Emsg1(M_WARNING, 0, _("No Job records defined in %s\n"), configfile);
+ Jmsg(NULL, M_FATAL, 0, _("No Job records defined in %s\n"), configfile);
OK = FALSE;
}
for (job=NULL; (job = (JOB *)GetNextRes(R_JOB, (RES *)job)); ) {
if (!job->client) {
- Emsg1(M_WARNING, 0, _("No Client record defined for job %s\n"), job->hdr.name);
+ Jmsg(NULL, M_FATAL, 0, _("No Client record defined for job %s\n"), job->hdr.name);
OK = FALSE;
}
- if (!job->fs) {
- Emsg1(M_WARNING, 0, _("No FileSet record defined for job %s\n"), job->hdr.name);
+ if (!job->fileset) {
+ Jmsg(NULL, M_FATAL, 0, _("No FileSet record defined for job %s\n"), job->hdr.name);
OK = FALSE;
}
if (!job->storage && job->JobType != JT_VERIFY) {
- Emsg1(M_WARNING, 0, _("No Storage resource defined for job %s\n"), job->hdr.name);
+ Jmsg(NULL, M_FATAL, 0, _("No Storage resource defined for job %s\n"), job->hdr.name);
OK = FALSE;
}
if (!job->pool) {
- Emsg1(M_WARNING, 0, _("No Pool resource defined for job %s\n"), job->hdr.name);
+ Jmsg(NULL, M_FATAL, 0, _("No Pool resource defined for job %s\n"), job->hdr.name);
OK = FALSE;
}
- if (job->client->catalog) {
+ if (job->client && job->client->catalog) {
CAT *catalog = job->client->catalog;
B_DB *db;
* Make sure we can open catalog, otherwise print a warning
* message because the server is probably not running.
*/
- db = db_init_database(catalog->db_name, catalog->db_user,
+ db = db_init_database(NULL, catalog->db_name, catalog->db_user,
catalog->db_password);
if (!db_open_database(db)) {
- Emsg1(M_WARNING, 0, "%s", db_strerror(db));
+ Jmsg(NULL, M_FATAL, 0, "%s", db_strerror(db));
+ } else {
+ /* If a pool is defined for this job, create the pool DB
+ * record if it is not already created.
+ */
+ if (job->pool) {
+ create_pool(db, job->pool);
+ }
+ db_close_database(db);
}
- db_close_database(db);
} else {
- Emsg1(M_WARNING, 0, _("No Catalog resource defined for client %s\n"),
+ if (job->client) {
+ Jmsg(NULL, M_FATAL, 0, _("No Catalog resource defined for client %s\n"),
job->client->hdr.name);
- OK = FALSE;
+ OK = FALSE;
+ }
}
}
UnlockRes();
+ if (OK) {
+ close_msg(NULL); /* close temp message handler */
+ init_msg(NULL, director->messages); /* open daemon message handler */
+ }
return OK;
}