assistant: Smarter log file rotation, which takes free disk space into account.
This commit is contained in:
parent
4596b8810f
commit
d32289bab0
3 changed files with 25 additions and 4 deletions
|
@ -38,6 +38,7 @@ import Assistant.Unused
|
||||||
import Logs.Unused
|
import Logs.Unused
|
||||||
import Logs.Transfer
|
import Logs.Transfer
|
||||||
import Config.Files
|
import Config.Files
|
||||||
|
import Utility.DiskFree
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
#ifdef WITH_WEBAPP
|
#ifdef WITH_WEBAPP
|
||||||
import Assistant.WebApp.Types
|
import Assistant.WebApp.Types
|
||||||
|
@ -203,17 +204,27 @@ hourlyCheck = do
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
{- Rotate logs until log file size is < 1 mb. -}
|
{- Rotate logs once when total log file size is > 2 mb.
|
||||||
|
-
|
||||||
|
- If total log size is larger than the amount of free disk space,
|
||||||
|
- continue rotating logs until size is < 2 mb, even if this
|
||||||
|
- results in immediately losing the just logged data.
|
||||||
|
-}
|
||||||
checkLogSize :: Int -> Assistant ()
|
checkLogSize :: Int -> Assistant ()
|
||||||
checkLogSize n = do
|
checkLogSize n = do
|
||||||
f <- liftAnnex $ fromRepo gitAnnexLogFile
|
f <- liftAnnex $ fromRepo gitAnnexLogFile
|
||||||
logs <- liftIO $ listLogs f
|
logs <- liftIO $ listLogs f
|
||||||
totalsize <- liftIO $ sum <$> mapM filesize logs
|
totalsize <- liftIO $ sum <$> mapM filesize logs
|
||||||
when (totalsize > oneMegabyte) $ do
|
when (totalsize > 2 * oneMegabyte) $ do
|
||||||
notice ["Rotated logs due to size:", show totalsize]
|
notice ["Rotated logs due to size:", show totalsize]
|
||||||
liftIO $ openLog f >>= redirLog
|
liftIO $ openLog f >>= redirLog
|
||||||
when (n < maxLogs + 1) $
|
when (n < maxLogs + 1) $ do
|
||||||
checkLogSize $ n + 1
|
df <- liftIO $ getDiskFree $ takeDirectory f
|
||||||
|
case df of
|
||||||
|
Just free
|
||||||
|
| free < fromIntegral totalsize ->
|
||||||
|
checkLogSize (n + 1)
|
||||||
|
_ -> noop
|
||||||
where
|
where
|
||||||
filesize f = fromIntegral . fileSize <$> liftIO (getFileStatus f)
|
filesize f = fromIntegral . fileSize <$> liftIO (getFileStatus f)
|
||||||
|
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -30,6 +30,8 @@ git-annex (5.20140228) UNRELEASED; urgency=medium
|
||||||
* webdav: When built with a new enough haskell DAV (0.6), disable
|
* webdav: When built with a new enough haskell DAV (0.6), disable
|
||||||
the http response timeout, which was only 5 seconds.
|
the http response timeout, which was only 5 seconds.
|
||||||
* webapp: Include no-pty in ssh authorized_keys lines.
|
* webapp: Include no-pty in ssh authorized_keys lines.
|
||||||
|
* assistant: Smarter log file rotation, which takes free disk space
|
||||||
|
into account.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Fri, 28 Feb 2014 14:52:15 -0400
|
-- Joey Hess <joeyh@debian.org> Fri, 28 Feb 2014 14:52:15 -0400
|
||||||
|
|
||||||
|
|
|
@ -59,3 +59,11 @@ pgl@....:/....../.git/annex$ cat daemon.log.9
|
||||||
|
|
||||||
# End of transcript or log.
|
# End of transcript or log.
|
||||||
"""]]
|
"""]]
|
||||||
|
|
||||||
|
> Changed log rotation to only rotate 1 log per hour max,
|
||||||
|
> unless the total size of the log files is larger than the
|
||||||
|
> free disk space on the filesystem containing them.
|
||||||
|
>
|
||||||
|
> This way, runaway log growth will still be contained,
|
||||||
|
> but logs will generally rotate slowly enough to give plenty of time
|
||||||
|
> to see what's in them. [[done]] --[[Joey]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue