Re: [systemd-devel] generator logging during daemon-reload
On Fri, 07.11.14 20:59, Alexandre Detiste (alexandre.deti...@gmail.com) wrote: Hi, I know that generators should log to /dev/kmsg during early boot. Correct! But, when they are restarted later by systemcl daemon-reload; is it better to write to the journal instead, by using systemd-cat for example ? Or is it racy/forbidden ? Yes, this is dangerous. During a daemon-reload PID 1 serilizes its state to a file in /run, then flushes all configuration, then invokes the generators, and then rereads the configuration and deserializes the state. Now, if you generator accesses the journal socket, and journald is not running yet (because you are in emergency mode for example), then things might deadlock: as logging is synchronous and the socket buffer is limited in size your generator might block while writing the log message and since activation cannot take place as PID 1 is not processing any events while doing the whole state flush/config flush/generator magic/config reload/state reload it would never unblock again. Generators really really shouldn't talk to any other services, and this means for logging they should log to /dev/kmsg or suchlike. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] generator logging during daemon-reload
Le lundi 10 novembre 2014, 14:32:49 Lennart Poettering a écrit : I know that generators should log to /dev/kmsg during early boot. Correct! Yes, but then the log appears as a ugly big chunck without the timestamp host on the left; except the first line. Is it ok to reopen /dev/ksmg for each line writen to avoid this ? Google gave me this: http://unix.stackexchange.com/questions/35639/how-can-i-write-to-dmesg-from-command-line With take me back here :-) ! which is easy to understand. http://cgit.freedesktop.org/systemd/systemd/tree/src/journal/journald-kmsg.c (...) deadlocks (...) Ok, I indeed got some while doing tests for my /var/spool/cron/crontabs problem. I finally settled to generate a kind of 'transient' service that does a daemon-reload ; restart cront.target _only_ if this path doesn't exist; and it iself contains a ConditionDirectoryNotEmpty=/var/spool/cron/crontabs to avoid needless daemon-reload. The twist: on the second run of the generator, this path now _does_ exist; so this service doesn't generate itself again. At first, I had used 'ExecStartPost=' for the restart part ; but the .service simply vanish during the daemon-reload and can never finish. (this behaves like a self-modifying shell script) Now I do this, it turns the ExecStart in a kind of atomic operation: ExecStart=/bin/sh -c /bin/systemctl daemon-reload ; /bin/systemctl try-restart cron.target https://github.com/systemd-cron/systemd-cron/blob/master/src/bin/systemd-crontab-generator#L471 Generators really really shouldn't talk to any other services, and this means for logging they should log to /dev/kmsg or suchlike. So we should also avoid sending mail with /usr/sbin/sendmail , for example ? Thanks, Alexandre Detiste ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] generator logging during daemon-reload
On Mon, 10.11.14 17:38, Alexandre Detiste (alexandre.deti...@gmail.com) wrote: Le lundi 10 novembre 2014, 14:32:49 Lennart Poettering a écrit : I know that generators should log to /dev/kmsg during early boot. Correct! Yes, but then the log appears as a ugly big chunck without the timestamp host on the left; journalctl should pretty much generate the same output for userspace messages written to /dev/kmsg then to those passed directly to journald. except the first line. Is it ok to reopen /dev/ksmg for each line writen to avoid this ? Not sure I follow? So we should also avoid sending mail with /usr/sbin/sendmail , for example ? Yes, that's really not an OK thing to do. /usr/sbin/sendmail might talk to a local service for delivering the mail, as well as syslog again for its own logging needs. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] generator logging during daemon-reload
Yes, but then the log appears as a ugly big chunck without the timestamp host on the left; except the first line. Is it ok to reopen /dev/ksmg for each line writen to avoid this ? Not sure I follow? This might be a trivial problem; it's just that there are really few people writing generators or outputing do /dev/kmsg . Here is a sample test case the 2 different behaviours, maybe a flush after the write would do it: root@antec:/home/tchet# cat log 4 log1: log1 4 log2: log2 4 log3: log3 4 log4: log4 root@antec:/home/tchet# LANG=C dd if=log of=/dev/kmsg 0+1 records in 0+1 records out 60 bytes (60 B) copied, 0.000114992 s, 522 kB/s root@antec:/home/tchet# while read level pgm msg; do echo $level $pgm $msg /dev/kmsg; done log root@antec:/home/tchet# journalctl -n ... nov 10 20:25:06 antec log1: log1 4 log2: log2 4 log3: log3 4 log4: log4 nov 10 20:25:20 antec log1: log1 nov 10 20:25:20 antec log2: log2 nov 10 20:25:20 antec log3: log3 nov 10 20:25:20 antec log4: log4 Yes, that's really not an OK thing to do. /usr/sbin/sendmail ... Ok, I don't want to test this with 20 differents MTA anyway. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] generator logging during daemon-reload
On Mon, 10.11.14 20:30, Alexandre Detiste (alexandre.deti...@gmail.com) wrote: Yes, but then the log appears as a ugly big chunck without the timestamp host on the left; except the first line. Is it ok to reopen /dev/ksmg for each line writen to avoid this ? Not sure I follow? This might be a trivial problem; it's just that there are really few people writing generators or outputing do /dev/kmsg . Here is a sample test case the 2 different behaviours, maybe a flush after the write would do it: root@antec:/home/tchet# cat log 4 log1: log1 4 log2: log2 4 log3: log3 4 log4: log4 root@antec:/home/tchet# LANG=C dd if=log of=/dev/kmsg 0+1 records in 0+1 records out 60 bytes (60 B) copied, 0.000114992 s, 522 kB/s root@antec:/home/tchet# while read level pgm msg; do echo $level $pgm $msg /dev/kmsg; done log root@antec:/home/tchet# journalctl -n ... nov 10 20:25:06 antec log1: log1 4 log2: log2 4 log3: log3 4 log4: log4 nov 10 20:25:20 antec log1: log1 nov 10 20:25:20 antec log2: log2 nov 10 20:25:20 antec log3: log3 nov 10 20:25:20 antec log4: log4 The kernel does some moronic line merging there. Consider just reopening the device each time to avoid it... Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] generator logging during daemon-reload
Hi, I know that generators should log to /dev/kmsg during early boot. But, when they are restarted later by systemcl daemon-reload; is it better to write to the journal instead, by using systemd-cat for example ? Or is it racy/forbidden ? Greetings, Alexandre Detiste ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel