itrigga-generator

A flexible template rendering gem. We use this to dynamically generate monit scripts, logrotate scripts, cron scripts etc. At the moment only erb templates are supported.

How to use with config file

There are 2 ways to make the generator work - with or without a config file. A config file is simply a hash of options serialized into YAML. An example (test.yml) is: +


processes_to_start: [:worker] processes:

worker:
  name: worker_1
  identifier: 1

+ In this example there is a worker process whose template should be rendered. If this was a monit script then in the TEMPLATE_DIR there must be a matching template named worker.monit.config

This can be invoked by: rake itrigga:generator TEMPLATE_DIR=/tmp/test/templates OUTPUT_DIR=/tmp/test/output CONFIG_FILE=/tmp/test/test.yml This will look for the template in /tmp/test/templates and put the rendered template into /tmp/test/output

If a config file is given then is must define a processes hash. Each key needs to match the name of the template. Only the templates listed in the processes_to_start list will be rendered.

For this example the worker.monit.config file looks like this: + check process <%= name %> with pidfile <%= File.join(“/var/run”,“worker_#identifer.pid”) %> start program = “/etc/init.d/itrigga start worker <%= identifer %>” stop program = “/etc/init.d/itrigga stop worker <%= identifer %>” group workers +

The keys defined in the config file for each process are made available to the template as top level variables (in this case identifer and name) Also any variables given to the rake task are also made available - so there will be variables named template_dir, output_dir and config_file.

How to use with no config file

You can also set the CONFIG_FILE=false in the rake task. This will then just make the variables in the rake task available to the template.

eg rake itrigga:generator PATTERN=logrotate TEMPLATE_DIR=/tmp/test/templates OUTPUT_DIR=/tmp/test/output CONFIG_FILE=false

What if I have different templates in the TEMPLATE_DIR?

Use the PATTERN=xxxx variable (which can be any regex minus the start and end /). This will then filter the templates in the TEMPLATE_DIR.

What if I have a template I don’t want rendered?

Change the template name to: worker.monit.config.inactive

Contributing to itrigga-generator

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 iTrigga Media. See LICENSE.txt for further details.