0

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?

Dragan R.
  • 598
  • 4
  • 18
  • 1
    Usually a bad idea. Just make it run synchronously in the console, CTRL+C to break, and use bash features to run in the background or to run as a daemon, to redirect logs etc. If you're still going that way (you shouldn't), `--start-collect` should daemonize your process, writing a pid file. `--stop-collect` should read the pid file and act accordingly on the daemon process. – Jazzwave06 Sep 17 '18 at 14:24
  • Can you add a socket to `metrics-tool` and have it listen for start/stop *commands*? – wwii Sep 17 '18 at 16:00

1 Answers1

1

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

grahamlyons
  • 687
  • 5
  • 15