Add user/group options for daemon mode.
This commit is contained in:
@@ -132,6 +132,14 @@ class Options(object):
|
|||||||
),
|
),
|
||||||
help='log file to use (ignored with --nodaemon)'
|
help='log file to use (ignored with --nodaemon)'
|
||||||
)
|
)
|
||||||
|
self.parser.add_argument(
|
||||||
|
'--user', dest='user',
|
||||||
|
help='user to use for daemon mode'
|
||||||
|
)
|
||||||
|
self.parser.add_argument(
|
||||||
|
'--group', dest='group',
|
||||||
|
help='group to use for daemon mode'
|
||||||
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# We have to set defaults from the config AFTER all add_argument()
|
# We have to set defaults from the config AFTER all add_argument()
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import daemon
|
import daemon
|
||||||
|
import grp
|
||||||
import lockfile
|
import lockfile
|
||||||
|
import pwd
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -68,6 +70,18 @@ def main():
|
|||||||
umask=0o022,
|
umask=0o022,
|
||||||
pidfile=lockfile.FileLock(args.pid)
|
pidfile=lockfile.FileLock(args.pid)
|
||||||
)
|
)
|
||||||
|
if args.user:
|
||||||
|
try:
|
||||||
|
context.uid = pwd.getpwnam(args.user).pw_uid
|
||||||
|
except KeyError:
|
||||||
|
logger.critical("Invalid user: %s" % args.user)
|
||||||
|
return 1
|
||||||
|
if args.group:
|
||||||
|
try:
|
||||||
|
context.gid = grp.getgrnam(args.group).gr_gid
|
||||||
|
except KeyError:
|
||||||
|
logger.critical("Invalid group: %s" % args.group)
|
||||||
|
return 1
|
||||||
with context:
|
with context:
|
||||||
server.main()
|
server.main()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user