Imported Upstream version 1.4.0
[platform/upstream/augeas.git] / lenses / tests / test_logrotate.aug
1 module Test_logrotate =
2
3 test Logrotate.body get "\n{\n monthly\n}" =
4   { "schedule" = "monthly" }
5
6 test Logrotate.rule get "/var/log/foo\n{\n monthly\n}\n" =
7   { "rule"
8     { "file" = "/var/log/foo" }
9     { "schedule" = "monthly" } }
10
11 test Logrotate.rule get "/var/log/foo /var/log/bar\n{\n monthly\n}\n" =
12   { "rule"
13     { "file" = "/var/log/foo" }
14     { "file" = "/var/log/bar" }
15     { "schedule" = "monthly" } }
16
17 let conf = "# see man logrotate for details
18 # rotate log files weekly
19 weekly
20
21 # keep 4 weeks worth of backlogs
22 rotate 4
23
24 # create new (empty) log files after rotating old ones
25 create
26
27 # uncomment this if you want your log files compressed
28 #compress
29
30 tabooext + .old .orig .ignore
31
32 # packages drop log rotation information into this directory
33 include /etc/logrotate.d
34
35 # no packages own wtmp, or btmp -- we'll rotate them here
36 /var/log/wtmp
37 /var/log/wtmp2
38 {
39     missingok
40     monthly
41     create 0664 root utmp
42     rotate 1
43 }
44
45 /var/log/btmp /var/log/btmp* {
46     missingok
47     # ftpd doesn't handle SIGHUP properly
48     monthly
49     create 0664 root utmp
50     rotate 1
51 }
52 /var/log/vsftpd.log {
53     # ftpd doesn't handle SIGHUP properly
54     nocompress
55     missingok
56     notifempty
57     rotate 4
58     weekly
59 }
60
61 /var/log/apache2/*.log {
62         weekly
63         missingok
64         rotate 52
65         compress
66         delaycompress
67         notifempty
68         create 640 root adm
69         sharedscripts
70         prerotate
71                 if [ -f /var/run/apache2.pid ]; then
72                         /etc/init.d/apache2 restart > /dev/null
73                 fi
74         endscript
75 }
76 /var/log/mailman/digest {
77     su root list
78     monthly
79     missingok
80     create 0664 list list
81     rotate 4
82     compress
83     delaycompress
84         sharedscripts
85         postrotate
86             [ -f '/var/run/mailman/mailman.pid' ] && /usr/lib/mailman/bin/mailmanctl -q reopen || exit 0
87         endscript
88 }
89 /var/log/ntp {
90     compress
91     dateext
92     maxage 365
93     rotate 99
94     size=+2048k
95     notifempty
96     missingok
97     copytruncate
98     postrotate
99         chmod 644 /var/log/ntp
100     endscript
101 }
102 "
103
104 test Logrotate.lns get conf =
105       { "#comment" = "see man logrotate for details" }
106       { "#comment" = "rotate log files weekly" }
107       { "schedule" = "weekly" }
108       {}
109       { "#comment" = "keep 4 weeks worth of backlogs" }
110       { "rotate"   = "4" }
111       {}
112       { "#comment" = "create new (empty) log files after rotating old ones" }
113       { "create" }
114       {}
115       { "#comment" = "uncomment this if you want your log files compressed" }
116       { "#comment" = "compress" }
117       {}
118       { "tabooext" = "+"  { ".old" } { ".orig" } { ".ignore" } }
119       {}
120       { "#comment" = "packages drop log rotation information into this directory" }
121       { "include" = "/etc/logrotate.d" }
122       {}
123       { "#comment" = "no packages own wtmp, or btmp -- we'll rotate them here" }
124       { "rule"
125            { "file"      = "/var/log/wtmp" }
126            { "file"      = "/var/log/wtmp2" }
127            { "missingok" = "missingok" }
128            { "schedule"  = "monthly" }
129            { "create"
130                 { "mode"  = "0664" }
131                 { "owner" = "root" }
132                 { "group" = "utmp" } }
133            { "rotate" = "1" } }
134       {}
135       { "rule"
136            { "file"      = "/var/log/btmp" }
137            { "file"      = "/var/log/btmp*" }
138            { "missingok" = "missingok" }
139            { "#comment"   = "ftpd doesn't handle SIGHUP properly" }
140            { "schedule"  = "monthly" }
141            { "create"
142                 { "mode"  = "0664" }
143                 { "owner" = "root" }
144                 { "group" = "utmp" } }
145            { "rotate" = "1" } }
146       { "rule"
147            { "file"      = "/var/log/vsftpd.log" }
148            { "#comment"  = "ftpd doesn't handle SIGHUP properly" }
149            { "compress"  = "nocompress" }
150            { "missingok" = "missingok" }
151            { "ifempty"   = "notifempty" }
152            { "rotate"    = "4" }
153            { "schedule"  = "weekly" } }
154       {}
155       { "rule"
156            { "file"          = "/var/log/apache2/*.log" }
157            { "schedule"      = "weekly" }
158            { "missingok"     = "missingok" }
159            { "rotate"        = "52" }
160            { "compress"      = "compress" }
161            { "delaycompress" = "delaycompress" }
162            { "ifempty"       = "notifempty" }
163            { "create"
164                 { "mode"  = "640"  }
165                 { "owner" = "root" }
166                 { "group" = "adm"  } }
167            { "sharedscripts" = "sharedscripts" }
168            { "prerotate" = "                if [ -f /var/run/apache2.pid ]; then
169                         /etc/init.d/apache2 restart > /dev/null
170                 fi" } }
171       { "rule"
172            { "file" = "/var/log/mailman/digest" }
173            { "su"
174                { "owner" = "root" }
175                { "group" = "list" } }
176            { "schedule"  = "monthly" }
177            { "missingok" = "missingok" }
178            { "create"
179                { "mode"  = "0664" }
180                { "owner" = "list" }
181                { "group" = "list" } }
182            { "rotate"        = "4" }
183            { "compress"      = "compress" }
184            { "delaycompress" = "delaycompress" }
185            { "sharedscripts" = "sharedscripts" }
186            { "postrotate"    = "            [ -f '/var/run/mailman/mailman.pid' ] && /usr/lib/mailman/bin/mailmanctl -q reopen || exit 0" } }
187       { "rule"
188            { "file" = "/var/log/ntp" }
189            { "compress" = "compress" }
190            { "dateext" = "dateext" }
191            { "maxage" = "365" }
192            { "rotate" = "99" }
193            { "size" = "+2048k" }
194            { "ifempty" = "notifempty" }
195            { "missingok" = "missingok" }
196            { "copytruncate" = "copytruncate" }
197            { "postrotate" = "        chmod 644 /var/log/ntp" } }
198
199 test Logrotate.lns get "/var/log/file {\n dateext\n}\n" =
200     { "rule"
201       { "file" = "/var/log/file" }
202       { "dateext" = "dateext" } }
203
204   (* Make sure 'minsize 1M' works *)
205 test Logrotate.lns get "/avr/log/wtmp {\n minsize 1M\n}\n" =
206   { "rule"
207       { "file" = "/avr/log/wtmp" }
208       { "minsize" = "1M" } }
209
210   (* '=' is a legal separator, file names can be indented *)
211 test Logrotate.lns get " \t /file {\n size=5M\n}\n" =
212      { "rule"
213          { "file" = "/file" }
214          { "size" = "5M" } }
215
216   (* Can leave owner/group off a create statement *)
217 test Logrotate.lns get "/file {
218         create 600\n}\n" =
219      { "rule"
220          { "file" = "/file" }
221          { "create"
222              { "mode" = "600" } } }
223
224 test Logrotate.lns put "/file {\n       create 600\n}\n" after
225     set "/rule/create/owner" "user"
226   = "/file {\n  create 600 user\n}\n"
227
228   (* The newline at the end of a script is optional *)
229 test Logrotate.lns put "/file {\n size=5M\n}\n" after
230     set "/rule/prerotate" "\tfoobar"
231   =
232 "/file {
233  size=5M
234 \tprerotate
235 \tfoobar
236 \tendscript\n}\n"
237
238 test Logrotate.lns put "/file {\n size=5M\n}\n" after
239     set "/rule/prerotate" "\tfoobar\n"
240   =
241 "/file {
242  size=5M
243 \tprerotate
244 \tfoobar\n
245 \tendscript\n}\n"
246
247 (* Bug #101: whitespace at the end of the line *)
248 test Logrotate.lns get "/file {\n missingok \t\n}\n" =
249   { "rule"
250     { "file" = "/file" }
251     { "missingok" = "missingok" } }
252
253 (* Bug #104: file names can be separated by newlines *)
254 let conf2 = "/var/log/mail.info
255 /var/log/mail.warn
256 /var/log/mail.err
257 {
258        weekly
259 }
260 "
261 test Logrotate.lns get conf2 =
262   { "rule"
263       { "file"      = "/var/log/mail.info" }
264       { "file"      = "/var/log/mail.warn" }
265       { "file"      = "/var/log/mail.err" }
266       { "schedule"  = "weekly" } }
267
268 (* Issue #217: support for dateformat *)
269 let dateformat = "dateformat -%Y%m%d\n"
270
271 test Logrotate.lns get dateformat =
272   { "dateformat" = "-%Y%m%d" }
273
274 (* Issue #123: no space before '{' *)
275 test Logrotate.lns get "/file{\n missingok \t\n}\n" =
276   { "rule"
277     { "file" = "/file" }
278     { "missingok" = "missingok" } }
279
280 (* RHBZ#1213292: maxsize 30k *)
281 test Logrotate.lns get "/var/log/yum.log {\n maxsize 30k\n}\n" =
282   { "rule"
283       { "file" = "/var/log/yum.log" }
284       { "maxsize" = "30k" } }
285