mksite is a small Python script made to simplify creating new websites on a Slicehost VPS.
Currently, it will create a vhost configuration file and the necessary directories for a site. These are all specified by template files and thus can be copied and modified to suit your specific needs and software.
- Python (tested with 2.6.4 and 2.7)
To install, simply run the included
You may need to modify the user and group that it installs
files as before using it.
At the very least, you need to check
/etc/mksite/mksite.conf and make any changes from that
to match your environment.
Optionally, create and modify templates as needed.
templates directory are 1 or more folders,
one per template. Each template has at least two files, the
configuration file and the actual template. Additional files
may be present for other operations.
All files for the template and the folder they're in share
a common name. In the case of the standard default template,
standard. The folder is standard and inside of it are
files such as standard.conf.
mksite will look for and use the following files:
- name.conf: configuration file
- name.tpl: template file
- name.dirs: file specifying directories to create
Template Configuration File
The templating system used for mksite is easy to work
with. All variables that get substituted are inside
As an example, the following line is in standard.tpl:
ServerAlias www.[% domain %]
domain is specified as
example.com, mksite will generate
domain, no variables are assumed to exist. They
are all specified in the template itself.
Let's look at the standard template.
[template] name = Standard website author = Ross Nelson license = Public domain ask = email
[template] section gives a name to the template, lists the
template's author, and specifies a license.
ask value is used to force mksite to ask for a value for
a given variable, even if a default is given. We'll get to
variables next, but for now we see that the email address is
listed as one we ask for.
Variables have two parts:
Description of the variable
[variables] domain = Domain name root = Root directory publicdirectory = Public HTML directory cgidirectory = CGI-BIN directory errorlog = Error log file accesslog = Access log file directoryindex = Directory index email = Webmaster e-mail address
Those are variables from the standard template. On the left is the variable name that we will use throughout the rest of the template, and on the right is our description. If the user is asked to specify a value for one of the variables, it will be shown the description.
We know from the
ask variable in
[template] that we can force
the user to give a value for something. We can also specify
defaults (remember, even if a default is specified, the user
will be asked for a value for something in
Defaults can be used to specify a value for something to be put in the configuration file that is static or a value that is based on other values.
For example, the standard template has the following:
[defaults] directoryindex = index.php index.xhtml index.htm index.html root = /srv/[% domain %] publicdirectory = [% root %]/public cgidirectory = [% root %]/cgi-bin/ errorlog = [% root %]/logs/error.log accesslog = [% root %]/logs/access.log email = webmaster@[% domain %]
As you can see,
publicdirectory is given here but not in
This will result in
publicdirectory being filled in with the
correct value (e.g.,
/srv/example.com/public) but it won't be
presented to the user.
Also included is
If you want to add a new variable that the user must give a value
for, add it to
[variables] but do not give it a default.
The directory file is used to tell mksite to create certain directories for you while it is creating the domain. This can be used to set up a directory structure that matches the vhost configuration.
As with the template file and the configuration file, this will be
processed by the template engine before it is used, allowing
you to do things like referencing
[% root %] (a variable in the
standard template) as shown here:
[% root %] [% mksiteuser %] [% mksitegroup %] 755 [% root %]/cgi-bin [% mksiteuser %] [% mksitegroup %] 755 [% root %]/logs [% mksiteuser %] [% mksitegroup %] 777 [% root %]/private [% mksiteuser %] [% mksitegroup %] 700 [% root %]/public [% mksiteuser %] [% mksitegroup %] 2750
There are four fields to every entry:
- The directory to create
- The user to set as the directory owner
- The group to set as the directory owning group
- The mode to set for the directory
Obviously, when running mksite, you have to have permission to set the owner, owning group, and mode as well as make the directory itself.
There are a number of variables that are filled in by mksite when it runs (overwriting any user-specified values for them):
domain: the domain the user is configuring
timestamp: a timestamp showing date and time mksite ran
templatename: the name of the template (from the configuration)
templateauthor: the author of the template (from the configuration)
templatelicense: the license for the template (from the configuration)
mksiteuser: the user specified in
mksitegroup: the group specified in
mksiteuid: the UID of
mksitegid: the GID of