Skip to content
/ reconf Public
forked from snsinfu/reconf

Generate config file and run command

License

Notifications You must be signed in to change notification settings

Sqooba/reconf

 
 

Repository files navigation

reconf: Generate config file and run command

Test Status Release

reconf generates files from templates and environment variables and executes a command.

Build

Requires a Go compiler. The following command builds reconf executable:

$ go build -o reconf github.com/snsinfu/reconf

Usage

reconf is a statically-built CLI utility. It accepts the following flags:

Usage: reconf [-f -w <file> ...] [<command>...]

  <command>   Command to execute. If command is not given, reconf will
              just generate files and exit.

Options:
  -w, --render <file>  Generate <file> (if it does not exist) by rendering
                       template file named "<file>.template".
                       Optional format "<template file>:<render file>" allows to be more flexible
  -f, --force          Force generating files, overwriting existing ones.
  -h, --help           Show this usage message and exit.

For example, the following command line generates a configuration file /srv/nginx.conf and runs nginx with the generated configuration. The file is generated from a template file /srv/nginx.conf.template using environment variables available as {{ .env.NAME }}.

$ reconf -w /srv/nginx.conf nginx -c /srv/nginx.conf

With the optional <template file>:<render file> format, template file can come from anywhere:

$ reconf -w /srv/templates/nginx.conf.template:/srv/nginx.conf nginx -c /srv/nginx.conf

So, if the template contains the following listen stanza

listen {{.env.PORT}};

and if you provide PORT environment variable, reconf interpolates the template part {{.env.PORT}} with the actual value:

$ PORT=8080 reconf -w /srv/nginx.conf nginx -c /srv/nginx.conf
nginx listens on port 8080

Passing -f (force) option makes sure the config file is always generated. So, the following command line updates the existing configuration file, and now the server listens on the different port number:

$ PORT=9000 reconf -fw /srv/nginx.conf nginx -c /srv/nginx.conf
nginx listens on port 9000

Without the -f option, reconf skips to generate existing files.

Test

Run unit tests:

$ git clone https://github.com/snsinfu/reconf.git
$ cd reconf
$ go test .

Integration tests:

$ tests/run

License

MIT License.

About

Generate config file and run command

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 79.0%
  • Shell 21.0%