💾 Archived View for alltext.umaneti.net › gemlog › LibreOffice-Headless-with-systemd › index.gmi captured on 2024-07-08 at 23:36:14. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2024-08-18)

-=-=-=-=-=-=-

LibreOffice Headless with systemd

I've fought a very annoying bug recently and think it's worth sharing it here. At work we manage different type of user provided documents. For various reason we convert it to pdf. This step is achieved using a headless libreoffice[1] installation. Our server run Debian GNU/Linux Wheezy[2] and everything go smoothly.

Until… one of our client need our software to be hosted on his own servers, running CentOS. Nothing bad here, but it leads us to develop various systemd service files for our systems as recent versions of CentOS switched to systemd. Here come the bug. We were used to run libreoffice as follow, embed in an init.d script:

soffice -headless -accept="socket,host=127.0.0.1,port=8101;urp;" -display :5.0 -nofirststartwizard & > /var/log/soffice.log 2>&1

Moving on systemd and more recent version of libreoffice, I learn that single-dotted options are no more. Thus, my first attempt to write a systemd service file, directly inspired by the line above, was:

[Unit]
Description=Control headless soffice instance
After=network.target xvfb.service
Requires=xvfb.service

[Service]
Type=simple
ExecStart=/opt/libreoffice4.4/program/soffice --headless \
    --accept="socket,host=127.0.0.1,port=8101;urp;" --display :5.0 \
    --pidfile=/var/run/soffice.pid --nologo --nodefault --nofirststartwizard
RestartSec=5
ExecStop=/usr/bin/pkill -F /var/run/soffice.pid
PIDFile=/var/run/soffice.pid

[Install]
WantedBy=multi-user.target

And nothing works as expected. In fact, I'm lying a bit: the daemon was here, systemctl telling me everything is ok and libreoffice showing off in `ps axf'. But no conversion succeeded. The problem was obvious: looking at `netstat -laputn' show me that nothing was listening at port 8101.

After weeks of test, we abandoned the problem (I just start the exactly same command by hand and forget it). Yesterday it comes to my face, due to a libreoffice crash, which prevents conversion to occurs. We use monit[3] to monitor our process, but in this case soffice wasn't monitored, as I didn't reached to have a functional service. As I was crying blood, because of not understanding the problem source, I try a last thing before fucking all of it and writing a quick'n'dirty shell script. And it works.

[Unit]
Description=Control headless soffice instance
After=network.target xvfb.service
Requires=xvfb.service

[Service]
Type=simple
ExecStart=/opt/libreoffice4.4/program/soffice --headless \
    --accept=socket,host=127.0.0.1,port=8101;urp; --display :5.0 \
    --pidfile=/var/run/soffice.pid --nologo --nodefault --nofirststartwizard
RestartSec=5
ExecStop=/usr/bin/pkill -F /var/run/soffice.pid
PIDFile=/var/run/soffice.pid

[Install]
WantedBy=multi-user.target

Yes: nothing changes, but the quotation marks on line 9. The solution was simply to remove them from the `ExecStart' line. I absolutely don't know why putting here double quotes prevent systemd-started soffice to open a socket, but it does. If anyone has an explanation, I'm very curious. The documentation[4] itself is not very clear about that. Anyway, now we have a working service file for headless execution of libreoffice.

[1] headless libreoffice (I18N)

[2] Debian GNU/Linux Wheezy (I18N)

[3] monit (I18N)

[4] documentation (I18N)

Commentaires

Comment from Dani

--

📅 mercredi 23 mars 2016 à 17:01

📝 milouse with GNU/Emacs 29.4 (Org mode 9.7.6)

propelled by fronde