class Slugforge::Build::ExportUpstart
Public Instance Methods
call()
click to toggle source
# File lib/slugforge/build/export_upstart.rb, line 5 def call unless File.exist?(procfile_path) logger.say_status :missing, 'foreman Procfile', :yellow return false end logger.say_status :execute, 'preprocessing foreman templates' preprocess_templates end
Private Instance Methods
foreman_templates_dir()
click to toggle source
# File lib/slugforge/build/export_upstart.rb, line 65 def foreman_templates_dir templates_dir('foreman') end
preprocess_templates()
click to toggle source
# File lib/slugforge/build/export_upstart.rb, line 17 def preprocess_templates Dir.foreach(foreman_templates_dir) do |template| next unless template =~ /\.erb$/ template "foreman/#{template}", File.join(upstart_templates_dir, template) end end
procfile_path()
click to toggle source
# File lib/slugforge/build/export_upstart.rb, line 69 def procfile_path project_path('Procfile') end
template_command()
click to toggle source
The template file is processed by ERB twice. Once by chef when putting it down and once by foreman when generating the upstart config. This ERB string goes into the command variable so it will show up as it is here when chef is done with it so foreman can process the logic in this string.
# File lib/slugforge/build/export_upstart.rb, line 29 def template_command if unicorn_command "<% if process.command.include?('bundle exec #{unicorn_command}') %> deploy/unicorn-shepherd.sh #{unicorn_command} <%= app %>-<%= name %>-<%= num %> <% else %> <%= process.command %> <% end %>" else "<%= process.command %>" end end
unicorn_command()
click to toggle source
iterate through procfile and see if we have have unicorn or rainbows
Returns===¶ ↑
unicorn|rainbows or nil if neither was found
Notes, currently doesn't handle if there is both unicorn AND rainbows. Will just return the last one it finds. We could handle this if someone needed it but this is easier for now.
# File lib/slugforge/build/export_upstart.rb, line 46 def unicorn_command @unicorn_command ||= begin command = nil ::File.read(procfile_path).lines do |line| if line.include?("bundle exec unicorn") command = "unicorn" elsif line.include?("bundle exec rainbows") command = "rainbows" end end # If we are using unicorn/rainbows, put the unicorn-shepherd script into the repo's deploy directory # so we can use it to start unicorn as an upstart service if command FileUtils.cp(unicorn_shepherd_path, project_path('deploy')) end command end end
unicorn_shepherd_path()
click to toggle source
# File lib/slugforge/build/export_upstart.rb, line 73 def unicorn_shepherd_path scripts_dir('unicorn-shepherd.sh') end
upstart_templates_dir()
click to toggle source
# File lib/slugforge/build/export_upstart.rb, line 77 def upstart_templates_dir @repo_templates_dir ||= project_path('deploy', 'upstart-templates').tap do |dir| FileUtils.mkdir_p(dir) end end