简体   繁体   English

如何通过命令行切换过程状态?

[英]How to toggle process state via command line?

We are trying to create a simple command line utility that tracks some metrics over an unknown period of time (start/stop triggered via command line externally). 我们正在尝试创建一个简单的命令行实用程序,该实用程序在未知的时间段内(通过外部命令行触发的启动/停止)来跟踪一些指标。

For example, 例如,

python metrics-tool.py --start-collect

... run some additional commands external to metrics-tool ...

python metrics-tool.py --stop-collect

Does anyone have any ideas or suggestions on how an application can receive a command for a "second time"? 是否有人对应用程序如何“第二次”接收命令有任何想法或建议? Is this even possible, or a good way to do this? 这是否可能,或者这样做的好方法?

It almost sounds like this should be a service, configurable at runtime by an endpoint? 几乎听起来这应该是一项服务,可以在运行时由端点配置?

This does sound more like a service which can be started and stopped, via Systemd (or Supervisor) for example. 这听起来更像是可以通过Systemd(或Supervisor)启动和停止的服务。

Using Systemd means there's no need to daemonise your Python process yourself: https://stackoverflow.com/a/30189540/736221 使用Systemd意味着无需自己守护Python进程: https ://stackoverflow.com/a/30189540/736221

You can of course do that if you want to, if you're using something other than Systemd: https://pagure.io/python-daemon 如果要使用Systemd以外的其他工具,当然可以这样做: https : //pagure.io/python-daemon

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM