systemd / pystemd

A thin Cython-based wrapper on top of libsystemd, focused on exposing the dbus API via sd-bus in an automated and easy to consume way.
GNU Lesser General Public License v2.1
411 stars 36 forks source link

Create Services/Timers #30

Closed henne90gen closed 4 years ago

henne90gen commented 5 years ago

Is it possible to create services or timers with pystemd? It would be awesome to be able to create these without having to copy files, but instead setting them up in python code.

aleivag commented 5 years ago

hi @henne90gen ,

you can create transient units with pystemd... for services, using pystemd.run is the best way, and i plan to extend pystemd.run to support .path .socket and .timer also...

with that said, right now, its not the easiest thing to do, but you can create timers and other units you just use StartTransientUnit from pystemd.systemd1.Manager object... an example is here

https://github.com/facebookincubator/pystemd/blob/master/examples/start_multiple_transient_unit.py

it does require you to know a little bit about what you are doing, but hey! you can always come here and ask.

will update here if/when pystemd.run support timers path and other stuff.

note: keep in mind that i'm talking about transient units, for non transient units, you probably should let your configuration management to deal with those.

Hope this helps!!

henne90gen commented 5 years ago

So it is not planned to add support for non transient units to pystemd? I would love to be able to define a service in my python code and have it installed as a permanent systemd service.

aleivag commented 5 years ago

i agree it would be cool to do that... :D , and maybe some day we will do it, but as of now, we dont want to do it... you see, pystemd is just a python interface to systemd... we dont do anything systemd (and more specifically libsystemd) dont already do. And systemd does not provide a public interface for creating non-transient units.

with that said, i dont think it would be hard to implement yourself... maybe some interface between yaml/multidict and then a rendered to convert to the .ini-ish file...

anyway will comment back once timers and path are part of pystemd.run

henne90gen commented 5 years ago

I would love to contribute to pystemd and create an API like pystemd.create, which would create a non-transient unit. Is that something that could get merged into the project or are you not interested in that?

aleivag commented 5 years ago

thanks for the offering, but we dont think this is something that should be part of pystemd.

But if you do it a separate project, i would be more than happy to contribute to that!, i do think its a cool idea, just dont think it belong in pystemd.

zealws commented 4 years ago

with that said, i dont think it would be hard to implement yourself... maybe some interface between yaml/multidict and then a rendered to convert to the .ini-ish file...

python has support for parsing and generating ini files via the configparser module. It would be pretty easy to use this to generate systemd units and drop them in the appropriate path.