0

This is an extension to the question is there a way to start/stop linux processes with python?

I just came across this piece of code:

os.system("/etc/init.d/apache2 " + op)

...where op is the action to perform on the service.

Obviously this is init-specific, perhaps even limited to openrc or some such. It's also going to break really easily.

Is there a python library to manage system services using the platform's own service manager?

It could be as simple as an OS Rosetta, but I imagine it's a little more complex if you include non-POSIX OSs.

As opposed to the other question:

  • I don't want the service to be a child process of my python app. Services themselves should be independently managed as normal.
  • We should, if possible, use the Operating System's chosen process manager
  • On Linux, this could mean any of openrc, init, supervisord, etc.
  • I would like it also to run on Windows and OSX, if possible.

We don't necessarily need complex operations. Start, stop, restart, reload, and status is ok.

Community
  • 1
  • 1

1 Answers1

0

** Interim Answer - POSIX systems only **

Ansible appear to have written a class to do exactly that here, at least for POSIX-derived OSs.

From the code:

Supported init systems include BSD init, OpenRC, SysV, Solaris SMF, systemd, upstart.

It appears to be a class called "LinuxService" which has a number of functions:

get_service_status()
service_enable()
service_control()