简体   繁体   中英

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.

Using Systemd means there's no need to daemonise your Python process yourself: 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

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.

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