Unix & Linux Asked by Rick LeLoup on December 17, 2021
I had to adjust a script from an “old” RHEL6 SysV script to a “new” RHEL7 systemd script. I can do the systemd script for LibreOffice no problem, but when I try to had Xvfb (mandatory for users with a GUI to connect to the LibreOffice server and use it) it stopped working and gives me headaches. I tried to launch it independantly (first Xvfb in a .service then libreoffice) but still no chance … The only way I made it work is by launching Xvfb at the command line then launching the systemd script for LibreOffice server. I’ll show you my scripts :
Old SysV script :
#!/bin/bash
# openoffice.org headless server script
#
# chkconfig: 2345 80 30
# description: headless openoffice server script
# processname: openoffice
#
# Author: Vic Vijayakumar
# Modified by Federico Ch. Tomasczik
OOo_HOME=/opt/libreoffice5.0/program
SOFFICE_PATH=$OOo_HOME/soffice
PIDFILE=/var/run/openoffice-server.pid
set -e
case "$1" in
start)
if [ -f $PIDFILE ]; then
echo "OpenOffice headless server has already started."
sleep 5
exit
fi
echo "Starting OpenOffice headless server"
Xvfb :1 -screen 0 1024x768x24 & > /dev/null 2>&1
$SOFFICE_PATH --nolockcheck --norestore --nodefault --nologo --nofirststartwizard --accept="socket,host=localhost,port=8085,tcpNoDelay=1;urp" --display :1 & > /dev/null 2>&1
touch $PIDFILE
;;
stop)
if [ -f $PIDFILE ]; then
echo "Stopping OpenOffice headless server."
killall -9 oosplash && killall -9 soffice.bin && killall -9 Xvfb
rm -f $PIDFILE
exit
fi
killall -9 Xvfb
echo "Openoffice headless server is not running."
exit
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
New Systemd Script :
[Unit]
Description=Headless LibreOffice server script
Documentation=https://fr.libreoffice.org/
DefaultDependencies=no
[Service]
ExecStartPre=Xvfb :1 -screen 0 1024x768x24 -nolisten inet6 & > /dev/null 2>&1
ExecStart=/usr/lib64/libreoffice/program/soffice --headless --nolockcheck --norestore --nodefault '--accept=socket,host=localhost,port=8101,tcpNoDelay=1;urp;' --nofirststartwizard --nologo
Type=oneshot
TimeoutStopSec=5
PIDFile=/var/run/libreoffice-server.pid
[Install]
WantedBy=multi-user.target
Then I found that the redirection (&) are not functionning really well in a systemd script so I made a bash script and called it from the systemd script like this :
...
[Service]
ExecStartPre=/bin/bash /usr/bin/Xvfb_launch.sh
...
And there is Xvfb_launch.sh :
#!/bin/bash
/usr/bin/Xvfb :1 -screen 0 1024x768x24 -nolisten inet6 & > /dev/null 2>&1
But still not working, the script stays forever on “Activating” and no process are launched.
Any ideas ?
Thank you for your help !
Have a great day !!
Rick
Libreoffice no longer requires a display if gui is not needed (so xvfb is not necessary)
Answered by rapto on December 17, 2021
I finally found how to fix this issue ...
I made a libreoffice-server.service that depends on another service (Xvfb.service) to start instead of calling the 2 services from one script and all is working perfectly now. I'll give you my solution if anyone else have the same kind of issue they'll be able to fix it.
First I did the Xvfb.service file :
[Unit]
Description=X Virtual Frame Buffer Service
After=network.target
Before=libreoffice-server.service
Documentation=http://x.org
DefaultDependencies=no
[Service]
ExecStart=/usr/bin/Xvfb :1 -screen 0 1024x768x24 -nolisten inet6
Type=simple
TimeoutStopSec=5
PIDFile=/var/run/Xvfb.pid
[Install]
WantedBy=multi-user.target libreoffice-server.service
Then I've edited the libreoffice-server.service to be like that :
[Unit]
Description=Headless LibreOffice server script
After=network.target
Documentation=https://fr.libreoffice.org/
DefaultDependencies=no
Wants=Xvfb.service
[Service]
ExecStart=/usr/lib64/libreoffice/program/soffice --headless --nolockcheck --norestore --nodefault '--accept=socket,host=localhost,port=8101,tcpNoDelay=1;urp;' --nofirststartwizard --nologo --display :1
Type=simple
TimeoutStopSec=5
PIDFile=/var/run/libreoffice-server.pid
[Install]
WantedBy=multi-user.target
Then I enabled the 2 scripts to start on machine boot :
$sudo systemctl enable Xvfb.service
$sudo systemctl enable libreoffice-server.service
And now when the machine boot the Xvfb.service starts right before the libreoffice-server.service is. So now everything works just fine !!
And I noticed that if I stopped Xvfb.service and Libreoffice-server.service then I launched libreoffice-server from the command line, it starts Xvfb.service BEFORE starting it's own process. So it's really the solution I was looking for.
Hope it will help some more people, I've searched for this solution for a week now and I finally find my answer, so I'm sharing it to the community.
Have a great day !!
Answered by Rick LeLoup on December 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP