From 72d219a24cd90c3d1a54fb31818ea898e93a79cd Mon Sep 17 00:00:00 2001 From: Jacob Oscarson Date: Wed, 15 May 2013 15:40:35 +0200 Subject: [PATCH] Writes an optional specified PID file on startup --- rq/scripts/__init__.py | 4 ++++ rq/scripts/rqworker.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/rq/scripts/__init__.py b/rq/scripts/__init__.py index fc31d09..6b45403 100644 --- a/rq/scripts/__init__.py +++ b/rq/scripts/__init__.py @@ -42,6 +42,10 @@ def setup_default_arguments(args, settings): if args.socket is None and socket: args.socket = socket + pid = settings.get('PID_FILE', False) + if args.pid is None and pid: + args.pid = pid + if args.db is None: args.db = settings.get('REDIS_DB', 0) diff --git a/rq/scripts/rqworker.py b/rq/scripts/rqworker.py index 29505ca..24aa714 100755 --- a/rq/scripts/rqworker.py +++ b/rq/scripts/rqworker.py @@ -27,6 +27,8 @@ def parse_args(): parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output') parser.add_argument('--quiet', '-q', action='store_true', default=False, help='Show less output') parser.add_argument('--sentry-dsn', action='store', default=None, metavar='URL', help='Report exceptions to this Sentry DSN') + parser.add_argument('--pid', '-i', action='store', default=None, + help='Write PID to this file') parser.add_argument('queues', nargs='*', help='The queues to listen on (default: \'default\')') return parser.parse_args() @@ -65,6 +67,10 @@ def main(): args.sentry_dsn = settings.get('SENTRY_DSN', os.environ.get('SENTRY_DSN', None)) + if args.pid: + with open(os.path.expanduser(args.pid), "w") as fp: + fp.write(str(os.getpid())) + setup_loghandlers_from_args(args) setup_redis(args)