How to start independent LO instance (avoid unoconv aborts)

Is it possible to start a separate, independent instance of LO which has no interaction with an already-running LO process?

Doing so is, I think, necessary to fix a forever-standing bug in the linux unoconv batch-convertion script. unoconv works by sending commands through a socket to a separate LO process. If it can’t connect to an existing LO process for some reason, it tries to start it’s own LO process.

But when it starts its own, the LO process it starts immediately exits (with zero status) without doing anything if another LO process is running. This causes unoconv to abort.

Here is what unoconv runs to start its “own” instance:

/usr/lib/libreoffice/program/soffice.bin --headless --invisible --nocrashreport --nodefault --nofirststartwizard --nologo --norestore --accept='socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext'

If you run this interactively with no previous LO process running, it just sits there as you might expect (doing nothing but listening on the indicated socket/port).

But if you first open a spreadsheet with localc /path/to/something.xlsx and then run the above command in another terminal, the supposedly-second LO process exits immediately, i.e. it does not stick around and listen. Even if you specify a different port number in the --accept string.

Side note: There remains a question as to why the existing interactive LO process can not work with batch unoconv commands. I don’t know the answer. It seems to work sometimes, but often fails immediately after LO has freshly started and opened a spreadsheet interactively (as if by default there is no listener, which might be the case). Anyway, I don’t think this should matter if unoconv can reliably start its own, independent instance of LO.

Did you check Search • Apache OpenOffice Community Forum ?

for serious reasons it isnt possible to run more than one instance on the same $user_configuration so you need for an second indepentend instance an addional argument: -env:UserInstallation=file:///home/<you>/...

Thanks @Karolus !

Here’s a wrapper shell script for unoconv which uses a temporary config dir to avoid conflicts. This way unoconv seems to work reliably regardless of what normal LO instances are doing:

#!/bin/sh
set -e -u

# Wrapper for unoconv which make LibreOffice use a separate
# temporary user-config dir to avoid unoconv aborts when
# LO is in use interactively.
#
# https://ask.libreoffice.org/t/how-to-start-independent-lo-instance-avoid-unoconv-aborts/61121

tempdir=$(mktemp -d /tmp/myuno.XXXXX)
cleanup() { [ -z "${tempdir:-}" ] || rm -rf "$tempdir"; }

# Remove tempdir when terminating
trap 'e=$?; cleanup; exit $e' EXIT
for sig in HUP INT QUIT KILL ; do
  trap "cleanup; trap $sig; kill -$sig \$\$" $sig
done

UserInstallation="file://$tempdir" unoconv ${1+"$@"}