Sha256: 65ef0bfcad36ee9898dd5eaf113a360e8643bf508457b82295781fa22799e836

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

namespace :deploy do
  set :bundle_binstubs, -> { shared_path.join('bin') }

  desc 'Export upstart script'
  task :export_upstart do
    on roles(:app) do
      within current_path do
        sudo fetch(:chruby_exec), "#{fetch(:chruby_ruby)} -- #{fetch(:bundle_binstubs)}/foreman export upstart /etc/init -a #{fetch(:application)} -u \`whoami\` -l #{shared_path}/log"
      end
    end
  end

  task :disable_autostart do
    on roles(:app) do
      execute "/bin/echo manual | sudo /usr/bin/tee /etc/init/#{fetch(:application)}.override"
    end
  end

  task :enable_autostart do
    on roles(:app) do
      execute "/bin/echo | sudo /usr/bin/tee /etc/init/#{fetch(:application)}.override"
    end
  end

  namespace :foreman do
    desc 'Upload Procfile to server'
    task :upload_procfile do
      on roles(:app) do |host|
        upload! "tmp/Procfile_#{host.hostname}", "#{fetch(:deploy_to)}/current/Procfile"
      end
    end

    desc 'Generate Procfile'
    task  :generate_procfile do
      Dir.mkdir('tmp') unless Dir.exist?('tmp')

      procfile_contents = fetch(:procfile_contents)

      on roles(:app) do |host|
        procfile_contents_string =
          if procfile_contents.is_a?(Hash)
            procfile_contents.fetch(host.hostname)
          else
            procfile_contents
          end

        File.open("tmp/Procfile_#{host.hostname}", 'w') do |conf|
          procfile_contents_string.each_line do |line|
            conf.puts "#{line.chomp} 2>&1 | logger -t #{fetch(:app_name)}"
          end
        end
      end
    end
  end

  before 'deploy:export_upstart', 'deploy:foreman:upload_procfile'
  before 'deploy:foreman:upload_procfile', 'deploy:foreman:generate_procfile'
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capistrano-twingly-3.0.0 lib/capistrano/twingly/tasks/upstart.rake
capistrano-twingly-2.4.1 lib/capistrano/twingly/tasks/upstart.rake