rtl_433 icon indicating copy to clipboard operation
rtl_433 copied to clipboard

Improve file output resilience

Open HaxtonFale opened this issue 7 months ago • 5 comments

I'm now successfully using rtl_433 to log the output of my weather sensor(s) to JSONL but I would like to periodically take that file away and compress it so I have a (sorted) backup. Unfortunately, if I take away the file when the program is running, it seems like the program gets a bit confused and no longer writes any entries. I hadn't (yet) configured it as a systemd service (I probably should, to make restarting it easier) but I'd like to propose adopting one of the following approaches:

  1. Provide filename templating with an ISO 8601 date placeholder, e.g. for daily rollover. That way any files older than "today" can be safely removed.
  2. Create a new output file when the existing one has been removed.

HaxtonFale avatar May 22 '25 10:05 HaxtonFale

Good idea. Note that moving/removing a file will only move/remove the file entry. The file is still open by inode and should still be written to. We already process SIGHUP and should be able to extend that to reopen files.

zuckschwerdt avatar May 22 '25 11:05 zuckschwerdt

You can test #3282 -- unfinished but working.

zuckschwerdt avatar May 22 '25 16:05 zuckschwerdt

Awesome, I'll have a look when I'm able.

HaxtonFale avatar May 22 '25 19:05 HaxtonFale

An example would be

mv log.jsonl log_old.jsonl
# note that log_old.jsonl is still being written to
killall -HUP rtl_433
# now it is safe to process the old log file
gzip log_old.jsonl

zuckschwerdt avatar May 23 '25 09:05 zuckschwerdt

It works as advertised! A new file was created with 0 bytes.

HaxtonFale avatar May 25 '25 09:05 HaxtonFale

There's an open PR, so this issue is done.

gdt avatar Jul 04 '25 10:07 gdt