Copy/truncate file rotation.
authorIain Patterson <me@iain.cx>
Thu, 18 Sep 2014 07:28:21 +0000 (08:28 +0100)
committerIain Patterson <me@iain.cx>
Thu, 18 Sep 2014 07:28:21 +0000 (08:28 +0100)
commitf7f20a0b3ecbb0e1a2eb59f95b50f0625b37c671
tree14a0dbc5e9e3436e8e492159f69294ed356e39de
parentb5286398f850b432edbddc6d602ab3f33ab086be
Copy/truncate file rotation.

Some processes, notably Logstash, open files for reading without setting
the FILE_SHARE_READ share mode.  If NSSM is using such a file for I/O
redirection and it tries to rotate the file, its MoveFile() call will
fail.

If the new (REG_DWORD) value(s) AppStdoutCopyAndTruncate and/or
AppStderrCopyAndTruncate are non-zero, NSSM will instead try to rotate
the file(s) by calling CopyFile() to create a copy of the file then
calling SetEndOfFile() to truncate the original file to zero size.
Doing so allows the rotation to succeed at the cost of time and disk
space to create a full copy of the file.

If the new (REG_DWORD) value AppRotateDelay is non-zero, NSSM will sleep
for the given number of milliseconds after rotation, regardless of the
rotation method used.  Testing with Logstash specifically has shown that
introducing a delay of 1000ms may be sufficient to avoid an issue
whereby the reading application loses the final line of input from the
old file due to not noticing that it has been truncated.

Thanks Miguel Angel TerrĂ³n.
ChangeLog.txt
README.txt
io.cpp
io.h
nssm.h
registry.cpp
registry.h
service.h
settings.cpp