This is where it gets interesting! The CKAN software can be customised with ‘extensions’. These are a simple way to extend core CKAN functions.
Extensions allow you to customise CKAN for your own requirements, without interfering with the basic CKAN system.
This is an advanced topic.
All CKAN extensions are listed on the official Extension listing on the CKAN wiki.
Some popular extensions include:
Those marked with (x) are ‘core’ extensions and are shipped as part of the core CKAN distribution
- ckanext-stats (x): Statistics (and visuals) about the datasets in a CKAN instance.
- ckanext-apps: Apps and ideas catalogue extension for CKAN.
- ckanext-disqus: Allows users to comment on dataset pages with Disqus.
- ckanext-follower: Allow users to follow datasets.
- ckanext-googleanalytics: Integrates Google Analytics data into CKAN. Gives download stats on dataset pages, list * of most popular datasets, etc.
- ckanext-qa: Provides link checker, 5 stars of openness and other Quality Assurance features.
- ckanext-rdf: Consolidated handling of RDF export and import for CKAN.
- ckanext-wordpresser: CKAN plugin / WSGI middleware for combining CKAN with a Wordpress site.
- ckanext-spatial: Adds geospatial capabilities to CKAN datasets, including a spatial search API.
Installing an Extension¶
You can install an extension on a CKAN instance as follows.
‘Core’ extensions do not need to be installed – just enabled (see below).
- Locate your CKAN virtual environment (pyenv) in your filesystem. It is usually in a directory similar to this: /var/lib/ckan/INSTANCE_NAME/pyenv
If it is not here, to get the definitive answer, check your CKAN Apache configuration (/etc/apache2/sites-enabled) for your WSGIScriptAlias (e.g. /var/lib/ckan/colorado/wsgi.py) which has an execfile instruction. The first parameter is the pyenv directory plus /bin/activate_this.py. e.g. /var/lib/ckan/colorado/pyenv/bin/activate_this.py means the pyenv dir is: /var/lib/ckan/colorado/pyenv.
- Install the extension package code into your pyenv using pip.
For example, to install the Disqus extension, which allows users to comment on datasets (replacing “INSTANCE_NAME” with the name of your CKAN instance):sudo -u ckanINSTANCE_NAME /var/lib/ckan/INSTANCE_NAME/pyenv/bin/pip install -E /var/lib/ckan/INSTANCE_NAME/pyenv -e git+https://github.com/okfn/ckanext-disqus.git#egg=ckanext-disqus --log=/tmp/pip-log.txt
Prefix the source URL with the repo type (hg+ for Mercurial, git+ for Git).
The dependency you’ve installed will appear in the src/ directory under your Python environment.
Now the extension is installed, so now you can enable it.
Enabling an Extension¶
Add the names of the extension’s plugins to the CKAN config file in the ‘[app:main]’ section under ‘ckan.plugins’. e.g.:
[app:main] ckan.plugins = disqus
If your extension implements multiple different plugin interfaces, separate them with spaces:
ckan.plugins = disqus amqp myplugin
Finding out the name of an extension’s plugins: this information should usually be provided in the extension’s documentation, but you can also find this information in the plugin’s setup.py file under [ckan.plugins].
To have this configuration change take effect it may be necessary to restart WSGI, which usually means restarting Apache:
sudo /etc/init.d/apache2 restart
Your extension should now be enabled. You can disable it at any time by removing it from the list of ckan.plugins in the config file.
Enabling an Extension with Background Tasks¶
Some extensions need to run tasks in the background. In order to do this we use celery as a job queue. Examples of these types of extensions are:
- ckanext-webstorer: Put resources that are tabular into the webstore i.e give tabular data a restful api.
- ckanext-archiver: Archives resources so that ckan holds a copy of them i.e caches them.
The above steps needs to be followed for these, but also:
The celery daemon needs to be started. This can be done as simply as:
This only works if you have a development.ini file in ckan root.
In production the daemon should be run with a different ini file and be run as an init script. The simplest way to do this is to install supervisor:
apt-get install supervisor
Using this file as a template and copy to /etc/supservisor/conf.d:
Also you can run:
paster celeryd --config=/path/to/file.ini