├── lib ├── capistrano-foreman.rb └── capistrano │ ├── foreman.rb │ └── tasks │ └── foreman.rake ├── Rakefile ├── Gemfile ├── .gitignore ├── README.md ├── capistrano-foreman.gemspec └── LICENSE /lib/capistrano-foreman.rb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | -------------------------------------------------------------------------------- /lib/capistrano/foreman.rb: -------------------------------------------------------------------------------- 1 | load File.expand_path("../tasks/foreman.rake", __FILE__) 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in capistrano-foreman.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | /.config 4 | /coverage/ 5 | /InstalledFiles 6 | /pkg/ 7 | /spec/reports/ 8 | /test/tmp/ 9 | /test/version_tmp/ 10 | /tmp/ 11 | 12 | ## Specific to RubyMotion: 13 | .dat* 14 | .repl_history 15 | build/ 16 | 17 | ## Documentation cache and generated files: 18 | /.yardoc/ 19 | /_yardoc/ 20 | /doc/ 21 | /rdoc/ 22 | 23 | ## Environment normalisation: 24 | /.bundle/ 25 | /vendor/bundle 26 | /lib/bundler/man/ 27 | 28 | Gemfile.lock 29 | .ruby-version 30 | .ruby-gemset 31 | 32 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 33 | .rvmrc 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Capistrano::Foreman 2 | 3 | Foreman support for Capistrano v3 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | # Gemfile 10 | gem 'capistrano', '~> 3.0' 11 | gem 'capistrano-foreman', github: 'RKushnir/capistrano-foreman' 12 | 13 | And then execute: 14 | 15 | $ bundle install 16 | 17 | ## Usage 18 | 19 | Require in Capfile to use the default task: 20 | 21 | # Capfile 22 | require 'capistrano/foreman' 23 | 24 | And you should be good to go! 25 | 26 | ## Contributing 27 | 28 | 1. Fork it 29 | 2. Create your feature branch (`git checkout -b my-new-feature`) 30 | 3. Commit your changes (`git commit -am 'Add some feature'`) 31 | 4. Push to the branch (`git push origin my-new-feature`) 32 | 5. Create new Pull Request 33 | -------------------------------------------------------------------------------- /capistrano-foreman.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = "capistrano-foreman" 7 | gem.version = '0.0.1' 8 | gem.authors = ["Roman Kushnir"] 9 | gem.email = ["roman.kushnir@innocode.no"] 10 | gem.description = %q{Foreman integration for Capistrano} 11 | gem.summary = %q{Foreman integration for Capistrano} 12 | gem.homepage = "https://github.com/RKushnir/capistrano-foreman" 13 | 14 | gem.files = `git ls-files`.split($/) 15 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 16 | gem.require_paths = ["lib"] 17 | 18 | gem.add_dependency 'capistrano', '~> 3.0' 19 | gem.add_dependency 'sshkit', '~> 1.2' 20 | end 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Roman Kushnir 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/foreman.rake: -------------------------------------------------------------------------------- 1 | namespace :foreman do 2 | desc "Prints the Foreman version on the target host" 3 | task :check do 4 | on roles(fetch(:foreman_roles, :all)) do 5 | if fetch(:log_level) == :debug 6 | puts capture(:foreman, "version") 7 | end 8 | end 9 | end 10 | 11 | desc "Prefix commands to run them with the ENV-variables loaded" 12 | task :hook do 13 | foreman_prefix = "foreman run" 14 | fetch(:foreman_map_bins).each do |command| 15 | SSHKit.config.command_map.prefix[command.to_sym].unshift(foreman_prefix) 16 | end 17 | end 18 | 19 | desc "Export the Procfile to Ubuntu's upstart scripts" 20 | task :export do 21 | on roles(fetch(:foreman_roles, :all)) do 22 | user = fetch(:foreman_user) { capture(:whoami) } 23 | as :root do 24 | execute :foreman, 25 | "export", 26 | "upstart", 27 | "/etc/init", 28 | "-a", fetch(:application), 29 | "-u", user, 30 | "-l", shared_path.join("log"), 31 | "-e", shared_path.join(".env"), 32 | "-f", release_path.join("Procfile"), 33 | "-d", release_path 34 | end 35 | end 36 | end 37 | 38 | desc "Start the application services" 39 | task :start do 40 | on roles(fetch(:foreman_roles, :all)) do 41 | as :root do 42 | execute :start, fetch(:application) 43 | end 44 | end 45 | end 46 | 47 | desc "Stop the application services" 48 | task :stop do 49 | on roles(fetch(:foreman_roles, :all)) do 50 | as :root do 51 | execute :stop, fetch(:application) 52 | end 53 | end 54 | end 55 | 56 | desc "Restart the application services" 57 | task :restart do 58 | on roles(fetch(:foreman_roles, :all)) do 59 | as :root do 60 | status = capture(:status, fetch(:application)) 61 | command = status =~ /running/ ? :restart : :start 62 | execute command, fetch(:application) 63 | end 64 | end 65 | end 66 | end 67 | 68 | Capistrano::DSL.stages.each do |stage| 69 | after stage, 'foreman:hook' 70 | after stage, 'foreman:check' 71 | end 72 | 73 | before 'deploy:publishing', 'foreman:export' 74 | after 'deploy:publishing', 'foreman:restart' 75 | 76 | namespace :load do 77 | task :defaults do 78 | set :foreman_map_bins, %w{rake} 79 | end 80 | end 81 | --------------------------------------------------------------------------------