]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird.c
Server address binding + bscan updates -- see kes25Sep02
[bacula/bacula] / bacula / src / dird / dird.c
index a9a49da782712b1c51e04b03884b6ab3c0010ec5..7401a340c6ea00e772372d2d2d49923074438c1b 100644 (file)
@@ -3,6 +3,8 @@
  *   Bacula Director daemon -- this is the main program
  *
  *     Kern Sibbald, March MM
+ *
+ *   Version $Id$
  */
 /*
    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
@@ -41,7 +43,7 @@ extern void term_scheduler();
 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);
 
@@ -89,6 +91,7 @@ int main (int argc, char *argv[])
 
    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));
 
@@ -160,35 +163,38 @@ int main (int argc, char *argv[])
       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 */
 
@@ -198,12 +204,12 @@ int main (int argc, char *argv[])
    /* 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 */
@@ -215,6 +221,8 @@ static void terminate_dird(int sig)
       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();
@@ -229,10 +237,10 @@ static void terminate_dird(int sig)
    }
    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);
 }
 
 /*
@@ -260,7 +268,7 @@ static void reload_config(int sig)
 
    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 */
@@ -291,42 +299,51 @@ static int check_resources()
    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;
 
@@ -334,19 +351,32 @@ Without that I don't know who I am :-(\n"), configfile);
          * 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;
 }