Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --stop-after parameter to unoserver #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Witiko
Copy link

@Witiko Witiko commented Oct 30, 2024

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:

$ docker run --name unoserver-stop-after --rm -it ubuntu
# apt update
# apt install git libreoffice python3 python3-pip wget
# pip install -U pip wheel setuptools
# pip install git+https://github.com/witiko/unoserver@feat/stop-after

Next, we download an example DOCX file and we launch unoserver with the parameter --stop-after 5:

# wget https://calibre-ebook.com/downloads/demos/demo.docx
# unoserver --stop-after 5
INFO:unoserver:Starting unoserver 3.0.2.dev0.
INFO:unoserver:Command: /usr/bin/soffice --headless --invisible --nocrashreport --nodefault --nologo --nofirststartwizard --norestore -env:UserInstallation=file:///tmp/tmpm2fgj8md --accept=socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext
INFO:unoserver:Starting UnoConverter.
INFO:unoserver:Starting UnoComparer.
INFO:unoserver:Server PID: 11762

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 -
# echo $?
0

@Witiko
Copy link
Author

Witiko commented Nov 4, 2024

What do you think, @regebro?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant