#NEWLINE# @ if_root #NEWLINE# @ skipUnless ( _can_query_journald ( ) , 'journald unavailable or inactive on this machine.' ) #NEWLINE# def run_journald_script( self , script ) : #NEWLINE# #INDENT# '\n        Run a script that logs messages to journald and uses\n        ``FlockerScriptRunner``.\n\n        :param ICommandLineScript: Script to run. Must be class in this module.\n\n        :return: ``Deferred`` that fires with decoded JSON messages from the\n            journal for the process.\n        ' #NEWLINE# name = random_name ( self ) . encode ( 'utf-8' ) #NEWLINE# code = _SCRIPT_CODE . format ( script . __name__ , script . __name__ ) #NEWLINE# 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 ) #NEWLINE# d . addCallback ( ( lambda result : msg ( ( 'systemd-run output: ' + result ) ) ) ) #NEWLINE# d . addCallback ( ( lambda _ : loop_until ( reactor , ( lambda : ( Popen ( [ b'systemctl' , b'--quiet' , b'is-active' , name ] ) . wait ( ) != 0 ) ) ) ) ) #NEWLINE# d . addCallback ( ( lambda _ : getProcessOutput ( b'journalctl' , [ b'--unit' , name , b'--output' , b'cat' ] ) ) ) #NEWLINE# d . addCallback ( ( lambda data : ( msg ( ( b'script output: ' + data ) ) , data ) [ 1 ] ) ) #NEWLINE# d . addCallback ( ( lambda data : [ loads ( l ) for l in data . splitlines ( ) if l . startswith ( b'{' ) ] ) ) #NEWLINE# return d