The zotonic command runs a number of utility commands which all operate on a Zotonic instance.
The zotonic command lives in the bin/ folder of the Zotonic source. Putting this path into your PATH variable makes working with Zotonic a lot easier:
export PATH=$HOME/zotonic/bin:$PATH
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.
Currently, the following subcommands are implemented:
creates a new site called “yoursite” based on the skeleton called “empty”. It has the following options:
| -s <skel> | Skeleton site (‘blog’ or ‘empty’; default: blog) |
| -h <host> | Database host (default: 127.0.0.1) |
| -p <port> | Database port (default: 5432) |
| -u <user> | Database user (default: zotonic) |
| -P <pass> | Database password (default: zotonic) |
| -d <name> | Database name (default: zotonic) |
| -n <schema> | Database schema (default: public) |
| -a <pass> | Admin password (default: admin) |
| -L | Create the site in the current directory instead of in zotonic/priv/sites. |
The “addsite” subcommand checks a file called $HOME/.zotonic-defaults for the default values to these options. This file is a file in bash-syntax which can define the following variables: SKEL, DBHOST, DBPORT, DBUSER, DBPASSWORD, DBDATABASE, DBSCHEMA, ADMINPASSWORD, DO_LINK.
Installs a module from the modules.zotonic.com repository into your Zotonic instance. The module will be checked out using source control (either git or hg) into the priv/modules folder:
~$ zotonic installmodule mod_openid
Getting module index
** Installing mod_openid ...
requesting all changes
adding changesets
adding manifests
adding file changes
added 11 changesets with 21 changes to 15 files
updating to branch default
14 files updated, 0 files merged, 0 files removed, 0 files unresolved
** mod_openid OK
Copy [site_name] and its database content from the [source_server] over SSH and load its content into the filesystem and database of the local machine. You will need to have created the database zotonic_[site_name] for this to work.
Warning: This command will reset the content of the database to the content retrieved from the [source_server]. It does, however, generate and output a restore file in case this was run by accident and explains how to recover.
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
Take a version control snapshot of [site_name] including its database content.
This works differently from mod_backup in that it consistently uses the same filename for the SQL backup to make revision-based full site rollbacks possible.
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)
)
)
))
For archival purposes, the zotonic.sh script that was used before release 0.8 is listed here.
#!/bin/bash
#
# Copyright 2009 Marc Worrell
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
## usage zotonic.sh {debug|start|stop|restart}
##
## Use "debug" to start an interactive shell (highly recommended when installing the db on the first run).
## Use "start" in production. This boots zotonic in an erlang vm with a heart beat process.
##
## The proposed directory structure is:
## /home/zotonic/zotonic.sh -- this script
## /home/zotonic/zotonic/... -- the zotonic code
## /home/zotonic/zotonic/priv/sites/default/... -- your site and uploaded files go here
# Change this to your base directory
BASE=/home/zotonic
# Change this to the complete path to zotonic.sh (this script)
ZOTONIC_SH=$BASE/zotonic.sh
# Change this to the directory where you have unpacked zotonic
# IMPORTANT: this directory must be called zotonic or zotonic-x.y where x.y is the version number.
ZOTONIC=$BASE/zotonic
# Change this to point to the erlang vm
ERL="/usr/local/bin/erl"
# The include path for the erlang vm, add when needed for your application.
PA="$ZOTONIC/ebin $ZOTONIC/deps/*/ebin $ZOTONIC/modules/*/deps/*/ebin $ZOTONIC/priv/modules/*/deps/*/ebin $ZOTONIC/priv/sites/*/modules/*/deps/*/ebin"
# The name of the Erlang node, this must be unique on your host.
SNAME=zotonic001
# Set the hostname to the fully qualified domain name of your host, or leave it as localhost.
# HOSTNAME=`hostname`
# HOSTNAME=your.domain.com
HOSTNAME=localhost
# The command used to restart zotonic when crashed, only used after a "zotonic.sh start"
export HEART_COMMAND="$ZOTONIC_SH start"
## The port and IP address zotonic will bind to (defaults to all ip addresses and port 8000)
export ZOTONIC_IP=any
export ZOTONIC_PORT=8000
# The filename where zotonic writes its unix process Id to, for monitoring applications.
export ZOTONIC_PIDFILE=$BASE/zotonic.pid
pushd $ZOTONIC >/dev/null
function start() {
echo "Starting zotonic $SNAME"
make -C $ZOTONIC >/dev/null
$ERL -pa $PA -name $SNAME@$HOSTNAME -boot start_sasl -heart -detached -s zotonic
}
function stop() {
echo "Stopping zotonic $SNAME"
$ERL -noshell -pa $PA -sname ${SNAME}_stop -s zotonic stop $SNAME@$HOSTNAME
}
function update() {
echo "Updating zotonic $SNAME"
$ERL -noshell -pa $PA -sname ${SNAME}_stop -s zotonic update $SNAME@$HOSTNAME
}
case $1 in
start)
start
;;
debug)
$ERL +P 10000000 +K true -pa $PA -name $SNAME@$HOSTNAME -boot start_sasl -s zotonic
;;
stop)
stop
;;
update)
update
;;
shell)
$ERL -sname zotonic_shell -remsh $SNAME@$HOSTNAME
;;
restart)
echo "Restarting zotonic"
stop
start
;;
*)
echo "Usage: $0 {debug|start|stop|restart|update}"
exit 1
esac
popd > /dev/null
exit 0