[augeas-devel] [PATCH] Add logrotate and associated test
Raphaël Pinson
raphink at gmail.com
Wed Jul 23 14:18:00 UTC 2008
I can't say I'm a big fan of the oneline (pre|post)rotate hooks (I prefer to
split them into 'line' nodes) but at least it works now.
On Wed, Jul 23, 2008 at 4:16 PM, <raphink at gmail.com> wrote:
> # HG changeset patch
> # User rpinson at lab64.echo-net.net
> # Date 1216822552 -7200
> # Node ID af5cf155aa832b7e0e048926c6818b2b9499a0db
> # Parent 8f1909e6885c5f1ac7007b22a28f7f9a8559b873
> Add logrotate and associated test
>
> diff -r 8f1909e6885c -r af5cf155aa83 lenses/logrotate.aug
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/lenses/logrotate.aug Wed Jul 23 16:15:52 2008 +0200
> @@ -0,0 +1,95 @@
> +(* Logrotate module for Augeas *)
> +(* Author: Raphael Pinson <raphink at gmail.com> *)
> +(* *)
> +(* Supported : *)
> +(* - defaults *)
> +(* - rules *)
> +(* - (pre|post)rotate entries *)
> +(* *)
> +(* Todo : *)
> +(* *)
> +
> +module Logrotate =
> + autoload xfm
> +
> + let sep_spc = Util.del_ws_spc
> + let eol = Util.del_str "\n"
> + let num = /[0-9]+/
> + let word = /[^,# \n\t{}]+/
> +
> +
> + (* define comments and empty lines *)
> + let comment (indent:string) = [ label "comment" . del /[ \t]*/ indent .
> del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . eol ]
> + let empty = [ del /[ \t]*\n/ "" ]
> +
> +
> + (* Useful functions *)
> +
> + let select_to_eol (kw:string) (select:regexp) (indent:string) = [ del
> /[ \t]*/ indent . label kw . store select . eol ]
> + let value_to_eol (kw:string) (value:regexp) (indent:string ) = [ del
> /[ \t]*/ indent . key kw . sep_spc . store value . eol ]
> + let flag_to_eol (kw:string) (indent:string) = [ del
> /[ \t]*/ indent . key kw . eol ]
> +
> +
> + (* Defaults *)
> +
> + let create (indent:string ) = [ del /[ \t]*/ indent . key "create" .
> + ( sep_spc . [ label "mode" . store num ] . sep_spc
> .
> + [ label "owner" . store word ] . sep_spc .
> + [ label "group" . store word ])?
> + . eol ]
> +
> + let attrs (indent:string) = select_to_eol "schedule"
> /(daily|weekly|monthly)/ indent
> + | value_to_eol "rotate" num indent
> + | create indent
> + | flag_to_eol "nocreate" indent
> + | value_to_eol "include" word indent
> + | select_to_eol "missingok" /(no)?missingok/ indent
> + | select_to_eol "compress" /(no)?compress/ indent
> + | select_to_eol "delaycompress" /(no)?delaycompress/ indent
> + | select_to_eol "ifempty" /(not)?ifempty/ indent
> + | flag_to_eol "sharedscripts" indent
> + | value_to_eol "size" word indent
> + | value_to_eol "tabooext" word indent
> + | value_to_eol "olddir" word indent
> + | flag_to_eol "noolddir" indent
> + | value_to_eol "mail" word indent
> + | flag_to_eol "mailfirst" indent
> + | flag_to_eol "maillast" indent
> + | flag_to_eol "nomail" indent
> + | value_to_eol "errors" word indent
> + | value_to_eol "extension" word indent
> +
> +
> + (* Define hooks *)
> +
> +
> + let hook_lines = store ( ( /.*/ . "\n") - /[ \t]*endscript[ \t]*\n/ )*
> +
> + let hook_func (func_type:string) = [
> + del /[ \t]*/ "\t" . key func_type . eol .
> + hook_lines .
> + del /[ \t]*endscript\n/ "\tendscript\n" ]
> +
> + let hooks = hook_func "postrotate"
> + | hook_func "prerotate"
> +
> + (* Define rule *)
> +
> + let body = Util.del_str "{\n"
> + . ( comment "\t" | attrs "\t" | hooks | empty )*
> + . Util.del_str "}\n"
> +
> + let rule =
> + [ label "rule" .
> + [ label "file" . store word ] .
> + [ del /[ \t]+/ " " . label "file" . store word ]* .
> + del /[ \t\n]*/ " " . body ]
> +
> + let lns = ( comment "" | empty | attrs "" | rule )*
> +
> + let filter = incl "/etc/logrotate.d/*"
> + . incl "/etc/logrotate.conf"
> + . Util.stdexcl
> +
> + let xfm = transform lns filter
> +
> diff -r 8f1909e6885c -r af5cf155aa83 lenses/tests/test_logrotate.aug
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/lenses/tests/test_logrotate.aug Wed Jul 23 16:15:52 2008 +0200
> @@ -0,0 +1,126 @@
> +module Test_logrotate =
> +
> + let conf = "# see man logrotate for details
> +# rotate log files weekly
> +weekly
> +
> +# keep 4 weeks worth of backlogs
> +rotate 4
> +
> +# create new (empty) log files after rotating old ones
> +create
> +
> +# uncomment this if you want your log files compressed
> +#compress
> +
> +# packages drop log rotation information into this directory
> +include /etc/logrotate.d
> +
> +# no packages own wtmp, or btmp -- we'll rotate them here
> +/var/log/wtmp
> +{
> + missingok
> + monthly
> + create 0664 root utmp
> + rotate 1
> +}
> +
> +/var/log/btmp /var/log/btmp* {
> + missingok
> + # ftpd doesn't handle SIGHUP properly
> + monthly
> + create 0664 root utmp
> + rotate 1
> +}
> +/var/log/vsftpd.log {
> + # ftpd doesn't handle SIGHUP properly
> + nocompress
> + missingok
> + notifempty
> + rotate 4
> + weekly
> +}
> +
> +/var/log/apache2/*.log {
> + weekly
> + missingok
> + rotate 52
> + compress
> + delaycompress
> + notifempty
> + create 640 root adm
> + sharedscripts
> + prerotate
> + if [ -f /var/run/apache2.pid ]; then
> + /etc/init.d/apache2 restart > /dev/null
> + fi
> + endscript
> +}
> +"
> +
> + test Logrotate.lns get conf =
> + { "comment" = "see man logrotate for details" }
> + { "comment" = "rotate log files weekly" }
> + { "schedule" = "weekly" }
> + {}
> + { "comment" = "keep 4 weeks worth of backlogs" }
> + { "rotate" = "4" }
> + {}
> + { "comment" = "create new (empty) log files after rotating old ones"
> }
> + { "create" }
> + {}
> + { "comment" = "uncomment this if you want your log files compressed"
> }
> + { "comment" = "compress" }
> + {}
> + { "comment" = "packages drop log rotation information into this
> directory" }
> + { "include" = "/etc/logrotate.d" }
> + {}
> + { "comment" = "no packages own wtmp, or btmp -- we'll rotate them
> here" }
> + { "rule"
> + { "file" = "/var/log/wtmp" }
> + { "missingok" = "missingok" }
> + { "schedule" = "monthly" }
> + { "create"
> + { "mode" = "0664" }
> + { "owner" = "root" }
> + { "group" = "utmp" } }
> + { "rotate" = "1" } }
> + {}
> + { "rule"
> + { "file" = "/var/log/btmp" }
> + { "file" = "/var/log/btmp*" }
> + { "missingok" = "missingok" }
> + { "comment" = "ftpd doesn't handle SIGHUP properly" }
> + { "schedule" = "monthly" }
> + { "create"
> + { "mode" = "0664" }
> + { "owner" = "root" }
> + { "group" = "utmp" } }
> + { "rotate" = "1" } }
> + { "rule"
> + { "file" = "/var/log/vsftpd.log" }
> + { "comment" = "ftpd doesn't handle SIGHUP properly" }
> + { "compress" = "nocompress" }
> + { "missingok" = "missingok" }
> + { "ifempty" = "notifempty" }
> + { "rotate" = "4" }
> + { "schedule" = "weekly" } }
> + {}
> + { "rule"
> + { "file" = "/var/log/apache2/*.log" }
> + { "schedule" = "weekly" }
> + { "missingok" = "missingok" }
> + { "rotate" = "52" }
> + { "compress" = "compress" }
> + { "delaycompress" = "delaycompress" }
> + { "ifempty" = "notifempty" }
> + { "create"
> + { "mode" = "640" }
> + { "owner" = "root" }
> + { "group" = "adm" } }
> + { "sharedscripts" }
> + { "prerotate" = " if [ -f /var/run/apache2.pid
> ]; then
> + /etc/init.d/apache2 restart > /dev/null
> + fi
> +" } }
> +
>
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080723/b1ac93db/attachment.htm>
More information about the augeas-devel
mailing list