-def _already_running():
- """If a pidfile has been configured and that pidfile already exists and is
- locked by a running process, returns True. Otherwise, returns False."""
- if _pidfile is not None:
- try:
- file = open(_pidfile, "r+")
- try:
- try:
- fcntl.lockf(file, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except IOError, e:
- if e.errno in [errno.EACCES, errno.EAGAIN]:
- return True
- logging.error("error locking %s (%s)"
- % (_pidfile, os.strerror(e.errno)))
- return False
- finally:
- # This releases the lock, which we don't really want.
- file.close()
- except IOError, e:
- if e.errno == errno.ENOENT:
- return False
- logging.error("error opening %s (%s)"
- % (_pidfile, os.strerror(e.errno)))
- return False
-
-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 _already_running():
- if not _overwrite_pidfile:
- msg = "%s: already running" % _pidfile
- logging.error("%s, aborting" % msg)
- sys.stderr.write("%s\n" % msg)
- sys.exit(1)
- else:
- logging.warn("%s: %s already running"
- % (get_pidfile(), ovs.util.PROGRAM_NAME))