我正在使用 python2.7 检查服务是否正在运行。我已经制作了自己的服务并将其放在 /etc/init.d
中。我有一个正在使用它的覆盆子。
现在要正常检查服务状态,我们可以这样做:
service my_service status
但是如何从 python 代码中获取服务状态。
谢谢
最佳答案
我可能要晚几年才能回答这个问题..但这是我找到的一个简单的解决方案
import os # I think it's better to use subprocess for this. but quick code for example
status = os.system('systemctl is-active --quiet service-name')
print(status) # will return 0 for active else inactive.
关于linux - 用于检查服务是否正在运行的 Python 代码。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46579170/