Skip to main content
01 / cgctl

cgctl

Every cgctl command, its options, the configuration variables and the exit codes.

Type
Reference
Needs
An API token, or an account's email and password
Version
unreleased
Last verified
Unverified

cgctl is a thin client of the panel's API, made for scripts. Every command becomes a single API request; the API's JSON answer goes, indented, to standard output. To get started see API tokens and cgctl.

Syntax​

cgctl [--wait|-w] [--timeout <duration>] <command> [arguments]
OptionEffect
--wait, -wWhen the answer names a task, follows it to the end (see below).
--timeout <duration>How long to wait with --wait, as 30m, 2h. Default 1h.
--End of the options: what follows is the command.
-v, --version, versionPrints cgctl <version> and exits with 0, without reading the configuration.
-h, --help, helpPrints the usage and exits with 2. Also with no command.

Options may stand anywhere on the line. Arguments that are IDs must be positive integers.

Commands​

Sites​

CommandRequestWhat it does
cgctl sites listGET /api/sitesLists the sites.
cgctl sites create <domain> <type> [flags-json] [database options] [--json]POST /api/sitesCreates a site and prints its summary (see below). <type> is wordpress, woocommerce, static, php, laravel or proxy. flags-json is a JSON object with the other creation fields; domain and type come from the arguments.
cgctl sites delete <site-id>DELETE /api/sites/<id>Deletes a site.
cgctl cert issue <site-id>POST /api/sites/<id>/certificateRequests the site's certificate.
cgctl purge <site-id> [url ...]POST /api/sites/<id>/purgePurges the page cache: only the given URLs, or the whole site without URLs.
cgctl warm <site-id>POST /api/sites/<id>/warmWarms the site's cache.

For example, a WordPress site:

bash
cgctl --wait sites create example.com wordpress \
'{"admin_email": "you@example.com", "admin_user": "admin", "admin_password": "<at least 12 characters>"}'

Create a site​

OptionEffect
--with-databaseAlso creates a database for a php or static site (create_database: true). WordPress, WooCommerce and Laravel always have one; a proxy never.
--db-name <name>The primary database's name. Without it, site_<id>.
--db-user <name>Its user's name. Without it, site_<id>.
--db-password-stdinReads the database password from one line of standard input (at most 4 KiB; empty is an error).
--db-password-file <file>Reads the password from a file, without its trailing newline.
--db-password <password>The password on the command line. It works, but prints on standard error cgctl: warning: --db-password puts the password where ps and the shell history show it; use --db-password-stdin or --db-password-file.
--jsonPrints the API's JSON answer instead of the summary.

Without a password, the panel generates one. The options also take the form --option=value, and win over the same fields in flags-json. An unknown option, an option without its value, two of the password options together, an unreadable file or more than three positional arguments is a usage error (exit 2). The names and the password follow the database rules.

The summary, in plain text: the site and its state (Being created: task <id>, or with --wait Created.), then the URL and the panel link, WordPress's admin URL and user, the database's host, port, socket, name, user and password, and SFTP (off on a new site). It ends with a reminder that the password is shown only now: the API's answer is the only place it appears.

bash
cgctl --wait sites create shop.example.com laravel \
--db-name shop --db-user shop_app --db-password-file /root/shop-db.pass

Staging and releases​

CommandRequestWhat it does
cgctl staging create <site-id>POST /api/sites/<id>/stagingCreates the staging copy.
cgctl safe-push <site-id> [path ...]POST /api/sites/<id>/safe-pushBrings staging to production with Safe Push. The path arguments are the URL paths Performance Guard measures (for example / and /shop/).
cgctl deploy <site-id> <folder>POST /api/sites/<id>/deploymentsPublishes a release from a folder inside the site (source_dir).
cgctl rollback <site-id>POST /api/sites/<id>/rollbackGoes back to the previous release.

Backups and database​

CommandRequestWhat it does
cgctl backup run <site-id>POST /api/sites/<id>/backupsTakes a backup now.
cgctl backup verify <backup-id>POST /api/backups/<id>/verifyRuns a restore test of the backup.
cgctl backup restore <backup-id> <domain> [full|files|database]POST /api/backups/<id>/restoreRestores the backup. <domain> is the confirmation and must be the site's domain; the default mode is full.
cgctl database list <site-id>GET /api/sites/<id>/databasesThe site's databases, with sizes and tables, and the database users with their privileges.
cgctl database create <site-id> <name>POST /api/sites/<id>/databasesCreates a database of the site.
cgctl database user-create <site-id> <name> [database:all|read ...]POST /api/sites/<id>/database-usersCreates a database user with the given privileges; the generated password appears once.
cgctl database import <site-id> <domain> <file.sql> [database]POST /api/sites/<id>/database/importImports a SQL file, into the primary database or the one named. The path is relative to the site's folder; <domain> is the confirmation. A rollback point is saved first.
cgctl cron run <cron-id>POST /api/cron/<id>/runRuns a scheduled task now.

Server​

CommandRequestWhat it does
cgctl statusGET /api/system/statusThe server's status: CPU, memory, disk, main services.
cgctl driftGET /api/system/driftManaged files changed outside the panel.
cgctl tasksGET /api/tasksThe latest 100 tasks.
cgctl task <task-id>GET /api/tasks/<id>One task.
cgctl auditGET /api/auditThe latest 200 rows of the audit log.
cgctl settings getGET /api/settingsThe panel's settings.
cgctl settings set <key> <value>PUT /api/settingsChanges one setting.

API tokens​

These commands always sign in with email and password (CLOUDGROUND_EMAIL, CLOUDGROUND_PASSWORD and, with 2FA, CLOUDGROUND_TOTP): the API does not take a token to manage tokens.

CommandRequestWhat it does
cgctl tokens listGET /api/tokensLists the tokens.
cgctl tokens create <name> [days]POST /api/tokensCreates a token; days from 0 (never) to 365. The token is shown once.
cgctl tokens revoke <token-id>DELETE /api/tokens/<id>Revokes a token.

On the server​

These commands run as root on the server and do not talk to the panel.

CommandWhat it does
cgctl install [--plan] [--from <dir> | --release <dir>] [--skip-packages] [--container]Installs CloudGround, or repairs a server running the same release (another release goes in with cgctl update); --plan shows what would change without changing anything. It is the command install.sh runs.
cgctl doctor [--skip-packages] [--container]Checks every installation step and reports what does not match; exits with 1 when it finds differences, otherwise prints no drift.
cgctl update [--to <vX.Y.Z>] [--channel stable|beta] [--check] [--timeout <duration>]Updates CloudGround to a newer signed release, with a snapshot and an automatic rollback, like the panel's Update now; --check only says what would be installed. See update CloudGround.
cgctl uninstall [--plan] [--yes] [--remove-sites [--confirm <hostname>]] [--purge-packages]Removes CloudGround from the server, keeping the sites and their databases unless --remove-sites; --plan lists every action without changing anything. See uninstall CloudGround.
cgctl release verify <dir> [file ...]Checks a downloaded release against the signing keys built into cgctl; needs neither the panel nor a token.

Authentication​

  1. With a token (CLOUDGROUND_TOKEN or CLOUDGROUND_TOKEN_FILE), every request carries Authorization: Bearer <token>.
  2. Without a token, CLOUDGROUND_EMAIL and CLOUDGROUND_PASSWORD (and CLOUDGROUND_TOTP) sign in once for the command, on the unix:// socket too.
  3. With neither, cgctl exits with 1 and explains how to get a token.

Configuration​

cgctl reads, from weakest to strongest: the defaults, the file /etc/cloudground/cgctl.env (or the file in CLOUDGROUND_CONFIG), the environment. The file has one KEY=value line per variable; blank lines and lines starting with # or ; are ignored. A file the user cannot read is ignored.

VariableDefaultValue
CLOUDGROUND_URLunix:///run/cloudground/api.sockunix://<absolute path>, https://host[:port], or http:// to a local address only.
CLOUDGROUND_TOKEN—A token: cgt_ followed by 43 base64url characters.
CLOUDGROUND_TOKEN_FILE—A file that holds the token.
CLOUDGROUND_INSECUREoff1 skips certificate verification to a non-local address.
CLOUDGROUND_EMAIL, CLOUDGROUND_PASSWORD, CLOUDGROUND_TOTP—Password sign-in, without a token.
CLOUDGROUND_CONFIG—Another file instead of /etc/cloudground/cgctl.env.

Token and token file are one setting: the environment beats the file, and within one source the token beats the token file. Switches take 1 (on) or empty and 0 (off); other values are an error. Every configuration error names the variable and where it came from.

With https:// cgctl verifies the certificate, except to a local address or with CLOUDGROUND_INSECURE=1. cgctl uses no proxy.

Output and errors​

The API's answer goes to standard output, as indented JSON; sites create prints its summary instead. Errors go to standard error as cgctl: HTTP <status>: <the API's error>.

Waiting for a task​

With --wait, when the answer names a task, cgctl asks GET /api/tasks/<id> every second and prints a progress line to standard error at every change. It stops when the status is final: succeeded is success; failed, cancelled or any status other than pending, queued and running is failure. The final task goes to standard output.

When the panel does not answer while cgctl waits (for example because it is restarting), cgctl tries again; the answers 401, 403 and 404 end the wait as a failure. Without a task in the answer, --wait changes nothing.

Exit codes​

CodeMeaning
0The request succeeded and, with --wait, so did the task.
1The API refused the request, could not be reached, or the task failed.
2Usage or configuration error.
3With --wait, --timeout ran out with the task still running.

Next step​

For what cgctl does not cover, use the API directly.

Was this page useful?
Edit this page ↗