@if_root
    @skipUnless(_can_query_journald(),
                "journald unavailable or inactive on this machine.")
    def run_journald_script(self, script):
        name = random_name(self).encode("utf-8")
        code = _SCRIPT_CODE.format(script.__name__, script.__name__)
        d = getProcessOutput(
            b"systemd-run", [b"--unit=" + name, b"--description=testing",
                             sys.executable, b"-u", b"-c", code,
                             b"--journald"],
            env=os.environ, errortoo=True,
        )
        d.addCallback(lambda result: msg("systemd-run output: " + result))
        # systemd-run doesn't wait for process to exit, so we need to ask
        # systemd when it's done:
        d.addCallback(lambda _: loop_until(reactor, lambda: Popen(
            [b"systemctl", b"--quiet", b"is-active", name]).wait() != 0))
        d.addCallback(lambda _: getProcessOutput(
            b"journalctl", [b"--unit", name, b"--output", b"cat"]))
        d.addCallback(lambda data: (msg(b"script output: " + data), data)[1])
        d.addCallback(lambda data: [
            loads(l) for l in data.splitlines() if l.startswith(b"{")])
        return d
Run a script that logs messages to journald and uses
dataset/ETHPy150Open ClusterHQ/flocker/flocker/common/functional/test_script.py/FlockerScriptRunnerJournaldTests.run_journald_script