Closed kurtbrose closed 6 years ago
Hi @kurtbrose , thanks for summiting this.
it seems that you already solve this, may i also point to you to pystemd.run
import shlex
import pystemd.run
acmd = shlex.split(cmd) # or just have it as an array
unit = pystemd.run(acmd, remain_after_exit=True)
will return you a pystemd.systemd1.Unit
object, that you can query for runtime information (and start/stop/restart/etc)
now about the request:
Yes it would be a nice addition, i was concentrating on making pystemd accept regular strings first (that is done, so i expect to put a new release today).
about this, i would definitely work on this. i still need to think exactly how to do it. The thing is that i dont want to assume anything about the used types, and i would much ratter let libsystemd0 reject types as they come, but with that said i can work on some sort of warning (hey you are putting a type X, but expected something from the family of type Y). let me think about it, and really thanks for the input.
Alvaro
thanks!
Thanks for the suggestion; psytemd.run is launching processes; now I'm trying to figure out how to monitor the running processes:
name = b'test.sleep.service'
pystemd.run([b'/usr/bin/sleep', b'10'], name=name)
unit = Unit(name, _autoload=True)
unit.Service.MainPID # always 0?
Does this seem like the correct way to use the API?
yes, MainPID shoudl be 0 when the process exit (or never started). you can do a few extra things:
unit = pystemd.run([b'/usr/bin/sleep', b'10'], remain_after_exit=True)
print('MainPID', unit.Service.MainPID)
print('SubState', unit.Unit.SubState)
print('LoadState', unit.Unit.LoadState)
you'll get
MainPID 3351
SubState b'running'
LoadState b'loaded'
By passing the remain_after_exit you make the unit to stay in memory after it finish, and allow pystemd.run to return a Unit file. if you don't specify, then when the unit finish (your 10 seconds), the unit will just go away.
there some (not the best i agree) documentation here https://github.com/facebookincubator/pystemd/blob/master/_docs/pystemd.run.md
i just landed something that will help with the debug, is not the best thing, but its there... this will continue to be on our radar,
Trying to follow the example for starting a transient unit from here: https://github.com/facebookincubator/pystemd/blob/master/examples/start_transient_unit.py
However, I'm getting the following error:
Because it is cython, I don't know how far the loop got.
I can see the
args
getting passed in tocall_method
:I think putting the value and/or name of the argument causing the problem would improve debugability a lot.
EDIT: the bug was I forgot to split the byte-string into a list, so cmd[0] was returning an integer