Skip to content

Commit

Permalink
Fix log rotation in daemon mode
Browse files Browse the repository at this point in the history
When daemon mode is started as root and the user is changed to a lower
privilege user the log rotation breaks.  This is because the log file is still
owned by root.

Now just before we switch user the log file user is changed to the new user.

Fixes bug# 1079743

Change-Id: Ia35e44bf9c891ce85a66e64989f97d3195520891
  • Loading branch information
LinuxJedi committed Nov 16, 2012
1 parent d01c2a8 commit dbda529
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Basic commands:
$ libra_worker --debug --nodaemon

NOTE: When running the worker in daemon mode, you must make sure that the
directory where the PID file will be (-p/--pid option) exists and is writable
directory where the PID file will be (-p/--pid option) and the directory where
the log files will be written (-l/--logfile option) exists and is writable
by the user/group specified with the --user and --group options. Also, the
Python module used to start the daemon process does not like it when the PID
file already exists at startup.
Expand Down
3 changes: 3 additions & 0 deletions libra/mgm/mgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def main():
except KeyError:
logger.critical("Invalid user: %s" % args.user)
return 1
# NOTE(LinuxJedi): we are switching user so need to switch
# the ownership of the log file for rotation
os.chown(logger.handlers[0].baseFilename, context.uid, -1)
if args.group:
try:
context.gid = grp.getgrnam(args.group).gr_gid
Expand Down
4 changes: 4 additions & 0 deletions libra/worker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
eventlet.monkey_patch()

import daemon
import os
import daemon.pidfile
import grp
import pwd
Expand Down Expand Up @@ -137,6 +138,9 @@ def main():
except KeyError:
logger.critical("Invalid user: %s" % args.user)
return 1
# NOTE(LinuxJedi): we are switching user so need to switch
# the ownership of the log file for rotation
os.chown(logger.handlers[0].baseFilename, context.uid, -1)
if args.group:
try:
context.gid = grp.getgrnam(args.group).gr_gid
Expand Down

0 comments on commit dbda529

Please sign in to comment.