Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright (c) 2014, Facebook, Inc. All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. #
# Only attempt to import if we have it...
"""Log what `pidfile` we'll be using to `logger`"""
"""Returns the pid in `pidfile` or None if the file doesn't exist.""" raise
"""Sends signal `signum` to `pid`, logging messages to `logger`"""
"""Daemonizes the `command` function.
Uses `name` for syslogging, `pidfile` for the pid file, and logs messages to `logger` or a child logger of logger as appropriate. """ # This is the only function that requires daemonize. # Bail if we don't have it. raise Exception("Need `daemonize` to run as daemon")
app=name, pid=pidfile, action=command, logger=logging.getLogger(logger.name + ".daemon") )
# Daemonize.start() calls sys.exit() for parent thread, so nothing # after this will execute.
"""Sends `signum` to the pid specified by `pidfile`.
Logs messages to `logger`. Returns True if the process is not running, or signal was sent successfully. Returns False if the process for the pidfile was running and there was an error sending the signal."""
except OSError as e: if e.errno == errno.ESRCH: logger.warning("Daemon not running (Stale lockfile)") os.remove(pidfile) return True elif e.errno == errno.EPERM: logger.error("Unable to kill %d (EPERM)", daemon_pid) return False raise
"""Checks to see if the process for the pid in `pidfile` is running.
Logs messages to `logger`. Returns True if there is a program for the running pid. Returns False if not or if there was an error polling the pid."""
# Sending signal 0 simply checks if the pid can be sent a signal # and makes sure the pid exist. It doesn't interrupt the running # program in any way.
logger.warning("Daemon not running (Stale lockfile)") os.remove(pidfile) return False raise |