- Notifications
You must be signed in to change notification settings - Fork17
run unoconv as a webservice
License
HeavyHorst/unoconv-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
unoconv-api is a simple http service that will call the unoconv executable, that in turn will call into the libreoffice api to convert documents.
For more info on unoconv and all possible conversions see theunoconv website.
Note: unoconv-api will serialize calls to the unoconv executable, since it doesn't support concurency.
Post the file you want to convert to the server and get the converted file in return.
The API for the webservice is /unoconv/{format-to-convert-to} so a docx to pdf conversion would be:
$ curl --form file=@myfile.docx http://127.0.0.1:3000/unoconv/pdf> myfile.pdf
There's a simple healthcheck api oncurl http://127.0.0.1:3000/unoconv/health
that tries to convert some plain text to pdf,and returns "200 -OK" on success.
To compile just rungo build
, the project usesgo 1.11 modules,so it'll download dependencies automatically.
Two services, one for unoconv (the libreoffice listener), and the other for unoconv-api.Both are running with the same user, but also DynamicUser=true, so no need to create the useron the system. They share a runtime directory (/run/unoconv
) for temporary files.
The services are bound together (BindsTo=
), so if one is restarted the other will be too.unoconv-api implements a systemd watchdog too, that will test that conversions are possible.
# unoconv-api.service[Unit]Description=unoconv-api listenerBindsTo=unoconv.serviceAfter=unoconv.service[Service]Type=notifyDynamicUser=yesWatchdogSec=60User=unoconvGroup=unoconvRuntimeDirectory=unoconvRuntimeDirectoryPreserve=yesEnvironment=TMPDIR=/run/unoconvEnvironment=LISTEN_ADDR=127.0.0.1:3000ExecStart=/usr/local/bin/unoconv-apiSyslogIdentifier=unoconv-apiRestart=always[Install]WantedBy=multi-user.target
# unoconv.service[Unit]Description=unoconv libreoffice listener[Service]Type=simpleDynamicUser=yesUser=unoconvGroup=unoconvRuntimeDirectory=unoconvRuntimeDirectoryPreserve=yesStateDirectory=unoconvEnvironment=HOME=/var/lib/private/unoconv/ExecStart=/usr/bin/unoconv --listener --server=127.0.0.1 --port=2002SyslogIdentifier=unoconvRestart=always[Install]WantedBy=multi-user.target