From 2c1528b8476a61cba3958bb54802f26a94bdbcd3 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 28 Oct 2017 18:35:50 +0200 Subject: [PATCH] Add -P daemon option to supress creating PID file --- bacula/manpages/bacula-dir.8 | 5 ++++- bacula/manpages/bacula-fd.8 | 5 ++++- bacula/manpages/bacula-sd.8 | 5 ++++- bacula/src/dird/dird.c | 18 ++++++++++++++---- bacula/src/filed/filed.c | 20 +++++++++++++++----- bacula/src/stored/stored.c | 33 +++++++++++++++++++++------------ 6 files changed, 62 insertions(+), 24 deletions(-) diff --git a/bacula/manpages/bacula-dir.8 b/bacula/manpages/bacula-dir.8 index 1fdc89bce1..662bc4e87c 100644 --- a/bacula/manpages/bacula-dir.8 +++ b/bacula/manpages/bacula-dir.8 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH BACULA\-DIR 8 "6 December 2009" "Kern Sibbald" "Network backup, recovery&verification" +.TH BACULA\-DIR 8 "28 October 2017" "Kern Sibbald" "Network backup, recovery&verification" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -43,6 +43,9 @@ Set the group/gid to run as. .BI \-m Print kaboom output (for debugging). .TP +.BI \-P +Do not create a PID file. +.TP .BI \-r\ job Run . .TP diff --git a/bacula/manpages/bacula-fd.8 b/bacula/manpages/bacula-fd.8 index 4f2c584a07..c5f2194604 100644 --- a/bacula/manpages/bacula-fd.8 +++ b/bacula/manpages/bacula-fd.8 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH BACULA\-SD 8 "6 December 2009" "Kern Sibbald" "Network backup, recovery & verification" +.TH BACULA\-SD 8 "28 October 2017" "Kern Sibbald" "Network backup, recovery & verification" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -48,6 +48,9 @@ Keep readall permission when dropping privileges. .BI \-m Print kaboom output (for debugging). .TP +.BI \-P +Do not create a PID file. +.TP .BI \-s No signals (for debugging). .TP diff --git a/bacula/manpages/bacula-sd.8 b/bacula/manpages/bacula-sd.8 index 56ee77891d..4a54c26f77 100644 --- a/bacula/manpages/bacula-sd.8 +++ b/bacula/manpages/bacula-sd.8 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH BACULA\-SD 8 "6 December 2009" "Kern Sibbald" "Network backup, recovery & verification" +.TH BACULA\-SD 8 "28 October 2017" "Kern Sibbald" "Network backup, recovery & verification" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -40,6 +40,9 @@ Run in foreground (for debugging). .BI \-g\ group Set the group/gid to run as. .TP +.BI \-P +Do not create a PID file. +.TP .BI \-p Proceed in spite of I/O errors .TP diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index c950080d59..545aa6fca5 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -64,6 +64,7 @@ void init_device_resources(); static char *runjob = NULL; static bool foreground = false; +static bool make_pid_file = true; /* create pid file */ static void init_reload(void); static CONFIG *config; static bool test_config = false; @@ -131,6 +132,7 @@ static void usage() " -g groupid\n" " -m print kaboom output (for debugging)\n" " -r run now\n" + " -P do not create pid file\n" " -s no signals\n" " -t test - read configuration and exit\n" " -u userid\n" @@ -190,7 +192,7 @@ int main (int argc, char *argv[]) setup_daemon_message_queue(); console_command = run_console_command; - while ((ch = getopt(argc, argv, "c:d:fg:mr:stu:v?T")) != -1) { + while ((ch = getopt(argc, argv, "c:d:fg:mPr:stu:v?T")) != -1) { switch (ch) { case 'c': /* specify config file */ if (configfile != NULL) { @@ -235,6 +237,10 @@ int main (int argc, char *argv[]) prt_kaboom = true; break; + case 'P': /* no pid file */ + make_pid_file = false; + break; + case 'r': /* run job */ if (runjob != NULL) { free(runjob); @@ -307,8 +313,10 @@ int main (int argc, char *argv[]) if (!test_config) { /* Create pid must come after we are a daemon -- so we have our final pid */ - create_pid_file(director->pid_directory, "bacula-dir", - get_first_port_host_order(director->DIRaddrs)); + if (make_pid_file) { + 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)); } @@ -673,7 +681,9 @@ void terminate_dird(int sig) unload_plugins(); if (!test_config) { 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)); + if (make_pid_file) { + delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs)); + } } term_scheduler(); term_job_server(); diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index b9a7d74108..1ac05f9864 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -46,6 +46,7 @@ extern struct s_cmds cmds[]; char *configfile = NULL; static bool test_config = false; static bool foreground = false; +static bool make_pid_file = true; /* create pid file */ static workq_t dir_workq; /* queue of work from Director */ static pthread_t server_tid; static CONFIG *config; @@ -63,6 +64,7 @@ static void usage() " -g groupid\n" " -k keep readall capabilities\n" " -m print kaboom output (for debugging)\n" + " -P do not create pid file\n" " -s no signals (for debugging)\n" " -t test configuration file and exit\n" " -T set trace on\n" @@ -99,7 +101,7 @@ int main (int argc, char *argv[]) daemon_start_time = time(NULL); setup_daemon_message_queue(); - while ((ch = getopt(argc, argv, "c:d:fg:kmstTu:v?D:")) != -1) { + while ((ch = getopt(argc, argv, "c:d:fg:kmPstTu:v?D:")) != -1) { switch (ch) { case 'c': /* configuration file */ if (configfile != NULL) { @@ -143,6 +145,10 @@ int main (int argc, char *argv[]) prt_kaboom = true; break; + case 'P': + make_pid_file = false; + break; + case 's': no_signals = true; break; @@ -228,8 +234,10 @@ int main (int argc, char *argv[]) lmgr_init_thread(); /* initialize the lockmanager stack */ /* Maximum 1 daemon at a time */ - create_pid_file(me->pid_directory, PROG_NAME, - get_first_port_host_order(me->FDaddrs)); + if (make_pid_file) { + create_pid_file(me->pid_directory, PROG_NAME, + get_first_port_host_order(me->FDaddrs)); + } read_state_file(me->working_directory, PROG_NAME, get_first_port_host_order(me->FDaddrs)); @@ -285,8 +293,10 @@ void terminate_filed(int sig) if (!test_config) { write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); - delete_pid_file(me->pid_directory, - "bacula-fd", get_first_port_host_order(me->FDaddrs)); + if (make_pid_file) { + delete_pid_file(me->pid_directory, + "bacula-fd", get_first_port_host_order(me->FDaddrs)); + } } if (configfile != NULL) { diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 9ca4c56024..3f0f9c40a9 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -64,7 +64,8 @@ static pthread_t server_tid; static bool server_tid_valid = false; /* Global static variables */ -static bool foreground = 0; +static bool foreground = false; +static bool make_pid_file = true; /* create pid file */ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static workq_t dird_workq; /* queue for processing connections */ static CONFIG *config; @@ -84,6 +85,7 @@ static void usage() " -g set groupid to group\n" " -m print kaboom output (for debugging)\n" " -p proceed despite I/O errors\n" + " -P do not create pid file\n" " -s no signals (for debugging)\n" " -t test - read config and exit\n" " -u userid to \n" @@ -148,7 +150,7 @@ int main (int argc, char *argv[]) Jmsg1(NULL, M_ABORT, 0, _("Tape block size (%d) is not a power of 2\n"), TAPE_BSIZE); } - while ((ch = getopt(argc, argv, "c:d:fg:mpstu:v?Ti")) != -1) { + while ((ch = getopt(argc, argv, "c:d:fg:mpPstu:v?Ti")) != -1) { switch (ch) { case 'c': /* configuration file */ if (configfile != NULL) { @@ -188,6 +190,11 @@ int main (int argc, char *argv[]) gid = optarg; break; + /* Temp code to enable new match_bsr() code, not documented */ + case 'i': + use_new_match_all = 1; + + break; case 'm': /* print kaboom output */ prt_kaboom = true; break; @@ -196,6 +203,10 @@ int main (int argc, char *argv[]) forge_on = true; break; + case 'P': /* no pid file */ + make_pid_file = false; + break; + case 's': /* no signals */ no_signals = true; break; @@ -212,11 +223,6 @@ int main (int argc, char *argv[]) verbose++; break; - /* Temp code to enable new match_bsr() code, not documented */ - case 'i': - use_new_match_all = 1; - break; - case '?': default: usage(); @@ -270,9 +276,10 @@ int main (int argc, char *argv[]) my_name_is(0, (char **)NULL, me->hdr.name); /* Set our real name */ - - create_pid_file(me->pid_directory, "bacula-sd", - get_first_port_host_order(me->sdaddrs)); + if (make_pid_file) { + create_pid_file(me->pid_directory, "bacula-sd", + get_first_port_host_order(me->sdaddrs)); + } read_state_file(me->working_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs)); @@ -741,8 +748,10 @@ void terminate_stored(int sig) if (!test_config) { write_state_file(me->working_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs)); - delete_pid_file(me->pid_directory, - "bacula-sd", get_first_port_host_order(me->sdaddrs)); + if (make_pid_file) { + delete_pid_file(me->pid_directory, + "bacula-sd", get_first_port_host_order(me->sdaddrs)); + } } Dmsg1(200, "In terminate_stored() sig=%d\n", sig); -- 2.39.5