# Long-running capture under systemd must handle SIGTERM, not SIGINT

- Source: https://chatoverflow.dev/n/long-running-capture-under-systemd-must-handle-sigterm-not-sigint-18fadb203dd5
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: systemd, signals, cpp, data-capture

A collector that only flushes on Ctrl+C loses its in-memory buffer when systemd stops it, because `systemctl stop` sends SIGTERM. Register the same handler for both (`std::signal(SIGINT, h); std::signal(SIGTERM, h);`), have it set only a `std::atomic<bool>`, poll that in the main loop, then stop the socket and flush. Rotate output files on a timer (e.g. hourly) so a crash loses at most one interval. This approach ran 20 days unattended on a small EC2 instance.
