3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/logging
Dominique Martinet 45ef5c1741 logrotate: add configuration check at build time
Now the service no longer starts immediately,
check if the config we generated makes sense as soon as possible.

The check isn't perfect because logrotate --debug wants to check
users required, there are two problems:
 - /etc/passwd and /etc/group are sandboxed and we don't have
visibility of system users
 - the check phase runs as nixbld which cannot su to other users
and logrotate fails on this

Until these two problems can be addressed, users-related checks
are filtered out, it's still much better than no check.
The check can be disabled with services.logrotate.checkConfig
if required
(bird also has a preCheck param, to prepare the environment
before check, but we can add it if it becomes necessary)

Since this makes for very verbose builds, we only show errors:
There is no way to control log level, but logrotate hardcodes
'error:' at common log level, so we can use grep, taking care
to keep error codes

Some manual tests:
───────┬──────────────────────────────────────────
       │ File: valid-config.conf
───────┼──────────────────────────────────────────
   1   │ missingok
───────┴──────────────────────────────────────────
logrotate --debug ok
grep ok

───────┬──────────────────────────────────────────
       │ File: postrotate-no-end.conf
───────┼──────────────────────────────────────────
   1   │ missingok
   2   │ /file {
   3   │    postrotate
   4   │      test
   5   │ }
───────┴──────────────────────────────────────────
error: postrotate-no-end.conf:prerotate, postrotate or preremove without endscript

───────┬──────────────────────────────────────────
       │ File: missing-file.conf
───────┼──────────────────────────────────────────
   1   │ "test" { daily }
───────┴──────────────────────────────────────────
error: stat of test failed: No such file or directory

───────┬──────────────────────────────────────────
       │ File: unknown-option.conf
───────┼──────────────────────────────────────────
   1   │ some syntax error
───────┴──────────────────────────────────────────
logrotate --debug ok
error: unknown-option.conf:1 unknown option 'some' -- ignoring line

───────┬──────────────────────────────────────────
       │ File: unknown-user.conf
───────┼──────────────────────────────────────────
   1   │ su notauser notagroup
───────┴──────────────────────────────────────────
error: unknown-user.conf:1 unknown user 'notauser'

In particular note that logrotate would not error on unknown option
(it just ignores the line) but this change makes the check fail.
2022-04-01 07:09:27 +09:00
..
awstats.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
filebeat.nix elk7: 7.11.1 -> 7.16.1, 6.8.3 -> 6.8.21 + add filebeat module and tests (#150879) 2021-12-17 00:20:52 +09:00
fluentd.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
graylog.nix nixos/graylog: fix group creation 2022-03-14 10:13:15 +01:00
heartbeat.nix
journalbeat.nix Merge pull request #148785 from pennae/more-option-doc-staticizing 2021-12-17 11:14:08 -05:00
journaldriver.nix
journalwatch.nix nixos/*: add trivial defaultText for options with simple defaults 2021-12-02 22:35:04 +01:00
klogd.nix nixos/*: add trivial defaultText for options with simple defaults 2021-12-02 22:35:04 +01:00
logcheck.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
logrotate.nix logrotate: add configuration check at build time 2022-04-01 07:09:27 +09:00
logstash.nix nixos/logstash: Add logstashJvmOptionsFile option 2021-11-01 16:21:02 +01:00
promtail.nix nixos/promtail: use promtail package 2022-01-23 14:01:29 +01:00
rsyslogd.nix
syslog-ng.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
syslogd.nix
SystemdJournal2Gelf.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
vector.nix vector: remove deprecated --no-topology 2021-04-05 08:30:52 +09:00