Git Product home page Git Product logo

capistrano-foreman-systemd's Introduction

Capistrano::ForemanSystemd

This is heavily based on the capistrano-foreman gem but it only targets systemd (default init system for Ubuntu since 16.04). It works best with foreman-systemd (fork of 0.78 version of foreman gem).

Installation

gem 'capistrano', '~> 3.1'
gem 'capistrano-foreman-systemd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano-foreman-systemd

Usage

Require in Capfile:

require 'capistrano/foreman_systemd'

Export Procfile to process management format (defaults to upstart) and restart the application services:

$ cap foreman_systemd:setup
$ cap foreman_systemd:start

Configurable options, shown here with defaults:

set :foreman_systemd_roles, :all
set :foreman_systemd_export_format, 'systemd'
set :foreman_systemd_export_path, '/etc/init'
set :foreman_systemd_flags, "--root=#{current_path}" # optional, default is empty string
set :foreman_systemd_target_path, release_path
set :foreman_systemd_app, -> { fetch(:application) }
set :foreman_systemd_concurrency, 'web=2,worker=1' # optional, default is not set
set :foreman_systemd_log, -> { shared_path.join('log') }
set :foreman_systemd_port, 3000 # optional, default is not set
set :foreman_systemd_user, 'www-data' # optional, default is not set

See exporting options for an exhaustive list of foreman options.

Tasks

This gem provides the following Capistrano tasks:

  • foreman_systemd:setup exports the Procfile and starts application services
  • foreman_systemd:export exports the Procfile to process management format
  • foreman_systemd:enable enables the application in systemd
  • foreman_systemd:disable disables the application in systemd
  • foreman_systemd:restart restarts the application services
  • foreman_systemd:start starts the application services
  • foreman_systemd:stop stops the application services

User permissions

Commands have to be executed with root or user with sudo writes because foreman:setup creates files in /etc/systemd/system directory.

Example

Configuration in deploy.rb:

# Set the app with `sites/` prefix
set :foreman_app, -> { fetch(:application) }

# Set user to `deploy`, assuming this is your deploy user
set :foreman_user, 'deploy'

# Set root to `current_path` so exporting only have to be done once.
set :foreman_flags, "--root=#{current_path}"

Setup your init scripts by running foreman:setup after your first deploy. From this moment on you only have to run foreman:setup when your Procfile has changed or when you alter the foreman deploy configuration.

Finally you have to instruct Capistrano to run foreman:restart after deploy:

You can control which process runs on which servers using server variable foreman_systemd_concurrency:

server '123.123.123.1', { roles: [:web], foreman_systemd_concurrency: 'web=1,sidekiq=1' }
server '123.123.123.1', { roles: [:web], foreman_systemd_concurrency: 'web=1,sidekiq=0' }

Finally

# Hook foreman restart after publishing
after :'deploy:publishing', :'foreman:restart'

Notes

When using rbenv, rvm, chruby and/or bundler don't forget to add foreman to the bins list:

fetch(:rbenv_map_bins, []).push 'foreman'
fetch(:rvm_map_bins, []).push 'foreman'
fetch(:chruby_map_bins, []).push 'foreman'
fetch(:bundle_bins, []).push 'foreman'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

capistrano-foreman-systemd's People

Contributors

3lvis avatar aserafin avatar glaszig avatar hatkirby avatar j15e avatar jgorset avatar koenpunt avatar pnomolos avatar stabenfeldt avatar wingrunr21 avatar yesmeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

capistrano-foreman-systemd's Issues

Not working with capistrano ~> 3.6 ?

Gemfile:

  gem 'capistrano', "~> 3.6"
  gem 'capistrano-rvm'
  gem 'capistrano-rails'
  gem 'capistrano-bundle'
  gem 'capistrano-locally'
  gem 'capistrano-scm-copy'
  gem 'capistrano-foreman-systemd'

Output:

 bundle install
The git source `git://github.com/plataformatec/devise.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
The git source `git://github.com/gregbell/active_admin.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
The git source `git://github.com/thoughtbot/paperclip.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies....
Bundler could not find compatible versions for gem "capistrano":
  In snapshot (Gemfile.lock):
    capistrano (= 3.6.1)

  In Gemfile:
    capistrano (~> 3.6)

    capistrano-bundle was resolved to 0.0.5, which depends on
      capistrano (>= 3.1)

    capistrano-foreman-systemd was resolved to 0.0.4, which depends on
      capistrano (~> 3.4.1)

    capistrano-rails was resolved to 1.1.8, which depends on
      capistrano (~> 3.1)

    capistrano-rails was resolved to 1.1.8, which depends on
      capistrano (~> 3.1)

    capistrano-rvm was resolved to 0.1.2, which depends on
      capistrano (~> 3.0)

    capistrano-rvm was resolved to 0.1.2, which depends on
      capistrano (~> 3.0)

    capistrano-rvm was resolved to 0.1.2, which depends on
      capistrano (~> 3.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

:-(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.