Permalink
Browse files

Add user and group options to celerydaemon command.

  • Loading branch information...
1 parent 24f0c9a commit d47cb94ade20c72c4d5de5fd9274f521f8dbf381 @oremj oremj committed with Jeff Balogh Sep 15, 2010
Showing with 16 additions and 4 deletions.
  1. +16 −4 apps/extras/management/commands/celerydaemon.py
@@ -1,3 +1,5 @@
+import grp
+import pwd
from optparse import make_option
from django.core.management.base import BaseCommand
@@ -9,7 +11,11 @@
opts = list(BaseCommand.option_list +
filter(lambda o: '--version' not in o._long_opts, OPTION_LIST))
-opts.append(make_option('--pidfile'))
+opts.extend([
+ make_option('--pidfile'),
+ make_option('--user', help='Run celery as this user'),
+ make_option('--group', help='Run celery as this group'),
+])
class Command(BaseCommand):
@@ -18,10 +24,16 @@ class Command(BaseCommand):
option_list = opts
def handle(self, *args, **opts):
- pidfile = None
+ pidfile = uid = gid = None
+
if opts['pidfile']:
pidfile = daemon.pidlockfile.PIDLockFile(opts['pidfile'])
- del opts['pidfile']
+ if opts['user']:
+ uid = pwd.getpwnam(opts['user']).pw_uid
+ if opts['group']:
+ gid = grp.getgrnam(opts['group']).gr_gid
+
+ del opts['pidfile'], opts['group'], opts['user']
- with daemon.DaemonContext(pidfile=pidfile):
+ with daemon.DaemonContext(pidfile=pidfile, uid=uid, gid=gid):
run_worker(**opts)

0 comments on commit d47cb94

Please sign in to comment.