-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0cb7b8
commit 96f1461
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Template Resources | ||
|
||
Template resources are written in TOML and define a single template resource. | ||
Template resources are stored under the `/etc/confd/conf.d` directory by default. | ||
|
||
Required: | ||
|
||
* `dest` (string) - output file where the template should be rendered. | ||
* `keys` (array of strings) - An array of etcd keys. Keys will be looked up | ||
with the configured prefix. | ||
* `src` (string) - relative path of a [configuration template](templates.md). | ||
|
||
Optional: | ||
|
||
* `group` (string) - name of the group that should own the file. | ||
* `mode` (string) - mode the file should be in. | ||
* `owner` (string) - name of the user that should own the file. | ||
* `reload_cmd` (string) - command to reload config. | ||
* `check_cmd` (string) - command to check config. Use `{{ .src }}` to reference | ||
the rendered source template. | ||
|
||
Example: | ||
|
||
```TOML | ||
[template] | ||
src = "nginx.conf.tmpl" | ||
dest = "/etc/nginx/nginx.conf" | ||
owner = "root" | ||
group = "root" | ||
mode = "0644" | ||
keys = [ | ||
"/nginx", | ||
] | ||
check_cmd = "/usr/sbin/nginx -t -c {{ .src }}" | ||
reload_cmd = "/usr/sbin/service nginx restart" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Templates | ||
|
||
Templates define a single application configration template. | ||
Templates are stored under the `/etc/confd/templates` directory by default. | ||
|
||
Templates are written in Go's [`text/template`](http://golang.org/pkg/text/template/). | ||
|
||
> Etcd keys are treated as paths and automatically transformed into keys for retrieval in templates. Underscores are used in place of forward slashes. _Values retrived from Etcd are never modified._ | ||
> For example `/foo/bar` becomes `foo_bar`. | ||
> `foo_bar` is accessed as `{{ .foo_bar }}` | ||
|
||
Example: | ||
```Bash | ||
$ etcdctl set /nginx/domain 'example.com' | ||
$ etcdctl set /nginx/root '/var/www/example_dotcom' | ||
$ etcdctl set /nginx/worker_processes '2' | ||
``` | ||
|
||
|
||
`$ cat /etc/confd/templates/nginx.conf.tmpl`: | ||
```Text | ||
worker_processes {{ .nginx_worker_processes }}; | ||
server { | ||
listen 80; | ||
server_name www.{{ .nginx_domain }}; | ||
access_log /var/log/nginx/{{ .nginx_domain }}.access.log; | ||
error_log /var/log/nginx/{{ .nginx_domain }}.log; | ||
location / { | ||
root {{ .nginx_root }}; | ||
index index.html index.htm; | ||
} | ||
} | ||
``` | ||
|
||
Will produce `/etc/nginx/nginx.conf`: | ||
```Text | ||
worker_processes 2; | ||
server { | ||
listen 80; | ||
server_name www.example.com; | ||
access_log /var/log/nginx/example.com.access.log; | ||
error_log /var/log/nginx/example.com.error.log; | ||
location / { | ||
root /var/www/example_dotcom; | ||
index index.html index.htm; | ||
} | ||
} | ||
``` | ||
|
||
Go's [`text/template`](http://golang.org/pkg/text/template/) package is very powerful. For more details on it's capabilities see its [documentation.](http://golang.org/pkg/text/template/) |