2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

daemon: Integrate checking for an existing pidfile into daemonize_start().

Until now, it has been the responsibility of an individual daemon to call
die_if_already_running() at an appropriate time.  A long time ago, this
had to happen *before* daemonizing, because once the process daemonized
itself there was no way to report failure to the process that originally
started the daemon.  With the introduction of daemonize_start(), this is
now possible, but we haven't been taking advantage of it.

Therefore, this commit integrates the die_if_already_running() call into
daemonize_start() and deletes the calls to it from individual daemons.
This commit is contained in:
Ben Pfaff
2011-03-31 09:44:30 -07:00
parent af9a144207
commit 00c0858987
13 changed files with 13 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/python
# Copyright (c) 2009, 2010 Nicira Networks
# Copyright (c) 2009, 2010, 2011 Nicira Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -450,8 +450,6 @@ def main(argv):
"(use --help for help)\n" % ovs.util.PROGRAM_NAME)
sys.exit(1)
ovs.daemon.die_if_already_running()
remote = args[0]
idl = ovs.db.idl.Idl(remote, "Open_vSwitch", monitor_uuid_schema_cb)

View File

@@ -107,9 +107,9 @@ is_chdir_enabled(void)
return chdir_;
}
/* Normally, die_if_already_running() will terminate the program with a message
* if a locked pidfile already exists. If this function is called,
* die_if_already_running() will merely log a warning. */
/* Normally, daemonize() or damonize_start() will terminate the program with a
* message if a locked pidfile already exists. If this function is called, an
* existing pidfile will be replaced, with a warning. */
void
ignore_existing_pidfile(void)
{
@@ -141,7 +141,7 @@ daemon_set_monitor(void)
/* If a locked pidfile exists, issue a warning message and, unless
* ignore_existing_pidfile() has been called, terminate the program. */
void
static void
die_if_already_running(void)
{
pid_t pid;
@@ -449,6 +449,7 @@ daemonize_start(void)
/* Running in daemon process. */
}
die_if_already_running();
make_pidfile();
/* Make sure that the unixctl commands for vlog get registered in a

View File

@@ -67,7 +67,6 @@ void daemon_set_monitor(void);
void daemonize(void);
void daemonize_start(void);
void daemonize_complete(void);
void die_if_already_running(void);
void ignore_existing_pidfile(void);
void daemon_usage(void);
pid_t read_pidfile(const char *name);

View File

@@ -101,7 +101,6 @@ main(int argc, char *argv[])
parse_options(argc, argv, &file_name, &remotes, &unixctl_path,
&run_command);
die_if_already_running();
daemonize_start();
error = ovsdb_file_open(file_name, false, &db, &file);

View File

@@ -89,9 +89,9 @@ def is_chdir_enabled():
return _chdir
def ignore_existing_pidfile():
"""Normally, die_if_already_running() will terminate the program with a
message if a locked pidfile already exists. If this function is called,
die_if_already_running() will merely log a warning."""
"""Normally, daemonize() or daemonize_start() will terminate the program
with a message if a locked pidfile already exists. If this function is
called, an existing pidfile will be replaced, with a warning."""
global _overwrite_pidfile
_overwrite_pidfile = True
@@ -111,7 +111,7 @@ def set_monitor():
global _monitor
_monitor = True
def die_if_already_running():
def _die_if_already_running():
"""If a locked pidfile exists, issue a warning message and, unless
ignore_existing_pidfile() has been called, terminate the program."""
if _pidfile is None:
@@ -343,6 +343,7 @@ def daemonize_start():
_monitor_daemon(daemon_pid)
# Running in daemon process
_die_if_already_running()
_make_pidfile()
def daemonize_complete():

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2010 Nicira Networks.
# Copyright (c) 2010, 2011 Nicira Networks.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -45,7 +45,6 @@ def main(argv):
% (ovs.util.PROGRAM_NAME, key))
sys.exit(1)
ovs.daemon.die_if_already_running()
ovs.daemon.daemonize_start()
if bail:
sys.stderr.write("%s: exiting after daemonize_start() as requested\n"

View File

@@ -182,8 +182,6 @@ do_listen(int argc OVS_UNUSED, char *argv[])
bool done;
int error;
die_if_already_running();
error = jsonrpc_pstream_open(argv[1], &pstream);
if (error) {
ovs_fatal(error, "could not listen on \"%s\"", argv[1]);

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2009, 2010 Nicira Networks
# Copyright (c) 2009, 2010, 2011 Nicira Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -49,8 +49,6 @@ def handle_rpc(rpc, msg):
return done
def do_listen(name):
ovs.daemon.die_if_already_running()
error, pstream = ovs.stream.PassiveStream.open(name)
if error:
sys.stderr.write("could not listen on \"%s\": %s\n"

View File

@@ -139,7 +139,6 @@ main(int argc, char *argv[])
ovs_fatal(0, "no active or passive switch connections");
}
die_if_already_running();
daemonize_start();
retval = unixctl_server_create(unixctl_path, &unixctl);

View File

@@ -103,7 +103,6 @@ main(int argc, char *argv[])
parse_options(argc, argv, &s);
signal(SIGPIPE, SIG_IGN);
die_if_already_running();
daemonize_start();
/* Start listening for ovs-appctl requests. */

View File

@@ -1289,7 +1289,6 @@ main(int argc, char *argv[])
process_init();
ovsrec_init();
die_if_already_running();
daemonize_start();
retval = unixctl_server_create(NULL, &unixctl);

View File

@@ -74,7 +74,6 @@ main(int argc, char *argv[])
process_init();
ovsrec_init();
die_if_already_running();
daemonize_start();
retval = unixctl_server_create(NULL, &unixctl);

View File

@@ -254,8 +254,6 @@ def main(argv):
"(use --help for help)\n" % ovs.util.PROGRAM_NAME)
sys.exit(1)
ovs.daemon.die_if_already_running()
remote = args[0]
idl = ovs.db.idl.Idl(remote, "Open_vSwitch", monitor_uuid_schema_cb)