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:
4
debian/ovs-monitor-ipsec
vendored
4
debian/ovs-monitor-ipsec
vendored
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/python
|
#!/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");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with 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)
|
"(use --help for help)\n" % ovs.util.PROGRAM_NAME)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ovs.daemon.die_if_already_running()
|
|
||||||
|
|
||||||
remote = args[0]
|
remote = args[0]
|
||||||
idl = ovs.db.idl.Idl(remote, "Open_vSwitch", monitor_uuid_schema_cb)
|
idl = ovs.db.idl.Idl(remote, "Open_vSwitch", monitor_uuid_schema_cb)
|
||||||
|
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ is_chdir_enabled(void)
|
|||||||
return chdir_;
|
return chdir_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normally, die_if_already_running() will terminate the program with a message
|
/* Normally, daemonize() or damonize_start() will terminate the program with a
|
||||||
* if a locked pidfile already exists. If this function is called,
|
* message if a locked pidfile already exists. If this function is called, an
|
||||||
* die_if_already_running() will merely log a warning. */
|
* existing pidfile will be replaced, with a warning. */
|
||||||
void
|
void
|
||||||
ignore_existing_pidfile(void)
|
ignore_existing_pidfile(void)
|
||||||
{
|
{
|
||||||
@@ -141,7 +141,7 @@ daemon_set_monitor(void)
|
|||||||
|
|
||||||
/* If a locked pidfile exists, issue a warning message and, unless
|
/* If a locked pidfile exists, issue a warning message and, unless
|
||||||
* ignore_existing_pidfile() has been called, terminate the program. */
|
* ignore_existing_pidfile() has been called, terminate the program. */
|
||||||
void
|
static void
|
||||||
die_if_already_running(void)
|
die_if_already_running(void)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@@ -449,6 +449,7 @@ daemonize_start(void)
|
|||||||
/* Running in daemon process. */
|
/* Running in daemon process. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
die_if_already_running();
|
||||||
make_pidfile();
|
make_pidfile();
|
||||||
|
|
||||||
/* Make sure that the unixctl commands for vlog get registered in a
|
/* Make sure that the unixctl commands for vlog get registered in a
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ void daemon_set_monitor(void);
|
|||||||
void daemonize(void);
|
void daemonize(void);
|
||||||
void daemonize_start(void);
|
void daemonize_start(void);
|
||||||
void daemonize_complete(void);
|
void daemonize_complete(void);
|
||||||
void die_if_already_running(void);
|
|
||||||
void ignore_existing_pidfile(void);
|
void ignore_existing_pidfile(void);
|
||||||
void daemon_usage(void);
|
void daemon_usage(void);
|
||||||
pid_t read_pidfile(const char *name);
|
pid_t read_pidfile(const char *name);
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ main(int argc, char *argv[])
|
|||||||
parse_options(argc, argv, &file_name, &remotes, &unixctl_path,
|
parse_options(argc, argv, &file_name, &remotes, &unixctl_path,
|
||||||
&run_command);
|
&run_command);
|
||||||
|
|
||||||
die_if_already_running();
|
|
||||||
daemonize_start();
|
daemonize_start();
|
||||||
|
|
||||||
error = ovsdb_file_open(file_name, false, &db, &file);
|
error = ovsdb_file_open(file_name, false, &db, &file);
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ def is_chdir_enabled():
|
|||||||
return _chdir
|
return _chdir
|
||||||
|
|
||||||
def ignore_existing_pidfile():
|
def ignore_existing_pidfile():
|
||||||
"""Normally, die_if_already_running() will terminate the program with a
|
"""Normally, daemonize() or daemonize_start() will terminate the program
|
||||||
message if a locked pidfile already exists. If this function is called,
|
with a message if a locked pidfile already exists. If this function is
|
||||||
die_if_already_running() will merely log a warning."""
|
called, an existing pidfile will be replaced, with a warning."""
|
||||||
global _overwrite_pidfile
|
global _overwrite_pidfile
|
||||||
_overwrite_pidfile = True
|
_overwrite_pidfile = True
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ def set_monitor():
|
|||||||
global _monitor
|
global _monitor
|
||||||
_monitor = True
|
_monitor = True
|
||||||
|
|
||||||
def die_if_already_running():
|
def _die_if_already_running():
|
||||||
"""If a locked pidfile exists, issue a warning message and, unless
|
"""If a locked pidfile exists, issue a warning message and, unless
|
||||||
ignore_existing_pidfile() has been called, terminate the program."""
|
ignore_existing_pidfile() has been called, terminate the program."""
|
||||||
if _pidfile is None:
|
if _pidfile is None:
|
||||||
@@ -343,6 +343,7 @@ def daemonize_start():
|
|||||||
_monitor_daemon(daemon_pid)
|
_monitor_daemon(daemon_pid)
|
||||||
# Running in daemon process
|
# Running in daemon process
|
||||||
|
|
||||||
|
_die_if_already_running()
|
||||||
_make_pidfile()
|
_make_pidfile()
|
||||||
|
|
||||||
def daemonize_complete():
|
def daemonize_complete():
|
||||||
|
|||||||
@@ -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");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with 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))
|
% (ovs.util.PROGRAM_NAME, key))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ovs.daemon.die_if_already_running()
|
|
||||||
ovs.daemon.daemonize_start()
|
ovs.daemon.daemonize_start()
|
||||||
if bail:
|
if bail:
|
||||||
sys.stderr.write("%s: exiting after daemonize_start() as requested\n"
|
sys.stderr.write("%s: exiting after daemonize_start() as requested\n"
|
||||||
|
|||||||
@@ -182,8 +182,6 @@ do_listen(int argc OVS_UNUSED, char *argv[])
|
|||||||
bool done;
|
bool done;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
die_if_already_running();
|
|
||||||
|
|
||||||
error = jsonrpc_pstream_open(argv[1], &pstream);
|
error = jsonrpc_pstream_open(argv[1], &pstream);
|
||||||
if (error) {
|
if (error) {
|
||||||
ovs_fatal(error, "could not listen on \"%s\"", argv[1]);
|
ovs_fatal(error, "could not listen on \"%s\"", argv[1]);
|
||||||
|
|||||||
@@ -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");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with 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
|
return done
|
||||||
|
|
||||||
def do_listen(name):
|
def do_listen(name):
|
||||||
ovs.daemon.die_if_already_running()
|
|
||||||
|
|
||||||
error, pstream = ovs.stream.PassiveStream.open(name)
|
error, pstream = ovs.stream.PassiveStream.open(name)
|
||||||
if error:
|
if error:
|
||||||
sys.stderr.write("could not listen on \"%s\": %s\n"
|
sys.stderr.write("could not listen on \"%s\": %s\n"
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ main(int argc, char *argv[])
|
|||||||
ovs_fatal(0, "no active or passive switch connections");
|
ovs_fatal(0, "no active or passive switch connections");
|
||||||
}
|
}
|
||||||
|
|
||||||
die_if_already_running();
|
|
||||||
daemonize_start();
|
daemonize_start();
|
||||||
|
|
||||||
retval = unixctl_server_create(unixctl_path, &unixctl);
|
retval = unixctl_server_create(unixctl_path, &unixctl);
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ main(int argc, char *argv[])
|
|||||||
parse_options(argc, argv, &s);
|
parse_options(argc, argv, &s);
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
die_if_already_running();
|
|
||||||
daemonize_start();
|
daemonize_start();
|
||||||
|
|
||||||
/* Start listening for ovs-appctl requests. */
|
/* Start listening for ovs-appctl requests. */
|
||||||
|
|||||||
@@ -1289,7 +1289,6 @@ main(int argc, char *argv[])
|
|||||||
process_init();
|
process_init();
|
||||||
ovsrec_init();
|
ovsrec_init();
|
||||||
|
|
||||||
die_if_already_running();
|
|
||||||
daemonize_start();
|
daemonize_start();
|
||||||
|
|
||||||
retval = unixctl_server_create(NULL, &unixctl);
|
retval = unixctl_server_create(NULL, &unixctl);
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ main(int argc, char *argv[])
|
|||||||
process_init();
|
process_init();
|
||||||
ovsrec_init();
|
ovsrec_init();
|
||||||
|
|
||||||
die_if_already_running();
|
|
||||||
daemonize_start();
|
daemonize_start();
|
||||||
|
|
||||||
retval = unixctl_server_create(NULL, &unixctl);
|
retval = unixctl_server_create(NULL, &unixctl);
|
||||||
|
|||||||
@@ -254,8 +254,6 @@ def main(argv):
|
|||||||
"(use --help for help)\n" % ovs.util.PROGRAM_NAME)
|
"(use --help for help)\n" % ovs.util.PROGRAM_NAME)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ovs.daemon.die_if_already_running()
|
|
||||||
|
|
||||||
remote = args[0]
|
remote = args[0]
|
||||||
idl = ovs.db.idl.Idl(remote, "Open_vSwitch", monitor_uuid_schema_cb)
|
idl = ovs.db.idl.Idl(remote, "Open_vSwitch", monitor_uuid_schema_cb)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user