Command Line Interface (CLI)¶
From CKAN 2.9 onwards the CKAN configuration file is named ‘ckan.ini’. Previous names: ‘production.ini’ and ‘development.ini’ (plus others) may also still appear in documentation and the software. These legacy names will eventually be phased out.
From CKAN 2.9 onwards, the
paster command used for common CKAN
administration tasks has been replaced with the
If you have trouble running ‘ckan’ CLI commands, see Troubleshooting ckan Commands below.
Once you activate your CKAN virtualenv the “ckan” command is available from within any location within the host environment.
To run a ckan command without activating the virtualenv first, you have to give the full path the ckan script within the virtualenv, for example:
/usr/lib/ckan/default/bin/ckan -c /etc/ckan/default/ckan.ini user list
In the example commands below, we assume you’re running the commands with your virtualenv activated and from your ckan directory.
The general form of a CKAN
ckan command is:
ckan --config=/etc/ckan/default/ckan.ini command
The `` –config`` option tells CKAN where to find your config file, which it
reads for example to know which database it should use. As you’ll see in the
examples below, this option can be given as
-c for short.
The config file (ckan.ini) will generally be located in the
/etc/ckan/default/ directory however it can be located in any directory on
the host machine
command should be replaced with the name of the CKAN command that you wish to execute. Most commands have their own subcommands and options.
You may also specify the location of your config file using the CKAN_INI environment variable. You will no longer need to use –config= or -c to tell ckan where the config file is:
You can run the ckan command in the same directory as the CKAN config file when the config file is named ‘ckan.ini’. You will not be required to use –config or -c in this case. For backwards compatibility, the config file can be also named ‘development.ini’, but this usage is deprecated and will be phased out in a future CKAN release.
cd /usr/lib/ckan/default/src/ckan; ckan command
Commands and Subcommands
ckan -c /etc/ckan/default/ckan.ini user list
user is the name of the CKAN command you’re running, and
a subcommand of
For a list of all available commands, see CKAN Commands Reference.
Each command has its own help text, which tells you what subcommands and
options it has (if any). To print out a command’s help text, run the command
--help option, for example:
ckan -c /etc/ckan/default/ckan.ini user --help
Troubleshooting ckan Commands¶
If you receive ‘Permission Denied’ error, try running ckan with sudo.
sudo /usr/lib/ckan/default/bin/ckan -c /etc/ckan/default/ckan.ini db clean
Virtualenv not activated, or not in ckan dir¶
Most errors with ckan commands can be solved by remembering to activate your virtual environment and change to the ckan directory before running the command:
. /usr/lib/ckan/default/bin/activate cd /usr/lib/ckan/default/src/ckan
Error messages such as the following are usually caused by forgetting to do this:
- Command ‘foo’ not known (where foo is the name of the command you tried to run)
- The program ‘ckan’ is currently not installed
- Command not found: ckan
- ImportError: No module named webassets (or other
Running ckan commands provided by extensions¶
If you’re trying to run a CKAN command provided by an extension that you’ve installed and you’re getting an error like Command ‘foo’ not known even though you’ve activated your virtualenv, make sure that you have added the relevant plugin to the ckan.plugins setting in the ini file.
Wrong config file path¶
- AssertionError: Config filename development.ini does not exist
- This means you forgot to give the
-coption to tell CKAN where to find your config file. (CKAN looks for a config file named
development.iniin your current working directory by default.)
- ConfigParser.MissingSectionHeaderError: File contains no section headers
- This happens if the config file that you gave with the
--configoption is badly formatted, or if you gave the wrong filename.
- IOError: [Errno 2] No such file or directory: ‘…’
- This means you gave the wrong path to the
-coption (you gave a path to a file that doesn’t exist).
ckan Commands Reference¶
The following ckan commands are supported by CKAN:
|config-tool||Tool for editing options in a CKAN config file|
|datapusher||Perform commands in the datapusher.|
|datastore||Perform commands to set up the datastore.|
|db||Perform various tasks on the database.|
|generate||Generate empty extension files to expand CKAN|
|jobs||Manage background jobs|
|less||Compile all root less documents into their CSS counterparts|
|notify||Send out modification notifications.|
|plugin-info||Provide info on installed plugins.|
|profile||Code speed profiler.|
|run||Start Development server.|
|search-index||Creates a search index for all datasets|
|seed||Create test data in the database.|
|sysadmin||Gives sysadmin rights to a named user.|
|tracking||Update tracking statistics.|
|translation||Translation helper functions|
|views||Create views on relevant resources|
asset: WebAssets commands¶
ckan asset build - Builds bundles, regardless of whether they are changed or not ckan asset watch - Start a daemon which monitors source files, and rebuilds bundles ckan asset clean - Will clear out the cache, which after a while can grow quite large
config-tool: Tool for editing options in a CKAN config file¶
ckan config-tool --section (-s) - Section of the config file ckan config-tool --edit (-e) - Checks the option already exists in the config file ckan config-tool --file (-f) - Supply an options file to merge in
ckan config-tool /etc/ckan/default/ckan.ini sqlalchemy.url=123 'ckan.site_title=ABC' ckan config-tool /etc/ckan/default/ckan.ini -s server:main -e port=8080 ckan config-tool /etc/ckan/default/ckan.ini -f custom_options.ini
datapusher: Perform commands in the datapusher¶
ckan datapusher resubmit - Resubmit udated datastore resources ckan datapusher submit - Submits resources from package
dataset: Manage datasets¶
ckan dataset DATASET_NAME|ID - shows dataset properties ckan dataset show DATASET_NAME|ID - shows dataset properties ckan dataset list - lists datasets ckan dataset delete [DATASET_NAME|ID] - changes dataset state to 'deleted' ckan dataset purge [DATASET_NAME|ID] - removes dataset from db entirely
datastore: Perform commands in the datastore¶
Make sure that the datastore URLs are set properly before you run these commands.
ckan datastore set-permissions - generate SQL for permission configuration ckan datastore dump - dump a datastore resource ckan datastore purge - purge orphaned datastore resources
db: Manage databases¶
ckan db clean - Clean the database ckan db downgrade - Downgrade the database ckan db duplicate_emails - Check users email for duplicate ckan db init - Initialize the database ckan db pending-migrations - List all sources with unapplied migrations. ckan db upgrade - Upgrade the database ckan db version - Returns current version of data schema
See Database Management.
generate: Generate empty extension files to expand CKANs¶
ckan generate extension - Create empty extension ckan generate --output-dir (-o) - Location to put the generated template
jobs: Manage background jobs¶
ckan jobs cancel - cancel a specific job. ckan jobs clear - cancel all jobs. ckan jobs list - list jobs. ckan jobs show - show details about a specific job. ckan jobs test - enqueue a test job. ckan jobs worker - start a worker
jobs command can be used to manage Background jobs.
New in version 2.7.
Run a background job worker¶
ckan -c /etc/ckan/default/ckan.ini jobs worker [--burst] [QUEUES]
Starts a worker that fetches job from the job queues and executes them. If no queue names are given then it listens to the default queue. This is equivalent to
ckan -c /etc/ckan/default/ckan.ini jobs worker default
If queue names are given then the worker listens to those queues and only those:
ckan -c /etc/ckan/default/ckan.ini jobs worker my-custom-queue another-special-queue
Hence, if you want the worker to listen to the default queue and some others then you must list the default queue explicitly
ckan -c /etc/ckan/default/ckan.ini jobs worker default my-custom-queue
--burst option is given then the worker will exit as soon as all its
queues are empty. Otherwise it will wait indefinitely until a new job is
enqueued (this is the default).
In a production setting you should use a more robust way of running background workers.
List enqueued jobs¶
ckan -c /etc/ckan/default/ckan.ini jobs list [QUEUES]
Lists the currently enqueued jobs from the given job queues. If no queue names are given then the jobs from all queues are listed.
Show details about a job¶
ckan -c /etc/ckan/default/ckan.ini jobs show ID
Shows details about the enqueued job with the given ID.
Cancel a job¶
ckan -c /etc/ckan/default/ckan.ini jobs cancel ID
Cancels the enqueued job with the given ID. Jobs can only be canceled while they are enqueued. Once a worker has started executing a job it cannot be aborted anymore.
Clear job queues¶
ckan -c /etc/ckan/default/ckan.ini jobs clear [QUEUES]
Cancels all jobs on the given job queues. If no queues are given then all queues are cleared.
less: Compile all root less documents into their CSS counterparts¶
notify: Send out modification notifications¶
ckan notify replay - send out modification signals. In "replay" mode, an update signal is sent for each dataset in the database.
plugin-info: Provide info on installed plugins¶
As the name suggests, this commands shows you the installed plugins (based on the .ini file) , their description, and which interfaces they implement
profile: Code speed profiler¶
Provide a ckan url and it will make the request and record how long each function call took in a file that can be read by runsnakerun.
ckan profile URL
The result is saved in profile.data.search. To view the profile in runsnakerun:
You may need to install the cProfile python module.
run: Start Development server¶
ckan run --host (-h) - Set Host ckan run --port (-p) - Set Port ckan run --disable-reloader (-r) - Use reloader
search-index: Search index commands¶
ckan search-index check - Check search index ckan search-index clear - Clear the search index ckan search-index rebuild - Rebuild search index ckan search-index rebuild-fast - Reindex with multiprocessing ckan search-index show - Show index of a dataset
search-index: Rebuild search index¶
Rebuilds the search index. This is useful to prevent search indexes from getting out of sync with the main database.
ckan -c /etc/ckan/default/ckan.ini search-index rebuild
This default behaviour will refresh the index keeping the existing indexed datasets and rebuild it with all datasets. If you want to rebuild it for only one dataset, you can provide a dataset name
ckan -c /etc/ckan/default/ckan.ini search-index rebuild test-dataset-name
Alternatively, you can use the -o or –only-missing option to only reindex datasets which are not already indexed
ckan -c /etc/ckan/default/ckan.ini search-index rebuild -o
There is also an option available which works like the refresh option but tries to use all processes on the computer to reindex faster
ckan -c /etc/ckan/default/ckan.ini search-index rebuild_fast
There is also an option to clear the whole index first and then rebuild it with all datasets:
ckan -c /etc/ckan/default/ckan.ini search-index rebuild --clear
There are other search related commands, mostly useful for debugging purposes
ckan search-index check - checks for datasets not indexed ckan search-index show DATASET_NAME - shows index of a dataset ckan search-index clear [DATASET_NAME] - clears the search index for the provided dataset or for the whole ckan instance
seed: Create test data in the database¶
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.
ckan -c /etc/ckan/default/ckan.ini seed basic
sysadmin: Give sysadmin rights¶
ckan sysadmin add - convert user into a sysadmin ckan sysadmin list - list sysadmins ckan sysadmin remove - removes user from sysadmins
For example, to make a user called ‘admin’ into a sysadmin
ckan -c /etc/ckan/default/ckan.ini sysadmin add admin
tracking: Update tracking statistics¶
ckan tracking update [start_date] - update tracking stats ckan tracking export FILE [start_date] - export tracking stats to a csv file
translation: Translation helper functions¶
regenerated if necessary when CKAN is started. Hence you usually do not
need to run
ckan translation js manually.
user: Create and manage users¶
Lets you create, remove, list and manage users.
ckan user add - add new user ckan user list - list all users ckan user remove - remove user ckan user setpass - set password for the user ckan user show - show user
For example, to create a new user called ‘admin’
ckan -c /etc/ckan/default/ckan.ini user add admin
To delete the ‘admin’ user
ckan -c /etc/ckan/default/ckan.ini user remove admin
views: Create views on relevant resources¶
ckan views clean - permanently delete views for all types no... ckan views clear - permanently delete all views or the ones with... ckan views create - create views on relevant resources. ckan views --dataset (-d) - Set Dataset ckan views --no-default-filters ckan views --search (-s) - Set Search ckan views --yes (-y)