Re: unit been dead before been running

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all:

Sorry to bring this up again... here is what i plan to do, i'm just asking if this make sense.

(the context is that i start a transient unit, and pass tty fd, and i need to know when the unit is dead, so i can close my fds) `systemd1.Manager.StartTransientUnit` returns a job in the form of `/org/freedesktop/systemd1/job/<job_id>`, so i'm just going to ignore all messages that comes with that Job. Because those comes when the unit is starting up.. the final `dead` of `failed` message comes with Job (0, '/')..

do that make sense?

Thanks!  


Alvaro Leiva


On Mon, Feb 18, 2019 at 1:46 PM aleivag <aleivag@xxxxxxxxx> wrote:

Hi All:

i notice a change of behaviour that broke a couple of my scripts between v239 and v240, and wanted to know that maybe i was always assuming the wrong thing, so here it goes:

so i subscribe to 

            "type='signal',"
            "sender='org.freedesktop.systemd1',"
            "path='/org/freedesktop/systemd1/unit/myu_2eservice',"
            "interface='org.freedesktop.DBus.Properties',"
            "member='PropertiesChanged'"

on the bus, and then i start a transient unit like `systemd-run --pty --unit myu.service /bin/bash` .

to do the subscribe to that event i use the following script, (its definitely not important the script i use but just show you for completeness),

```
#!/usr/bin/python3

from pprint import pprint
import pystemd
from pystemd.dbuslib import DBus

with DBus() as bus, pystemd.DBus.Manager(bus=bus, _autoload=True) as man:
    mstr = (
            "type='signal',"
            "sender='org.freedesktop.systemd1',"
            "path='/org/freedesktop/systemd1/unit/myu_2eservice',"
            "interface='org.freedesktop.DBus.Properties',"
            "member='PropertiesChanged'"
    ).encode()
    man.Monitoring.BecomeMonitor([mstr], 0)
    while True:
        bus.wait(1000)
        m = bus.process()
        if m.is_empty():
            continue

        m.process_reply(False)
        if m.get_path() == b'/org/freedesktop/systemd1/unit/myu_2eservice':
            pprint(m.body)
``` 


on systemd v239 and bellow before the unit is active i got only 2 messages, one `org.freedesktop.systemd1.Service` and one on `org.freedesktop.systemd1.Unit`. the second one notify me that the "SubState" is "running". when the unit ends, i get 2 messages also, and the last one is to tell me that the "SubState" is "dead" 

on v240  on the other part, before the unit ready, i get 4 messages, one on `org.freedesktop.systemd1.Service` -> `org.freedesktop.systemd1.Unit` -> `org.freedesktop.systemd1.Service` -> `org.freedesktop.systemd1.Unit`, where the Unit ones the substate first is "dead" and then is "running", on deactivating, the messages are the same between 239 and 240.

so i used to tell that the unit had finished, by inspecting the messages on the bus, and then looking for SubState to be any of ("exited", "failed", "dead"), but i cant do that now.

at the end of the  email i copy the dumps on the 2 versions, but my questions are:

1.- Is this change in behaviour, intended, or a side effect of something else?
2.- was what i was doing the best way to decide if a transient unit has finished? i'm super temped to instead check when the `org.freedesktop.systemd1.Service.MainPID == 0` i think its the best idea, but maybe you guys have one that is better.

thanks guys!!

now i paste the messages:

on v239

on start
[b'org.freedesktop.systemd1.Service',
 {b'ControlPID': 0,
  b'ExecMainCode': 0,
  b'ExecMainExitTimestamp': 0,
  b'ExecMainExitTimestampMonotonic': 0,
  b'ExecMainPID': 18328,
  b'ExecMainStartTimestamp': 1550516822984246,
  b'ExecMainStartTimestampMonotonic': 41004687391,
  b'ExecMainStatus': 0,
  b'GID': 4294967295,
  b'MainPID': 18328,
  b'NRestarts': 0,
  b'Result': b'success',
  b'StatusErrno': 0,
  b'StatusText': b'',
  b'UID': 4294967295,
  b'USBFunctionDescriptors': b'',
  b'USBFunctionStrings': b''},
 [b'ExecStartPre',
  b'ExecStart',
  b'ExecStartPost',
  b'ExecReload',
  b'ExecStop',
  b'ExecStopPost']]
[b'org.freedesktop.systemd1.Unit',
 {b'ActiveEnterTimestamp': 1550516822984291,
  b'ActiveEnterTimestampMonotonic': 41004687437,
  b'ActiveExitTimestamp': 0,
  b'ActiveExitTimestampMonotonic': 0,
  b'ActiveState': b'active',
  b'AssertResult': True,
  b'AssertTimestamp': 1550516822983511,
  b'AssertTimestampMonotonic': 41004686656,
  b'ConditionResult': True,
  b'ConditionTimestamp': 1550516822983509,
  b'ConditionTimestampMonotonic': 41004686655,
  b'InactiveEnterTimestamp': 0,
  b'InactiveEnterTimestampMonotonic': 0,
  b'InactiveExitTimestamp': 1550516822984291,
  b'InactiveExitTimestampMonotonic': 41004687437,
  b'Job': (0, b'/'),
  b'StateChangeTimestamp': 1550516822984291,
  b'StateChangeTimestampMonotonic': 41004687437,
  b'SubState': b'running'},
 []]

on end

[b'org.freedesktop.systemd1.Service',
 {b'ControlPID': 0,
  b'ExecMainCode': 1,
  b'ExecMainExitTimestamp': 1550516877103509,
  b'ExecMainExitTimestampMonotonic': 41058806656,
  b'ExecMainPID': 18328,
  b'ExecMainStartTimestamp': 1550516822984246,
  b'ExecMainStartTimestampMonotonic': 41004687391,
  b'ExecMainStatus': 0,
  b'GID': 4294967295,
  b'MainPID': 0,
  b'NRestarts': 0,
  b'Result': b'success',
  b'StatusErrno': 0,
  b'StatusText': b'',
  b'UID': 4294967295,
  b'USBFunctionDescriptors': b'',
  b'USBFunctionStrings': b''},
 [b'ExecStartPre',
  b'ExecStart',
  b'ExecStartPost',
  b'ExecReload',
  b'ExecStop',
  b'ExecStopPost']]
[b'org.freedesktop.systemd1.Unit',
 {b'ActiveEnterTimestamp': 1550516822984291,
  b'ActiveEnterTimestampMonotonic': 41004687437,
  b'ActiveExitTimestamp': 1550516877103599,
  b'ActiveExitTimestampMonotonic': 41058806745,
  b'ActiveState': b'inactive',
  b'AssertResult': True,
  b'AssertTimestamp': 1550516822983511,
  b'AssertTimestampMonotonic': 41004686656,
  b'ConditionResult': True,
  b'ConditionTimestamp': 1550516822983509,
  b'ConditionTimestampMonotonic': 41004686655,
  b'InactiveEnterTimestamp': 1550516877103599,
  b'InactiveEnterTimestampMonotonic': 41058806745,
  b'InactiveExitTimestamp': 1550516822984291,
  b'InactiveExitTimestampMonotonic': 41004687437,
  b'Job': (0, b'/'),
  b'StateChangeTimestamp': 1550516877103599,
  b'StateChangeTimestampMonotonic': 41058806745,
  b'SubState': b'dead'},
 []]


and on v240, on activating (please notice 4 message)

```
[b'org.freedesktop.systemd1.Service',
 {b'ControlPID': 0,
  b'ExecMainCode': 0,
  b'ExecMainExitTimestamp': 0,
  b'ExecMainExitTimestampMonotonic': 0,
  b'ExecMainPID': 7133,
  b'ExecMainStartTimestamp': 1550515398840688,
  b'ExecMainStartTimestampMonotonic': 1922045814,
  b'ExecMainStatus': 0,
  b'GID': 4294967295,
  b'MainPID': 7133,
  b'NRestarts': 0,
  b'Result': b'success',
  b'StatusErrno': 0,
  b'StatusText': b'',
  b'UID': 4294967295},
 [b'ExecStartPre',
  b'ExecStart',
  b'ExecStartPost',
  b'ExecReload',
  b'ExecStop',
  b'ExecStopPost']]
[b'org.freedesktop.systemd1.Unit',
 {b'ActiveEnterTimestamp': 0,
  b'ActiveEnterTimestampMonotonic': 0,
  b'ActiveExitTimestamp': 0,
  b'ActiveExitTimestampMonotonic': 0,
  b'ActiveState': b'inactive',
  b'AssertResult': True,
  b'AssertTimestamp': 1550515398840037,
  b'AssertTimestampMonotonic': 1922045163,
  b'ConditionResult': True,
  b'ConditionTimestamp': 1550515398840035,
  b'ConditionTimestampMonotonic': 1922045161,
  b'InactiveEnterTimestamp': 0,
  b'InactiveEnterTimestampMonotonic': 0,
  b'InactiveExitTimestamp': 0,
  b'InactiveExitTimestampMonotonic': 0,
  b'InvocationID': [249,
                    205,
                    238,
                    134,
                    209,
                    51,
                    64,
                    133,
                    164,
                    25,
                    160,
                    192,
                    70,
                    197,
                    1,
                    112],
  b'Job': (903, b'/org/freedesktop/systemd1/job/903'),
  b'StateChangeTimestamp': 0,
  b'StateChangeTimestampMonotonic': 0,
  b'SubState': b'dead'},
 [b'Conditions', b'Asserts']]
[b'org.freedesktop.systemd1.Service',
 {b'ControlPID': 0,
  b'ExecMainCode': 0,
  b'ExecMainExitTimestamp': 0,
  b'ExecMainExitTimestampMonotonic': 0,
  b'ExecMainPID': 7133,
  b'ExecMainStartTimestamp': 1550515398840688,
  b'ExecMainStartTimestampMonotonic': 1922045814,
  b'ExecMainStatus': 0,
  b'GID': 4294967295,
  b'MainPID': 7133,
  b'NRestarts': 0,
  b'Result': b'success',
  b'StatusErrno': 0,
  b'StatusText': b'',
  b'UID': 4294967295},
 [b'ExecStartPre',
  b'ExecStart',
  b'ExecStartPost',
  b'ExecReload',
  b'ExecStop',
  b'ExecStopPost']]
[b'org.freedesktop.systemd1.Unit',
 {b'ActiveEnterTimestamp': 1550515398840853,
  b'ActiveEnterTimestampMonotonic': 1922045979,
  b'ActiveExitTimestamp': 0,
  b'ActiveExitTimestampMonotonic': 0,
  b'ActiveState': b'active',
  b'AssertResult': True,
  b'AssertTimestamp': 1550515398840037,
  b'AssertTimestampMonotonic': 1922045163,
  b'ConditionResult': True,
  b'ConditionTimestamp': 1550515398840035,
  b'ConditionTimestampMonotonic': 1922045161,
  b'InactiveEnterTimestamp': 0,
  b'InactiveEnterTimestampMonotonic': 0,
  b'InactiveExitTimestamp': 1550515398840853,
  b'InactiveExitTimestampMonotonic': 1922045979,
  b'InvocationID': [249,
                    205,
                    238,
                    134,
                    209,
                    51,
                    64,
                    133,
                    164,
                    25,
                    160,
                    192,
                    70,
                    197,
                    1,
                    112],
  b'Job': (903, b'/org/freedesktop/systemd1/job/903'),
  b'StateChangeTimestamp': 1550515398840853,
  b'StateChangeTimestampMonotonic': 1922045979,
  b'SubState': b'running'},
 [b'Conditions', b'Asserts']]

```
and on the way out

```
[b'org.freedesktop.systemd1.Service',
 {b'ControlPID': 0,
  b'ExecMainCode': 1,
  b'ExecMainExitTimestamp': 1550515593404243,
  b'ExecMainExitTimestampMonotonic': 2116609370,
  b'ExecMainPID': 7133,
  b'ExecMainStartTimestamp': 1550515398840688,
  b'ExecMainStartTimestampMonotonic': 1922045814,
  b'ExecMainStatus': 0,
  b'GID': 4294967295,
  b'MainPID': 0,
  b'NRestarts': 0,
  b'Result': b'success',
  b'StatusErrno': 0,
  b'StatusText': b'',
  b'UID': 4294967295},
 [b'ExecStartPre',
  b'ExecStart',
  b'ExecStartPost',
  b'ExecReload',
  b'ExecStop',
  b'ExecStopPost']]
[b'org.freedesktop.systemd1.Unit',
 {b'ActiveEnterTimestamp': 1550515398840853,
  b'ActiveEnterTimestampMonotonic': 1922045979,
  b'ActiveExitTimestamp': 1550515593404360,
  b'ActiveExitTimestampMonotonic': 2116609486,
  b'ActiveState': b'inactive',
  b'AssertResult': True,
  b'AssertTimestamp': 1550515398840037,
  b'AssertTimestampMonotonic': 1922045163,
  b'ConditionResult': True,
  b'ConditionTimestamp': 1550515398840035,
  b'ConditionTimestampMonotonic': 1922045161,
  b'InactiveEnterTimestamp': 1550515593404360,
  b'InactiveEnterTimestampMonotonic': 2116609486,
  b'InactiveExitTimestamp': 1550515398840853,
  b'InactiveExitTimestampMonotonic': 1922045979,
  b'InvocationID': [249,
                    205,
                    238,
                    134,
                    209,
                    51,
                    64,
                    133,
                    164,
                    25,
                    160,
                    192,
                    70,
                    197,
                    1,
                    112],
  b'Job': (0, b'/'),
  b'StateChangeTimestamp': 1550515593404360,
  b'StateChangeTimestampMonotonic': 2116609486,
  b'SubState': b'dead'},
 [b'Conditions', b'Asserts']]
```

Alvaro Leiva
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux