Content translation/cxserver/Setup
InstallationEdit
Get the codeEdit
Content Translation ServerEdit
If you want to do an anonymous checkout:
git clone https://gerrit.wikimedia.org/r/mediawiki/services/cxserver
Or if you plan to hack CXServer, then please follow the Gerrit 'getting started' docs and use an authenticated checkout url instead, such as:
git clone ssh://<user>@gerrit.wikimedia.org:29418/mediawiki/services/cxserver
NodejsEdit
Install nodejs 8 or higher. When you are using Ubuntu and depending on OS version you may not end up with the most recent version of nodejs please read this [1] first before you proceed:
sudo apt-get install nodejs npm
nodejs --version # should now print 8 or higher
For other systems, see:
JS dependenciesEdit
Install the JS dependencies. Run this command in the cxserver directory:
npm install
Dictd ServerEdit
InstallationEdit
sudo apt-get install dictd
To install language pair,
sudo apt-get install dict-freedict-xxx-yyy
Where xxx and yyy are two different languages.
On CentOS 7 instead do:
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/Kenzy:/packages/CentOS_7/x86_64/dictd-server-1.12.0-6.4.x86_64.rpm
rpm -Uvh dictd-server-1.12.0-6.4.x86_64.rpm
RESTBase ServerEdit
InstallationEdit
Server ConfigurationEdit
An example configuration file is given as config.dev.yaml and config.prod.yaml.
RESTBase configuration sectionEdit
...
restbase_req:
method: '{{request.method}}'
uri: http://localhost:7231/YOUR_WIKI_WEBSITE/v1/{+path}
query: '{{ default(request.query, {}) }}'
headers: '{{request.headers}}'
body: '{{request.body}}'
...
Apertium configuration sectionEdit
...
apertium:
api: http://localhost:2737
...
The server expected on localhost:2737 is then Apertium-apy . (See http://wiki.apertium.org/wiki/Apy for instructions; you'll have to install Apertium and at least one language pair too). Adjust configuration according to your requirement and restart the server.
Run the serverEdit
Using nodeEdit
$ nodejs server.js
On CentOS 7:
$ node server.js
Using npmEdit
$ npm start
As a cxserver commandEdit
Following step is to be performed only once. You might have to use 'sudo'.
$ npm link .
Subsequently, just use following to start the server.
$ cxserver
Then browse to http://localhost:8080/v1 You'll see the server playground page.
Running it in secure mode (https)Edit
In the configuration file, provide the SSL certificate details and set value of 'secure' as true
DebuggingEdit
To run the ContentTranslation server:
$ npm run-script debug
It will open Chrome developer tools with the ContentTranslation source code. You can debug the code just like a web application. You can also edit the code and save from the debugger.
Starting cxserver automaticallyEdit
There are many ways to start services automatically, consult your server's operating system documentation.
upstartEdit
On Ubuntu and other operating systems using Upstart, one approach is
sudo ln -s /lib/init/upstart-job /etc/init.d/cxserver
sudo vi /etc/init/cxserver.conf
And, use following upstart script template:
# Upstart job configuration for cxserver
description "cxserver service"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]
setuid "www-data"
setgid "www-data"
env NODE_PATH="/path/to/cxserver/node_modules"
chdir "/path/to/cxserver"
exec npm start
respawn
To start cxserver,
sudo service cxserver start
To stop cxserver,
sudo service cxserver stop
DebuggingEdit
Upstart can be debug using log messages at /var/log/syslog
.
systemdEdit
On recent versions of Debian, Fedora and other operating systems using systemd, use a cxserver.service
unit file similar to the following template (modify the file paths as appropriate) and place file at /lib/systemd/system/
directory.
[Unit]
Description=MediaWiki Content Translation service
Documentation=https://www.mediawiki.org/wiki/ContentTranslation
Wants=local-fs.target network.target
After=local-fs.target network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/path/to/cxserver/node_modules
ExecStart=/usr/bin/node /path/to/cxserver/server.js
KillMode=process
Restart=on-success
PrivateTmp=true
StandardOutput=syslog
To start cxserver,
sudo service cxserver start
To stop cxserver,
sudo service cxserver stop
If you change in service script, you need to reload script by,
sudo systemctl --system daemon-reload
DebuggingEdit
Systemd scripts logs messages at /var/log/syslog
. It can be customized using StandardOutput=
in cxserver.service script.
Backend ServicesEdit
VarnishEdit
InstallationEdit
sudo apt-get install varnish
ConfigurationEdit
1. Configure varnish http accelerator port:
edit /etc/default/varnish
Example configuration to run varnish on port 8000
DAEMON_OPTS="-a :8000 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
2. Configure the varnish default backend:
edit /etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
}
3. Restart the varnish:
sudo service varnish restart
Make sure you are running cxserver nodejs server on port 8080 - the backend configuration of varnish
cxserver --port=8080
127.0.0.1:8000 will be your server URL with varnish 127.0.0.1:8080 will be your server URL without varnish
4. Configure cxclient's wgContentTranslationServerURL to 127.0.0.1:8000
Extensions dependenciesEdit
Content translation extension requires following extensions as dependencies.