Command-line

The zotonic command runs a number of utility commands which all operate on a Zotonic instance.

The command determines where the Zotonic base dir is by looking at its path; it always assumes that its zotonic basedir is one dir up from where the binary itself is.

Shell environment variables

See environment variables for the environment variables that can be set when using the Zotonic command line tools.

Commands

Currently, the following subcommands are implemented:

zotonic start
Start the background Zotonic server instance.
zotonic stop
Stop the Zotonic server instance.
zotonic debug
Launch the Zotonic server interactively and get an EShell on the running instance. See Command-line shell. The start.sh command in the root folder is a shortcut for this command. The Zotonic instance can be stopped with twice ctrl-C.
zotonic start_nodaemon
Start the Zotonic server instance as a foreground process, but without the interactive EShell. This is useful when running Zotonic in a Docker container or other process.
zotonic restart
Restart the Zotonic server instance.
zotonic wait [timeout]
Wait timeout seconds (defaults to 30 seconds) for Zotonic to be started, then return.
zotonic shell
Get an EShell on the running Zotonic instance. See Command-line shell.
zotonic status
List all sites on the running Zotonic instance and their current status.
zotonic configfiles
List all config files used for Zotonic.
zotonic configtest
Read all config files and check if they are syntactically correct.
zotonic config [all | zotonic | erlang]
Prints the configuration as defined in the configuration files. Taking into account all shell environment variables. Defaults to showing the zotonic config.
zotonic rpc
Send an RPC request to the running Zotonic instance. Example: zotonic rpc “zotonic ping”
zotonic addsite [options] <site_name>
Creates a new site with [site_name] as its name. See The addsite command for a full overview of this command.
zotonic startsite <site_name>
Start the site with name [site_name].
zotonic stopsite <site_name>
Stop the site with name [site_name].
zotonic restartsite <site_name>
Restart the site with name [site_name].
zotonic sitedir <site_name>
Get the absolute path for a site based on [site_name]
zotonic siteconfig <site_name>
Prints the configuration of site [site_name] as defined in its configuration files.
zotonic siteconfigfiles <site_name>
List all configuration files for of site [site_name]
zotonic open [sitename]
Open the site in Chrome, or when on macOS, in the default browser.
zotonic chrome [options] [switches] [sitename]
Open the site in Chrome. The switches are options to Chrome.
zotonic chromium [options] [switches] [sitename]
Open the site in Chromium. The switches are options to Chromium.
zotonic dispatch <url>

Dispatch an URL. Finds the site matching the hostname and shows the dispatch information for the path. Example:

bin/zotonic dispatch https://mysite.test:8443/en/page/1/foobar
zotonic dispatch <site_name> [detail]
List all dispatch rules for a site. Add the detail option to show all controller options for each dispatch rule.
zotonic dispatch <site_name> <path>

Show the dispatch information for a specific path and site. Example:

bin/zotonic dispatch mysite /en/page/1/foobar
zotonic etop
Show the processes that consume the most CPU. Stop with twice ctrl-C.
zotonic logtail [ console | error | crash ]
Show the last 50 entries of the console.log, error.log or crash.log file. Defaults to the console log.
zotonic flush
Flush the caches of all sites.
zotonic flush <site_name>
Flush the caches of the site with name [site_name].
zotonic createdb <site_name>

Create a database called zotonic_[site_name] with the basic setup in place to host a Zotonic datastore. This script will likely need to be run as postgres unless zotonic has been granted CREATEDB in postgres as follows:

ALTER ROLE zotonic WITH CREATEDB
zotonic compilefile <path/to/filename.erl>
Compiles and reloads a single Erlang module within the Zotonic folder. This runs very fast and works very well on a save-hook of your text editor. In Emacs, it would be called like this:
(add-hook 'erlang-mode-hook
      '(lambda ()
         (add-hook 'after-save-hook '
                   (lambda ()
                     (call-process "/path/to/your/bin/zotonic" nil "*scratch*" nil "compilefile" buffer-file-name)
                     )
                   )
         ))
zotonic compile
Compiles all the Zotonic Erlang source files, modules and sites, including those in the user directory (see Global configuration).
zotonic update
Like zotonic compile but also flushes caches and rescans all modules and sites for new templates etc.
zotonic load
Reloads all (changed) beam files from disk.
zotonic runtests
Starts Zotonic in the foreground and runs all (enunit) tests. Stops after completion of the tests.
zotonic sitetest <site_name>
Runs all tests for the given site. Zotonic must be running. See Testing sites.

Edit on GitHub

Configuration Reference

Referred by

Testing sites

It is possible to create end-to-end integration tests for Zotonic websites. Tests like these are called sitetests .

Automatic startup on system boot

Once you have Zotonic running, you want to make sure that it automatically starts up when the server reboots, so that…

The addsite command

Adding a site to Zotonic is done through the zotonic shell command. It syntax is like this:

Directory structure

Zotonic is a set of regular OTP applications. These can be found in the repository’s apps/ directory: