From 3fab0b09236b25886f990078cbc5d8467c8233f0 Mon Sep 17 00:00:00 2001 From: Volodymyr Burenin Date: Mon, 21 Nov 2016 00:03:13 -0600 Subject: [PATCH] Move lock file from /tmp to /var/run/lock. Do not run logrotate immediately on boot. (#3250) * Run logrotate after expected timeout to ensure systemd finishes its initial work and system is up. Move lock file from /tmp to /var/run/lock. --- pkg/filelock/flock.go | 3 ++- pkg/logmgr/logmgr.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/filelock/flock.go b/pkg/filelock/flock.go index 2970f35de1..6ec6435b5f 100644 --- a/pkg/filelock/flock.go +++ b/pkg/filelock/flock.go @@ -36,7 +36,7 @@ type FileLock struct { func NewFileLock(lockName string) *FileLock { return &FileLock{ LockName: lockName, - LockFile: filepath.Join(os.TempDir(), lockName), + LockFile: filepath.Join("/var/run/lock", lockName), } } @@ -65,6 +65,7 @@ func (fl *FileLock) Release() error { if fl.fh == nil { panic("Attempt to release not acquired lock!") } + syscall.Flock(int(fl.fh.Fd()), syscall.LOCK_UN) err := fl.fh.Close() fl.fh = nil fl.mu.Unlock() diff --git a/pkg/logmgr/logmgr.go b/pkg/logmgr/logmgr.go index 6eb1d4c375..a9a241b1a5 100644 --- a/pkg/logmgr/logmgr.go +++ b/pkg/logmgr/logmgr.go @@ -169,9 +169,8 @@ func (lm *LogManager) Start() error { for { lm.loopsCount++ if lm.loopsCount%10 == 0 { - lm.op.Debugf("logrotate has been run %s times") + lm.op.Debugf("logrotate has been run %d times", lm.loopsCount) } - lm.rotateLogs() select { case <-time.After(lm.runInterval): case <-lm.closed: @@ -179,6 +178,7 @@ func (lm *LogManager) Start() error { lm.wg.Done() return } + lm.rotateLogs() } }() })