Universal Office Converter (unoconv): Difference between revisions

From MoodleDocs
Line 18: Line 18:
Potential problems:
Potential problems:
* On some systems the apache user home directory is set to a non existent folder. This can cause unoconv to fail. There are 2 solutions to this - one is to make a (writable) home directory for the apache user (like /home/www-data). The other is to run a unoconv listener (described below) as another user other than the apache user (someone with a valid, writable home directory).
* On some systems the apache user home directory is set to a non existent folder. This can cause unoconv to fail. There are 2 solutions to this - one is to make a (writable) home directory for the apache user (like /home/www-data). The other is to run a unoconv listener (described below) as another user other than the apache user (someone with a valid, writable home directory).
* If you are still running 14.04LTS then unoconv won't work as shipped. This might not be the most efficient route but it worked by installing unoconv from the package manager as above. You will need to grab unoconv 0.7 from Github (https://github.com/dagwieers/unoconv), then upgrade to the latest libreoffice using the PPA (https://launchpad.net/~libreoffice/+archive/ubuntu/ppa). Point moodle at the Github version of unoconv. You need to modify the Python unoconv file by changing 'python' in the first line to 'python3'. You also need to change the permissions on the directory /var/www so that the user www-data can write to it (www-data needs to write to its home directory which it cannot do by default).
* If you are still running 14.04LTS then unoconv won't work as shipped. This might not be the most efficient route but it worked by first installing unoconv (version 0.6) from the package manager as above. You will then need to grab unoconv 0.7 from Github (https://github.com/dagwieers/unoconv), then upgrade to the latest libreoffice using the PPA (https://launchpad.net/~libreoffice/+archive/ubuntu/ppa). Point moodle at the Github version of unoconv. You need to modify the Python unoconv file by changing 'python' in the first line to 'python3'. You also need to change the permissions on the directory /var/www so that the user www-data can write to it (www-data needs to write to its home directory which it cannot do by default).


== Installing unoconv on OS X ==
== Installing unoconv on OS X ==

Revision as of 08:55, 19 May 2016

Installing unoconv

"unoconv" is a command line program that is used to convert between different office document file formats. It uses an instance of LibreOffice to do the conversion and is used by the assignment module to convert documents to pdf so that they can be annotated. If unoconv is not installed - the only impact is that the assignment module will only allow annotations when students upload a pdf document.

The steps required to install unoconv are different depending on the operating system that you have installed Moodle on.

Installing unoconv on Linux

The required version of unoconv is at least 0.7. Depending on your flavour of linux, this may be available in your package manager and you can install it directly with:

(Ubuntu 16.04 LTS)

apt-get install unoconv

If your package manager contains an older version of the package, you will have to find a newer version and install it manually (Debian Testing). Unoconv itself is just a python script, so it has few dependencies.

Potential problems:

  • On some systems the apache user home directory is set to a non existent folder. This can cause unoconv to fail. There are 2 solutions to this - one is to make a (writable) home directory for the apache user (like /home/www-data). The other is to run a unoconv listener (described below) as another user other than the apache user (someone with a valid, writable home directory).
  • If you are still running 14.04LTS then unoconv won't work as shipped. This might not be the most efficient route but it worked by first installing unoconv (version 0.6) from the package manager as above. You will then need to grab unoconv 0.7 from Github (https://github.com/dagwieers/unoconv), then upgrade to the latest libreoffice using the PPA (https://launchpad.net/~libreoffice/+archive/ubuntu/ppa). Point moodle at the Github version of unoconv. You need to modify the Python unoconv file by changing 'python' in the first line to 'python3'. You also need to change the permissions on the directory /var/www so that the user www-data can write to it (www-data needs to write to its home directory which it cannot do by default).

Installing unoconv on OS X

Download and install LibreOffice for Mac. Make sure to run it and verify it is working before continuing.

Get the latest version of the unoconv python script. One way to do this is with [brew].

brew install unoconv

If you haven't done it already - install ghostscript. One way to install ghostscript is also with [brew]

brew install ghostscript

Set the paths to unoconv and ghostscript in Moodle (Site administration ▶︎ Server ▶︎ System paths ). If you used brew, they will both be installed to /usr/local/bin.

Installing unoconv on Windows

Download and install LibreOffice for windows.

Download the latest version of the unoconv script from https://github.com/dagwieers/unoconv/releases.

Rename the downloaded script to C:\unoconv\unoconv.py

Create a batch file C:\unoconv\unoconv.bat with these contents:

@cd "C:\Program Files (x86)\LibreOffice 5\program"
@"python-core-3.3.0\bin\python.exe" unoconv.py %* 

Set paths in Moodle.

Login as admin and go to Site administration ► Server ► System paths

Set pathtogs setting to your ghostscript installation binary, (C:\gs\bin\gswin32.exe)

Set pathtounoconv to the batch file created above (C:\unoconv\unoconv.bat)

Test ghostscript and unoconv are working correctly in the admin test pages "Site administration ► Plugins ► Activity modules ► Assignment ► Feedback plugins ► Annotate PDF".

Run a unoconv listener

unoconv utilises a client/server process when converting documents. By default, when there is no running server process - each time unoconv runs it will start a server process, send it's request and shutdown the server process when the request is complete. The drawback of this mode is that if 2 requests are submitted simultaneously - this can cause the first request to shutdown the server process when the second request is still in progress - and the second conversion request fails. A more robust way to configure unoconv is to start a server process at boot time, and run a script to monitor it and restart it if it crashes.

To start a unoconv listener at boot time on linux - you need a start up script. Different linux distributions use different startup scripts - but here is an example of an init.d script for debian systems.

Init script for Debian

Offload processing to a different server

Processing office documents can put increased load on your webserver, which may impact on the responsiveness of your site. If you are installing unoconv on a large site you may want to consider running unoconv on a server that is not also serving web requests.

How to do this:

Install unoconv on each webservers and the remote server following the installation instructions above.

Make sure unoconv is started at boot time on the remote server with the "--listener" argument and is monitored and restarted if it exits (see Debian init script for an example of how to do this).

Open the firewall port 2002 between the moodle webservers and the machine running unoconv.

Share the moodle data root between the webservers and the machine running unoconv. This folder must be mounted at the same path on all servers.

Install a wrapper for unoconv on the webservers that forwards the requests to the remote server. Example:

#!/bin/bash
# Wrapper script for unoconv to forward processing.
# Install to /usr/bin/unoconv-remote with 755 permissions
/usr/bin/unoconv --server=<ip of remote server> "$@"

Configure the path to unoconv in the Moodle admin settings to point to this wrapper script.

Additional Resources

The unoconv documentation site has additional information on installation of unoconv and troubleshooting tips.