Chapter 10. Managing databases with the command-line assistant daemon
To store information and provide access to your history database, the command-line assistant daemon (clad) uses an unencrypted SQLite database by default. You can install and connect to a different database back end, such as PostgreSQL or MySQL.
clad does not include these databases by default to avoid adding unwanted dependencies.
10.1. Changing the default database in the configuration file Copy linkLink copied to clipboard!
You can store and access your command-line assistant history by using the default unencrypted SQLite database.
Prerequisites
- You have installed the command-line assistant.
Procedure
Install the database of your choice:
To install MySQL, enter:
# dnf install python3-PyMySQLTo install PostgreSQL, enter:
# dnf install python3-psycopg2
-
Access your database configuration file at
/etc/xdg/command-line-assistant/config.toml. Locate and comment out the default configuration. For example:
[database] # type = "sqlite" # connection_string = "/var/lib/command-line-assistant/history.db"Configure the database of your choice. The following information is also available in
/etc/xdg/command-line-assistant/config.toml.-
Set the database type, where
<db_type>can bemysqlorpostgresql. Set the database details.
type = <db_type> host = "<hostname_or_ip_address>" port = "5432" username = "<database_user_name>" password = "<password>" database = "<database_name>"
-
Set the database type, where
After changing the database type, restart the
claddaemon to apply the changes:$ sudo systemctl restart clad
10.2. Connecting to your database by using the stored systemd-creds passwords Copy linkLink copied to clipboard!
Use the systemd-creds tool to securely store your encrypted credentials. Connect to PostgreSQL, SQLite, or MySQL by using these stored secrets.
Prerequisites
- The command-line assistant.
- Access to the database configuration file.
Procedure
-
Access your database configuration file at
/etc/xdg/command-line-assistant/config.toml. Remove the
usernameandpasswordparameters from the[database]section, for example:[database] type = "postgresql" host = "localhost" port = "5432" database = "history"NoteIf you leave the username and password in the configuration file, these credentials take precedence over the
systemd-credstool.Generate encrypted credentials for your username or password. The following example uses
systemd-ask-passwordcommands. The name must follow the schema ofdatabase-usernameanddatabase-password, otherwise,claddoes not load the credentials properly.To generate an encrypted username, run the following command:
$ systemd-ask-password -n | ( echo "[Service]" && systemd-creds encrypt --name=<database_username> -p - - ) >/etc/systemd/system/clad.service.d/<username>.confTo generate an encrypted password, run the following command:
$ systemd-ask-password -n | ( echo "[Service]" && systemd-creds encrypt --name=<database_password> -p - - ) >/etc/systemd/system/clad.service.d/<password>.conf
After updating the database credentials, reload
systemdand restart thecladdaemon to apply the changes:$ sudo systemctl daemon-reload $ sudo systemctl restart clad