* Version $Id$
*/
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2000-2003 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
extern int do_backup(JCR *jcr);
extern void backup_cleanup(void);
extern void start_UA_server(char *addr, int port);
-extern void run_job(JCR *jcr);
extern void init_job_server(int max_workers);
static char *configfile = NULL;
static char *runjob = NULL;
-
static int background = 1;
/* Globals Exported */
static void usage()
{
fprintf(stderr, _(
-"\nVersion: " VERSION " (" DATE ")\n\n"
+"\nVersion: " VERSION " (" BDATE ")\n\n"
"Usage: dird [-f -s] [-c config_file] [-d debug_level] [config_file]\n"
" -c <file> set configuration file to file\n"
" -dnn set debug level to nn\n"
" -f run in foreground (for debugging)\n"
+" -g groupid\n"
" -r <job> run <job> now\n"
" -s no signals\n"
" -t test - read configuration and exit\n"
+" -u userid\n"
+" -v verbose user messages\n"
" -? print this message.\n"
"\n"));
JCR *jcr;
int no_signals = FALSE;
int test_config = FALSE;
+ char *uid = NULL;
+ char *gid = NULL;
init_stack_dump();
my_name_is(argc, argv, "bacula-dir");
+ textdomain("bacula-dir");
init_msg(NULL, NULL); /* initialize message handler */
daemon_start_time = time(NULL);
- memset(&last_job, 0, sizeof(last_job));
- while ((ch = getopt(argc, argv, "c:d:fr:st?")) != -1) {
+ while ((ch = getopt(argc, argv, "c:d:fg:r:stu:v?")) != -1) {
switch (ch) {
case 'c': /* specify config file */
- if (configfile != NULL) {
- free(configfile);
- }
- configfile = bstrdup(optarg);
- break;
+ if (configfile != NULL) {
+ free(configfile);
+ }
+ configfile = bstrdup(optarg);
+ break;
- case 'd': /* set debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
- }
- Dmsg1(0, "Debug level = %d\n", debug_level);
- break;
+ case 'd': /* set debug level */
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ Dmsg1(0, "Debug level = %d\n", debug_level);
+ break;
- case 'f': /* run in foreground */
- background = FALSE;
- break;
+ case 'f': /* run in foreground */
+ background = FALSE;
+ break;
- case 'r': /* run job */
- if (runjob != NULL) {
- free(runjob);
- }
- if (optarg) {
- runjob = bstrdup(optarg);
- }
- break;
+ case 'g': /* set group id */
+ gid = optarg;
+ break;
+
+ case 'r': /* run job */
+ if (runjob != NULL) {
+ free(runjob);
+ }
+ if (optarg) {
+ runjob = bstrdup(optarg);
+ }
+ break;
- case 's': /* turn off signals */
- no_signals = TRUE;
- break;
+ case 's': /* turn off signals */
+ no_signals = TRUE;
+ break;
- case 't': /* test config */
- test_config = TRUE;
- break;
+ case 't': /* test config */
+ test_config = TRUE;
+ break;
- case '?':
- default:
- usage();
+ case 'u': /* set uid */
+ uid = optarg;
+ break;
+
+ case 'v': /* verbose */
+ verbose++;
+ break;
+
+ case '?':
+ default:
+ usage();
}
}
if (!no_signals) {
init_signals(terminate_dird);
}
- signal(SIGCHLD, SIG_IGN);
if (argc) {
if (configfile != NULL) {
parse_config(configfile);
if (!check_resources()) {
- Jmsg(NULL, M_ERROR_TERM, 0, "Please correct configuration file: %s\n", configfile);
+ Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
}
if (test_config) {
my_name_is(0, NULL, director->hdr.name); /* set user defined name */
- FDConnectTimeout = director->FDConnectTimeout;
- SDConnectTimeout = director->SDConnectTimeout;
+ FDConnectTimeout = (int)director->FDConnectTimeout;
+ SDConnectTimeout = (int)director->SDConnectTimeout;
if (background) {
daemon_start();
init_stack_dump(); /* grab new pid */
}
+ drop(uid, gid); /* reduce priveleges if requested */
+
/* 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);
delete_pid_file(director->pid_directory, "bacula-dir",
director->DIRport);
stop_watchdog();
- signal(SIGCHLD, SIG_IGN); /* don't worry about children now */
+// signal(SIGCHLD, SIG_IGN); /* don't worry about children now */
term_scheduler();
if (runjob) {
free(runjob);
}
/* Reset globals */
- working_directory = director->working_directory;
+ set_working_directory(director->working_directory);
FDConnectTimeout = director->FDConnectTimeout;
SDConnectTimeout = director->SDConnectTimeout;
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;
+ set_working_directory(director->working_directory);
if (!director->messages) { /* If message resource not specified */
director->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
if (!director->messages) {
* message because the server is probably not running.
*/
db = db_init_database(NULL, catalog->db_name, catalog->db_user,
- catalog->db_password);
- if (!db_open_database(db)) {
- Jmsg(NULL, M_FATAL, 0, "%s", db_strerror(db));
+ catalog->db_password, catalog->db_address,
+ catalog->db_port, catalog->db_socket);
+ if (!db || !db_open_database(NULL, db)) {
+ Jmsg(NULL, M_FATAL, 0, _("Could not open database \"%s\".\n"),
+ catalog->db_name);
+ if (db) {
+ Jmsg(NULL, M_FATAL, 0, _("%s"), db_strerror(db));
+ }
+ OK = FALSE;
} 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);
+ create_pool(NULL, db, job->pool, POOL_OP_UPDATE); /* update request */
}
- db_close_database(db);
+ /* Set default value in all counters */
+ for (COUNTER *counter=NULL; (counter = (COUNTER *)GetNextRes(R_COUNTER, (RES *)counter)); ) {
+ /* Write to catalog? */
+ if (!counter->created && counter->Catalog == catalog) {
+ COUNTER_DBR cr;
+ bstrncpy(cr.Counter, counter->hdr.name, sizeof(cr.Counter));
+ cr.MinValue = counter->MinValue;
+ cr.MaxValue = counter->MaxValue;
+ cr.CurrentValue = counter->MinValue;
+ if (counter->WrapCounter) {
+ bstrncpy(cr.WrapCounter, counter->WrapCounter->hdr.name, sizeof(cr.WrapCounter));
+ } else {
+ cr.WrapCounter[0] = 0; /* empty string */
+ }
+ if (db_create_counter_record(NULL, db, &cr)) {
+ counter->CurrentValue = cr.CurrentValue;
+ counter->created = true;
+ Dmsg2(100, "Create counter %s val=%d\n", counter->hdr.name, counter->CurrentValue);
+ }
+ }
+ if (!counter->created) {
+ counter->CurrentValue = counter->MinValue; /* default value */
+ }
+ }
+ db_close_database(NULL, db);
}
+
} else {
if (job->client) {
Jmsg(NULL, M_FATAL, 0, _("No Catalog resource defined for client %s\n"),