Skip to content

tests: various fixes#1812

Merged
poettering merged 1 commit intosystemd:masterfrom
evverx:test-fixes
Nov 10, 2015
Merged

tests: various fixes#1812
poettering merged 1 commit intosystemd:masterfrom
evverx:test-fixes

Conversation

@evverx
Copy link
Contributor

@evverx evverx commented Nov 8, 2015

  • remove journal flushing (systemd-journal-flush.service runs journalctl --flush on boot)
  • add journal syncing to the end.service (see poettering@b374689)
  • use sh -c and PATH instead of the @systemctl@ expansion
  • remove unnecessary semicolons etc

@ronnychevalier , please, take a look.

@martinpitt , I removed that commit. Is it ok?

@evverx evverx force-pushed the test-fixes branch 3 times, most recently from 4b64229 to 967c9e0 Compare November 8, 2015 23:06
@evverx
Copy link
Contributor Author

evverx commented Nov 9, 2015

Is there a better way for syncing journal files to disk?

I think

systemctl kill --signal SIGUSR1 --kill-who main systemd-journald.service; sleep 1

is ugly:)

/cc @poettering

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually have a slight preference for using /bin/sh instead since this should also work with non-bash shells (e.g. Debian/Ubuntu ship "dash" as a possible alternative) and there are no reasons why that wouldn't work.

The set -x can also be pulled outside:

ExecStart=/bin/sh -x -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'

And last trailing semi-colon is not really necessary anymore.

Otherwise, looks great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good points, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filbranden , fixed.
Please, take a look: evverx@7d97774. I like /bin/bash -xc but use /bin/sh -x -c. It's consistent with your style in test-execute

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

One more point of /bin/sh is that we can then use busybox shell, in which case we can aim at a very minimal container that doesn't need to have bash + coreutils to run the experiments on.

Cheers!
Filipe

@poettering
Copy link
Member

@evverx yeah, there is "journalctl --flush", which waits for the flush to complete... But I figure you found that too, by now?

I am a bit confused by the order here... as the original message was updated after some of the comments, right? Patch looks good to me now, everybody else OK with this too?

@poettering
Copy link
Member

Regarding /bin/sh vs. /bin/bash: I personally don't really believe in Debian's usage of "dash"... it sounds like an additional source of bugs for no real gain, but well..

Either way, I'd merge it with either /bin/bash or /bin/sh as long as the semaphore thing builds... On my systems both are the same anyway, and i am sure that folks who run into problems with it, will yell if it does break things...

Anyway, would be good to get feedback from @ronnychevalier, @martinpitt as @evverx requested, before we merge this.

@evverx
Copy link
Contributor Author

evverx commented Nov 9, 2015

@evverx yeah, there is "journalctl --flush", which waits for the flush to complete... But I figure you found that too, by now?

I don't understand. Why do you change journalctl --flush with sending SIGUSR1?

--flush checks /run/systemd/journal/flushed and exits (it doesn't send SIGUSR1 to systemd-journald)

I need a server_sync. I force it with the direct sending SIGUSR1 to the systemd-journald.

BTW

Regarding /bin/sh vs. /bin/bash: I personally don't really believe in Debian's usage of "dash"

https://wiki.ubuntu.com/DashAsBinSh

In Ubuntu 6.10, the default system shell, /bin/sh, was changed to dash (the Debian Almquist Shell); previously it had been bash (the GNU Bourne-Again Shell). The same change will affect users of Ubuntu 6.06 LTS upgrading directly to Ubuntu 8.04 LTS. This document explains this change and what you should do if you encounter problems.

https://wiki.debian.org/Shell

Up to DebianLenny, the default /bin/sh shell was bash. Starting with DebianSqueeze, the default shell will be dash

@ronnychevalier
Copy link
Member

Hmm, @poettering since you added this feature, why this file is not removed afterward? Or maybe, this switch is meant to be used only once? (which would be contradictory with what the man page says) because nowhere in the journal we remove this file, so after systemd-journal-flush, journalctl --flush becomes a no-op.

Or maybe i'm missing something?

@poettering
Copy link
Member

hmm?

"journalctl --flush" is about flushing the journal data from /run to /var, which is really a one-time operation. The command only sends a SIGUSR1 when invoked the first time. If the flush already took place it becomes a NOOP. As such it is idempotent: whenever you run it, you can be sure that afterwards the log data is in /var, if things are configured that way.

@poettering
Copy link
Member

@evverx what precisely are you looking for? just a way to get the journal files into a clean state? There's no nice way for this, all ways are necessarily racy, since any log message will immediately cause the files to be marked dirty again...

What's precisely needed here? what exactly do you want journald to do for you?

@ronnychevalier
Copy link
Member

Ok, just a misunderstanding from my part, thanks :)

@evverx
Copy link
Contributor Author

evverx commented Nov 9, 2015

@evverx what precisely are you looking for?

I want sync the journal before shutdown.

If I have a journalctl --flush in the end.service

$ cd test/TEST-01-BASIC/
$ sudo make clean setup run
...
$ cat .testdir
TESTDIR="/var/tmp/systemd-test.xERhYs"
LOOPDEV=/dev/loop4

$ sudo journalctl -D /var/tmp/systemd-test.xERhYs/nspawn-root/var/log/journal -u testsuite.service
-- Logs begin at Mon 2015-11-09 17:32:38 UTC, end at Mon 2015-11-09 17:32:38 UTC. --
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: About to execute: /bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok;'
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: Forked /bin/bash as 33
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: Changed dead -> start
Nov 09 17:32:38 systemd-testsuite systemd[1]: Starting Testsuite service...
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: Child 33 belongs to testsuite.service
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: Main process exited, code=exited, status=0/SUCCESS
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: Changed start -> dead
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: Job testsuite.service/start finished, result=done
Nov 09 17:32:38 systemd-testsuite systemd[1]: Started Testsuite service.
Nov 09 17:32:38 systemd-testsuite systemd[1]: testsuite.service: cgroup is empty

Should be (note bash[34] + part)

-- Logs begin at Mon 2015-11-09 17:34:25 UTC, end at Mon 2015-11-09 17:34:26 UTC. --
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: About to execute: /bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok;'
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Forked /bin/bash as 34
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Changed dead -> start
Nov 09 17:34:25 systemd-testsuite systemd[1]: Starting Testsuite service...
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Child 34 belongs to testsuite.service
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Main process exited, code=exited, status=0/SUCCESS
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Changed start -> dead
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Job testsuite.service/start finished, result=done
Nov 09 17:34:25 systemd-testsuite systemd[1]: Started Testsuite service.
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: cgroup is empty
Nov 09 17:34:25 systemd-testsuite systemd[1]: testsuite.service: Failed to send unit change signal for testsuite.service: Transport endpoint is not connected
Nov 09 17:34:25 systemd-testsuite bash[34]: + systemctl --failed --no-legend --no-pager
Nov 09 17:34:25 systemd-testsuite bash[34]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member
Nov 09 17:34:25 systemd-testsuite bash[34]: Got message type=method_return sender=n/a destination=n/a object=n/a interface=n/a member=n/a cookie=1 reply_cookie=1 error=n/a
Nov 09 17:34:25 systemd-testsuite bash[34]: + echo OK

@evverx
Copy link
Contributor Author

evverx commented Nov 9, 2015

I mean, I want 'save' stderr and stdout of the testsuite.service.

@poettering
Copy link
Member

let me get this right. All you want to do is ensure that the journal picked up everything written to stdout/stderr of testsuite.serivce and wrote it to disk? i.e. an operation one could well describe as a "sync"? Why precisely do you need this? I mean, when shutting down, we'll sync things anyway... why does that not suffice?

I figure to support this properly we could intrdouce a new flag file "/run/systemd/journal/sync" or so that is touched each time systemd has synced all files to disk. Then, let's add a new sync signal to journald (for example SIGRTMIN+1), which will result in a sync of all files, and thus the date being updated on /run/systemd/journal/sync. If all files where already synced it would nonetheless touch the sync file. Then, in journalctl let's add a new --sync verb: it would get the current time, send the signal, and then wait with inotify until the mtime of the sync file is newer than the time it sent the signal.

That way by invoking "journalctl --sync" we'd have reliable way to know that everything that was logged before invoking it has hit the disk, after it returns.

@evverx does that make sense to you?

@evverx
Copy link
Contributor Author

evverx commented Nov 9, 2015

I mean, when shutting down, we'll sync things anyway... why does that not suffice?

I don't know why but it doesn't work for me. I always lose the output of the testsuite.service.

Hm,
journald calls server_done, server_done calls stdout_stream_free, stdout_stream_free calls safe_close, safe_close calls close. No one call fsync (or, maybe I'm missing something:))

@evverx
Copy link
Contributor Author

evverx commented Nov 9, 2015

That way by invoking "journalctl --sync" we'd have reliable way to know that everything that was logged before invoking it has hit the disk, after it returns.

@evverx does that make sense to you?

Yes.

@evverx
Copy link
Contributor Author

evverx commented Nov 10, 2015

I figure to support this properly we could intrdouce a new flag file "/run/systemd/journal/sync" or so that is touched each time systemd has synced all files to disk. Then, let's add a new sync signal to journald (for example SIGRTMIN+1), which will result in a sync of all files, and thus the date being updated on /run/systemd/journal/sync

There is an option SyncIntervalSec=:

The timeout before synchronizing journal files to disk. After syncing, journal files are placed in the OFFLINE state. Note that syncing is unconditionally done immediately after a log message of priority CRIT, ALERT or EMERG has been logged. This setting hence applies only to messages of the levels ERR, WARNING, NOTICE, INFO, DEBUG. The default timeout is 5 minutes.

Will it update /run/systemd/journal/sync too?

Anyway, journalctl --sync is a separate issue.

systemctl kill --signal SIGUSR1 --kill-who main systemd-journald.service; sleep 1 works fine (it forces fsync).

We can replace it later.

poettering added a commit to poettering/systemd that referenced this pull request Nov 10, 2015
Let's make sure to process all queued log data before exiting, so that
we don't unnecessary lose messages when shutting down.

systemd#1812 (comment)
@poettering
Copy link
Member

@evverx i just posted PR #1835 which should ensure we process all queued log messages before exiting. This should make the whole explicit syncing unnecessary. Does that work for you?

* remove journal flushing (systemd-journal-flush.service runs journalctl --flush on boot)
* use sh -c and PATH instead of @systemctl@ expansion
* remove unnecessary semicolons etc
@evverx
Copy link
Contributor Author

evverx commented Nov 10, 2015

I rebased my commit on your branch, removed syncing, run make clean setup run && check-testsuite-output 10 times. My test passed.

@poettering , yes, that works for me. Thanks!

poettering added a commit that referenced this pull request Nov 10, 2015
@poettering poettering merged commit 7fa89e2 into systemd:master Nov 10, 2015
@poettering
Copy link
Member

OK, merged this one now. Of course, this will only be complete if #1835 is merged too.

@poettering
Copy link
Member

@evverx btw, I implemented a "journalctl --sync" now in PR #1848. Of course, we don't need this anymore for the tests, but I figured it's a good thing to have anyway.

@evverx
Copy link
Contributor Author

evverx commented Nov 11, 2015

@poettering , thanks. I'll take a look.

@evverx evverx deleted the test-fixes branch November 11, 2015 14:10
apovichuk-stratoscale pushed a commit to Stratoscale/systemd that referenced this pull request Jun 19, 2017
Let's make sure to process all queued log data before exiting, so that
we don't unnecessary lose messages when shutting down.

systemd/systemd#1812 (comment)

Cherry-picked from: b374689
Related: #1318994
apovichuk-stratoscale pushed a commit to Stratoscale/systemd that referenced this pull request Jun 20, 2017
Let's make sure to process all queued log data before exiting, so that
we don't unnecessary lose messages when shutting down.

systemd/systemd#1812 (comment)

Cherry-picked from: b374689
Related: #1318994
caobinxin pushed a commit to caobinxin/systemd-lx that referenced this pull request Oct 19, 2019
Let's make sure to process all queued log data before exiting, so that
we don't unnecessary lose messages when shutting down.

systemd/systemd#1812 (comment)

Cherry-picked from: b374689c02c681671a3c3c0b0fd3add32386b442
Related: #1318994
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants