In this article, we will walk through a series of common Linux commands used for managing CKAN instances on an Ubuntu server with Nginx. We'll cover a variety of actions, explaining each command and its purpose. Whether you’re maintaining a CKAN instance, performing updates, or troubleshooting, this guide will help you understand the underlying operations.
The run through
System status and package updates
1. Checking system uptime
- `uptime`: This command displays how long the system has been running, how many users are currently logged in, and the system’s load average over 1, 5, and 15 minutes.
2. Updating the system
- `sudo apt update && sudo apt upgrade -y`: This command first refreshes the package list (`apt update`), and then upgrades all installed packages to their latest versions (`apt upgrade -y`), applying updates without any confirmation prompts.
Navigating history and user information
3. Accessing command history
- `hstr`: This interactive tool allows you to search through and reuse your command history efficiently, making it easier to find previously used commands.
4. Viewing operating system information
- `cat /etc/os-release`: Displays detailed information about the operating system, including the distribution name and version.
5. Finding the current directory
- `pwd`: Prints the path of the current working directory.
6. Viewing user details
- `compgen -u`: Lists all users on the system.
- `getent passwd`: Displays user account information stored in the system’s `/etc/passwd` file.
Managing CKAN virtual environments and directories
7. Activating CKAN virtual environment
- `. /usr/lib/ckan/default/bin/activate`: Activates the CKAN virtual environment, preparing it for any CKAN-related operations.
8. Navigating CKAN directories
- `cd /usr/lib/ckan/default/src/ckan`: Changes the current directory to the CKAN source code directory.
- `ll`: Lists files in the current directory in a detailed format, including file permissions, sizes, and timestamps.
Database and file management
9. Backing up the CKAN database
- `sudo -u postgres pg_dump --format=custom -d ckan_default > ~/pre.211.ckan.dump`: Runs a backup of the CKAN database (`ckan_default`) in a custom format, saving the file to the home directory.
10. Listing files in the home directory
- `ls ~`: Lists files in the home directory.
- `ls -al ~`: Lists all files, including hidden files, with detailed file information.
Exporting datasets with CKAN API
11. Dumping datasets using CKAN API
- `ckanapi dump datasets -c /etc/ckan/default/ckan.ini -O ~/pre.211.my_datasets.jsonl`: Dumps all datasets into a JSON Lines format file using CKAN's API, with the configuration specified in `ckan.ini`.
System maintenance and downloads
12. Downloading CKAN package
- `wget https://packaging.ckan.org/python-ckan_2.11-jammy_amd64.deb`: Downloads the CKAN 2.11 package for Ubuntu Jammy.
13. Rebooting the system
- `sudo reboot now`: Reboots the system immediately.
14. Installing CKAN package
- `sudo dpkg -i python-ckan_2.11-jammy_amd64.deb`: Installs the downloaded CKAN package using the Debian package manager.
Upgrading and validating CKAN database
15. Upgrading the CKAN database
- `ckan -c /etc/ckan/default/ckan.ini db upgrade`: Upgrades the CKAN database schema using the specified configuration file.
- `sudo ckan -c /etc/ckan/default/ckan.ini db upgrade`: Same as above but executed with superuser privileges.
16. Validating CKAN configuration
- `sudo ckan --config /etc/ckan/default/ckan.ini config validate`: Validates the CKAN configuration file for correctness.
Python utility commands
17. Generating secure tokens
- `python -c "import secrets; print(secrets.token_urlsafe(20))"`: Generates a secure, URL-safe token using Python’s `secrets` module, and prints it.
- `python3 -c "import secrets; print(secrets.token_urlsafe(20))"`: Same as above but with Python 3.
Editing and managing configuration files
18. Editing CKAN configuration
- `sudo nano /etc/ckan/default/ckan.ini`: Opens the CKAN configuration file in `nano` (a terminal-based text editor) with superuser permissions for editing.
19. Backing up configuration files
- `sudo cp /etc/ckan/default/ckan.ini ~/pre.211.ckan.ini`: Copies the CKAN configuration file to the home directory as a backup.
20. Generating a new CKAN configuration
- `sudo ckan generate config`: Automatically generates a new CKAN configuration file based on the system setup.
Additional administrative tasks
21. Listing CKAN users
- `sudo ckan user list`: Retrieves a list of users in the CKAN instance.
22. Rebooting the server again
- `sudo reboot now`: Immediately reboots the server.
23. Checking Python version
- `python3 --version`: Prints the installed version of Python 3.
The wrap
This article has provided an overview of various commands essential for managing a CKAN instance on Ubuntu with Nginx. From updating the system and managing users to performing database backups and validating CKAN configurations, these commands ensure smooth operation and troubleshooting for any CKAN administrator.
Steps
Here's a breakdown of the bash commands you listed and what each action is performing:
1. `uptime` – Displays how long the system has been running, the number of logged-in users, and system load averages.
2. `sudo apt update && sudo apt upgrade -y` – Updates the package list and then upgrades installed packages automatically without prompting.
3. `hstr` – A command-line utility to view and reuse command history (similar to `history`, but more interactive).
4. `cat /etc/os-release` – Displays the operating system release information.
5. `pwd` – Prints the current working directory.
6. `w` – Displays information about the users currently logged in and their processes.
7. `compgen -u` – Lists all the users on the system.
8. `getent passwd` – Displays the system’s user account information from the `/etc/passwd` file.
9. `history` – Displays the command history.
10. `history | more` – Displays the command history one screen at a time (useful for large history).
11. `hstr` – As mentioned, opens the command history viewer.
12. `. /usr/lib/ckan/default/bin/activate` – Activates a Python virtual environment (used for CKAN).
13. `cd /usr/lib/ckan/default/src/ckan` – Changes the directory to the CKAN source code directory.
14. `ll` – Lists the files in the current directory with details like file permissions, sizes, and modification times (equivalent to `ls -l`).
15. `sudo -u postgres pg_dump --format=custom -d ckan_default > ~/pre.211.ckan.dump` – As the `postgres` user, dumps the CKAN database (`ckan_default`) to a file in a custom format.
16. `ls ~` – Lists the contents of the home directory.
17. `ls -al ~` – Lists the contents of the home directory in long format, showing hidden files and details.
18. `ckanapi dump datasets -c /etc/ckan/default/ckan.ini -O ~/pre.211.my_datasets.jsonl` – Dumps CKAN datasets to a JSONL file using the CKAN API, with the configuration file specified.
19. `ckanapi dump datasets -c /etc/ckan/default/ckan.ini -O pre.211.my_datasets.jsonl` – Same as above but the file is saved to the current directory.
20. `cd ~` – Changes to the home directory.
21. `pwd` – Prints the current working directory again (should now be the home directory).
22. `wget https://packaging.ckan.org/python-ckan_2.11-jammy_amd64.deb` – Downloads the CKAN 2.11 package for Ubuntu Jammy.
23. `exit` – Exits the current shell session.
24. `sudo reboot now` – Immediately reboots the system.
25. `sudo dpkg -i python-ckan_2.11-jammy_amd64.deb` – Installs the downloaded CKAN package using the Debian package manager.
26. `ckan -c /etc/ckan/default/ckan.ini db upgrade` – Runs a database upgrade for CKAN using the specified configuration file.
27. `sudo ckan -c /etc/ckan/default/ckan.ini db upgrade` – Same as above but with `sudo`, running the command as the root user.
28. `python -v` – Starts Python in verbose mode (though `-v` is rarely used alone).
29. `python3 -v` – Same as above, but for Python 3.
30. `python -c "import secrets; print(secrets.token_urlsafe(20))"` – Executes a Python one-liner that generates and prints a URL-safe token of 20 characters.
31. `python3 -c "import secrets; print(secrets.token_urlsafe(20))"` – Same as above but with Python 3.
32. `sudo nano /etc/ckan/default/ckan.ini` – Opens the CKAN configuration file in the `nano` text editor with root privileges.
33. `sudo cp /etc/ckan/default/ckan.ini ~/pre.211.ckan.ini` – Copies the CKAN configuration file to the home directory as a backup.
34. `cat ~/pre.211.ckan.ini` – Displays the contents of the CKAN configuration backup file.
35. `cat ~/pre.211.ckan.ini | more` – Displays the CKAN configuration file one screen at a time (useful for long files).
36. `sudo ckan generate config` – Generates a CKAN configuration file.
37. `sudo ckan user list` – Lists CKAN users.
38. `sudo cp /etc/ckan/default/ckan.ini ~/post.211.ckan.ini` – Copies the CKAN configuration file to the home directory as a post-backup after changes.
39. `sudo nano ~/clean.211.ckan.ini` – Opens the cleaned CKAN configuration file in `nano` for editing.
40. `sudo reboot now` – Reboots the system again.
41. `python3 --version` – Prints the installed version of Python 3.