njh / rotter

Rotter is a Recording of Transmission / Audio Logger for JACK.
http://www.aelius.com/njh/rotter/
GNU General Public License v2.0
50 stars 11 forks source link

Ability to call a hook command/script on file rotation #35

Open paraenggu opened 6 years ago

paraenggu commented 6 years ago

First, thanks a lot for publishing this nice piece of recording software. I'm currently evaluating and testing it to see if it could replace our current 7/24h recording solution.

What would be really nice, is the ability to call a custom hook command or script on file rotation. Ideally, one could specify an optional command (rotter ... -s "/usr/libexec/rotter/my-rotter-hook.sh %s" /var/tmp ) which will be called each time a recording has finished (the file gets closed). The command would be executed and %s (or similar) would be replaced with the absolute path to the finished recording file.

In my case, I have to record to a temporary path and move the file to its final location once (but not before) it has finished (e.g. rotter ... -s "/usr/bin/mv %s /var/archive/" /var/tmp). Other use cases would be to upload the file somewhere, insert a database record, inform a monitoring system or similar.

njh commented 6 years ago

Yes - very good idea.

The other thing I have considered is using a pipe or Unix socket that can provide a stream of files as they are written to disk.

I am not sure when I might get round to implementing this. In the meantime you could look at using a Filesystem notification system. Unfortunately this is operating system specific, but it is possible to get an notification when a file in a directory is closed:

https://github.com/rvoicilas/inotify-tools/wiki

paraenggu commented 6 years ago

Thanks for your prompt feedback. I've also considered to implement this with the help of inotify and waiting for close_write, but thought that the implementation of a hook command execution could be beneficial for other use cases as well and doesn't require another long-running process/daemon.

paraenggu commented 6 years ago

One needs to be aware, that two close_write events occur while recording a flac or vorbis file (as the first read-write open fails). This means, that a script using inotify needs to either preserve some event history about a file, or initiate a size or modification time sanity check before acting on a close_write event.