Module: MonitrcHelper
- Defined in:
- lib/capistrano-monit/monit_config_helper.rb
Overview
This modules provides methods to create monitrc configuration files for various services
The methods are available through monitrc.
Currently you are required to manually modify your main monitrc file to include those generated by capistrano.
An example include directive:
- include "/home/myapp/config/monit/*.monitrc"
Instance Method Summary collapse
-
#create(template, path, options = {}) ⇒ Object
Creates a monitrc file from a template, puts it on the server at the given path and sets file permissions to 0700.
-
#get_template(template) ⇒ Object
Works out whether the given template is a file or string containing rhtml.
Instance Method Details
#create(template, path, options = {}) ⇒ Object
Creates a monitrc file from a template, puts it on the server at the given path and sets file permissions to 0700.
- template can be 'mongrel' or the name of a file or a string. 'mongrel' uses the standard mongrel templates provided with this package. See get_template below for a list of places searched for template files of your own.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capistrano-monit/monit_config_helper.rb', line 27 def create(template, path, = {}) template = template.to_s = () if template == 'mongrel' config_data = mongrel_ports.collect {|port| render .merge(:template => get_template(template), :port => port)}.join("\n\n") else config_data = render .merge(:template => get_template(template)) end put config_data, path, :mode => 0700 end |
#get_template(template) ⇒ Object
Works out whether the given template is a file or string containing rhtml.
Checks:
- current directory
- monitrc_templates path (defaults to templates/monit)
- capistrano-monit-tasks-templates dir where cappy-monit is installed (the standard templates are here)
If it can't find the file it assumes it's a one line string template and returns that
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/capistrano-monit/monit_config_helper.rb', line 52 def get_template(template) if template =~ /<%/ or template =~ /\n/ template else [ ".", configuration.monitrc_template_path, File.join(File.dirname(__FILE__), 'templates') ].each do |dir| if File.file?(File.join(dir, template)) return File.read(File.join(dir, template)) elsif File.file?(File.join(dir, template + ".erb")) @file_template_full_path = File.join(dir, template + ".erb") return File.read(File.join(dir, template + ".erb")) end end end template end |