When using unoserver as a long-running service, it is often useful to restart both unoserver and LibreOffice after a certain number of requests (e.g. 1,000), so that any potential bad state is reset and any potential misallocated memory in LibreOffice is freed.
This PR adds the parameter --stop-after to unoserver:
--stop-after: Terminate Libreoffice and exit after the given number of requests.
Demonstation
Here is a demonstration of using the new parameter.
First, we spin up a Docker container with Ubuntu, LibreOffice, Python, and the code from this PR:
Finally, from the outside of the container, we launch 5 conversions:
$ for _ in {1..5}; do docker exec unoserver-stop-after unoconvert /demo.docx /demo.odt; done
INFO:unoserver:Connecting.
INFO:unoserver:Converting.
INFO:unoserver:Saved to /demo.odt.
INFO:unoserver:Connecting.
INFO:unoserver:Converting.
INFO:unoserver:Saved to /demo.odt.
INFO:unoserver:Connecting.
INFO:unoserver:Converting.
INFO:unoserver:Saved to /demo.odt.
INFO:unoserver:Connecting.
INFO:unoserver:Converting.
INFO:unoserver:Saved to /demo.odt.
INFO:unoserver:Connecting.
INFO:unoserver:Converting.
INFO:unoserver:Saved to /demo.odt.
Meanwhile, in the container, we can see that unoserver has exited with a zero exit code after the fifth conversion:
127.0.0.1 - - [30/Oct/2024 13:04:56] "POST /RPC2 HTTP/1.1" 200 -
INFO:unoserver:Opening /demo.docx for input
INFO:unoserver:Exporting to /demo.odt
INFO:unoserver:Using writer8 export filter from None to writer8
127.0.0.1 - - [30/Oct/2024 13:04:57] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [30/Oct/2024 13:05:16] "POST /RPC2 HTTP/1.1" 200 -
INFO:unoserver:Opening /demo.docx for input
INFO:unoserver:Exporting to /demo.odt
INFO:unoserver:Using writer8 export filter from None to writer8
127.0.0.1 - - [30/Oct/2024 13:05:17] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [30/Oct/2024 13:05:17] "POST /RPC2 HTTP/1.1" 200 -
INFO:unoserver:Opening /demo.docx for input
INFO:unoserver:Exporting to /demo.odt
INFO:unoserver:Using writer8 export filter from None to writer8
127.0.0.1 - - [30/Oct/2024 13:05:17] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [30/Oct/2024 13:05:17] "POST /RPC2 HTTP/1.1" 200 -
INFO:unoserver:Opening /demo.docx for input
INFO:unoserver:Exporting to /demo.odt
INFO:unoserver:Using writer8 export filter from None to writer8
127.0.0.1 - - [30/Oct/2024 13:05:18] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [30/Oct/2024 13:05:18] "POST /RPC2 HTTP/1.1" 200 -
INFO:unoserver:Opening /demo.docx for input
INFO:unoserver:Exporting to /demo.odt
INFO:unoserver:Using writer8 export filter from None to writer8
INFO:unoserver:Processed 5 requests, exiting.
127.0.0.1 - - [30/Oct/2024 13:05:19] "POST /RPC2 HTTP/1.1" 200 -
When using
unoserver
as a long-running service, it is often useful to restart bothunoserver
and LibreOffice after a certain number of requests (e.g. 1,000), so that any potential bad state is reset and any potential misallocated memory in LibreOffice is freed.This PR adds the parameter
--stop-after
tounoserver
:--stop-after
: Terminate Libreoffice and exit after the given number of requests.Demonstation
Here is a demonstration of using the new parameter.
First, we spin up a Docker container with Ubuntu, LibreOffice, Python, and the code from this PR:
Next, we download an example DOCX file and we launch
unoserver
with the parameter--stop-after 5
:Finally, from the outside of the container, we launch 5 conversions:
Meanwhile, in the container, we can see that
unoserver
has exited with a zero exit code after the fifth conversion: