Thin_Upstart

This is an alternative to Foreman + Upstart generating your Upstart conf files. It ignores your Procfile, and insteads uses your Thin .yml config file. The following files are generated (assuming you call your group of Thin apps 'web-app'):

# App dirs
|- app1
|- app2

# Template dir
|- {{name}}.conf
|- {{name}}-{{app}}.conf

# Files generated
|- output-dir
  |- web-apps.conf
  |- web-apps-app1.conf
  |- web-apps-app2.conf
  |- ...

Installation

gem install Thin_Upstart

Usage: Ruby

require "Thin_Upstart"

Thin_Upstart { |o|
  o.name      "web-apps"
  o.apps      "./apps"
  o.templates "./templates/*.conf" # file glob     
  o.output    "./upstart"        
  o.yml       "config/thin.yml"  
  o.kv        Hash[]               # Custom key/value for your mustache templates.
}

If you want to delete files generated by Thin_Upstart, use:

Thin_Upstart.trash "my/conf/dir"

All files that end in ".conf" are deleted if they contain the following string:

# Generated by Thin_Upstart

Usage: Shell

Thin_Upstart 
  --name       web-apps 
  --apps       ./apps
  --templates  ./templates
  --yml        config/thin.yml
  --output     ./output
  --kv         " custom_1 => val_1 , custom_2 => val_2 , ... "
  --trash      my/conf/dir  # When used, all other options are ignored.
  --help 

Note: Be sure to use quotation marks when using file globs or --kv:

Thin_Upstart --templates "template/*.conf"
Thin_Upstart --yml       "config/*.yml"
Thin_Upstart --kv        " custom_1 => val_1 , custom_2 => val_2 , ... "

When using the --kv option on the shell, you are limited to using the above format. This means you can put any values using commas:

Thin_Upstart --kv " custom_1 => val 1 , custom_2 => val 2 "

# This hash is generated based on the above line:
# { 
#    'custom_1' => "val 1", 
#    'custom_2' => 'val 2'
# }

Usage: Mustache Template

In your Mustache templates, you have access to the following values:

  • name: Name of app group: e.g. My-Web-Apps
  • app: Name of current app: e.g. Blog
  • yml: Relative path from current app directory to .yml file
  • app_path: Full path to app.
  • yml_path: Full path to .yml file.
  • apps_dir: Full path to directory of apps.
  • your custom values: Use method :kv with an argument of a hash.

You can use Mustache values in the file names of the templates. For example:

  • my/template/dir/{name}.conf
  • my/template/dir/{name}-{app}.conf

Run Tests

git clone git@github.com:da99/Thin_Upstart.git
cd Thin_Upstart
bundle update
bundle exec bacon spec/main.rb

"I hate writing."

If you know of existing software that makes the above redundant, please tell me. The last thing I want to do is maintain code.