Ckan basic configuration, seeding test data, and uwsgi

Aliases and sysadmin account

Once you have ckan installed properly, it is time to do some basic configuration. In order to do this, the first thing is to add a sysadmin account for ckan. This can be done by running the following commands.

To make it easier for me, I have created a permanent alias for ckan activation. I have edited my .bashrc file, and at the very end, I have added the following line:

alias activate=". /usr/lib/ckan/default/bin/activate"

Now, source this file to update the current shell session and see if it works.

ubuntu@ip-172-26-6-221:~$ source ~/.bashrc
ubuntu@ip-172-26-6-221:~$ activate
(default) ubuntu@ip-172-26-6-221:~$ cd /usr/lib/ckan/default/src/ckan/
(default) ubuntu@ip-172-26-6-221:/usr/lib/ckan/default/src/ckan$ ckan -c /etc/ckan/default/ckan.ini sysadmin add masud email=masud.khokhar@gmail.com name=masud
2020-06-16 06:29:50,528 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 06:29:50,528 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 06:29:50,573 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 06:29:50,812 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
User "masud" not found
Create new user: masud? [Y/n]: Y
Password : 
Repeat for confirmation: 
Successfully created user: masud
Added masud as sysadmin
(default) ubuntu@ip-172-26-6-221:/usr/lib/ckan/default/src/ckan$

Let’s get rid of the need to add the -c path_to_ckan_ini_file for every command. Update your .bashrc file to add the following:

export CKAN_INI="/etc/ckan/default/ckan.ini"

ubuntu@ip-172-26-6-221:~$ source ~/.bashrc

Seeding some test data

Let’s create some test data in the system. Unfortunately, the documentation is again outdated here for the latest version. The actual commands that you need are provided below. With the latest version of ckan, we have multiple options to populate test data.

(default) ubuntu@ip-172-26-6-221:~$ ckan seed
2020-06-16 07:54:46,206 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 07:54:46,206 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 07:54:46,252 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 07:54:46,493 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
Usage: ckan seed [OPTIONS] COMMAND [ARGS]...

  Create test data in the database.

  Tests can also delete the created objects easily with the delete() method.

Options:
  --help  Show this message and exit.

Commands:
  basic         Annakarenina and warandpeace.
  family        Package relationships data.
  gov           Government style data.
  hierarchy     Hierarchy of groups.
  search        Realistic data to test search.
  translations  Test translations of terms.
  user          Create a user "tester" with api key "tester".
  vocabs        Some test vocabularies.
(default) ubuntu@ip-172-26-6-221:~$ 

You can add multiple forms of data, e.g.

(default) ubuntu@ip-172-26-6-221:~$ ckan seed gov
2020-06-16 07:55:48,267 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 07:55:48,268 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 07:55:48,314 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 07:55:48,552 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
(default) ubuntu@ip-172-26-6-221:~$ ckan seed basic
2020-06-16 07:56:20,616 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 07:56:20,616 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 07:56:20,655 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 07:56:20,893 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
(default) ubuntu@ip-172-26-6-221:~$ ckan seed family
2020-06-16 07:56:56,626 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 07:56:56,626 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 07:56:56,666 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 07:56:56,901 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates

You can also clean all the test data by running the following commands. If you do run the clean command, it will drop all database tables in your ckan_default database. This means you will remove all data, including any users you have created in the system. You will need to recreate the sysadmin user.

(default) ubuntu@ip-172-26-6-221:/usr/lib/ckan/default/src/ckan$ ckan db clean
2020-06-16 09:00:56,704 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 09:00:56,704 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 09:00:56,747 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 09:00:56,988 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
This will delete all of your data!
Do you want to continue? [y/N]: y
2020-06-16 09:00:59,521 INFO  [ckan.model] Database tables dropped
Cleaning DB: SUCCESS
(default) ubuntu@ip-172-26-6-221:/usr/lib/ckan/default/src/ckan$ ckan db init
2020-06-16 09:01:03,861 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 09:01:03,861 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 09:01:03,900 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 09:01:04,124 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 09:01:04,393 INFO  [ckan.cli.db] Initialize the Database
2020-06-16 09:01:06,003 INFO  [ckan.model] CKAN database version upgraded: base -> 19ddad52b500 (head)
2020-06-16 09:01:06,003 INFO  [ckan.model] Database initialised
Initialising DB: SUCCESS
(default) ubuntu@ip-172-26-6-221:/usr/lib/ckan/default/src/ckan$ ckan sysadmin add masud email=masud.khokhar@gmail.com name=masud
2020-06-16 09:01:44,345 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 09:01:44,345 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 09:01:44,385 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 09:01:44,737 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
User "masud" not found
Create new user: masud? [Y/n]: Y
Password : 
Repeat for confirmation: 
Successfully created user: masud
Added masud as sysadmin
(default) ubuntu@ip-172-26-6-221:/usr/lib/ckan/default/src/ckan$ 

Sometimes the search indexes would remain intact, as a consequence of which, you will keep seeing datasets and being able to search for them using keywords, but when you click on a title, it would give you Error 404. Easiest option here is to rebuild search index.

(default) ubuntu@ip-172-26-6-221:~$ ckan search-index rebuild
2020-06-16 11:56:06,542 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2020-06-16 11:56:06,543 INFO  [ckan.config.environment] Loading static files from public
2020-06-16 11:56:06,590 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 11:56:06,835 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2020-06-16 11:56:07,116 INFO  [ckan.lib.search] Rebuilding search index...
2020-06-16 11:56:07,119 INFO  [ckan.lib.search] Rebuilding the whole index...
2020-06-16 11:56:07,306 INFO  [ckan.lib.search] Finished rebuilding search index.
2020-06-16 11:56:07,320 INFO  [ckan.lib.search] Commited pending changes on the search index
(default) ubuntu@ip-172-26-6-221:~$ 

Changing ckan configuration settings

At this point, I wanted to check some ckan settings. Initially, I want to disable the web-based user registration functionality. This is easy enough as there are settings for this in the ckan.ini file.

ckan.auth.create_user_via_api = False
ckan.auth.create_user_via_web = False

However, after changing these and restarting Nginx, nothing was changing on the actual webpage. This was really frustrating. After a day worth of digging, I finally realised that restarting the web server as per the documentation is not enough if you are using Nginx with uwsgi server. You will also need to reload uwsgi server. This really frustrated me and I hope this might save you some time if you come across this blog post.

In order to gracefully reload uwsgi configuration, do the following. Identify the pid of the uwsgi server – for me it is present at /tmp/ckan-uwsgi.pid

(default) ubuntu@ip-172-26-6-221:/etc/ckan/default$ uwsgi --reload /tmp/ckan-uwsgi.pid 

Now that we have done some data seeding, let’s have a quick look at some basic configuration settings of ckan through a sysadmin account.

You can access these settings at: http://masudklabs.com/ckan-admin/config (replace masudklabs.com with your domain name). I have gone with the third layout option (Search, introductory area, and stats), a site logo, a new site title, and the Green style. I have also revised intro and about text. This is how the home page looks like for me.

This image has an empty alt attribute; its file name is Screenshot-2020-06-21-at-01.10.30.png

In the next post, I will be looking at customising the layout of the home page and exploring theming in more detail.

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Site Footer

Sliding Sidebar

Blog of Masud Khokhar

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Currently Reading