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