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:
We don't necessarily need complex operations. Start, stop, restart, reload, and status is ok.
** 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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.