Capistrano::Procsd

Capistrano integration for Procsd. All available tasks:

cap procsd:create[arguments]       # Create app services
cap procsd:create_or_restart       # Create or restart (if already created) app services
cap procsd:destroy                 # Destroy app services
cap procsd:list                    # List all services
cap procsd:logs[arguments]         # Check app services logs
cap procsd:restart                 # Restart app services
cap procsd:run[cmd]                # Run command on the remote server
cap procsd:start                   # Start app services
cap procsd:status[arguments]       # Check status of app services
cap procsd:stop                    # Stop app services

Configuration

Add to your application Gemfile somewhere:

# Gemfile

group :development do
  gem 'capistrano-procsd', require: false
end

Require procsd tasks inside Capfile:

# Capfile

require 'capistrano/procsd'

And finally add hook to call procsd:create_or_restart task each time after publishing:

# config/deploy.rb

after "deploy:published", "procsd:create_or_restart"

Done!

Procsd location on the remote server

System-wide

Configuration above assumes that you have $ procsd executable somewhere in the global system path on your remote server. You can install gem system-wide this way:

# Install ruby system-wide from apt repositories:
$ sudo apt install ruby

# Install procsd gem system-wide:
$ sudo gem install procsd

# Check the procsd installed path:
$ sudo which procsd
/usr/local/bin/procsd

Like you see, Procsd installed to the system bin path /usr/local/bin/ and can be accessed from any user and kind of connection (including default Capistrano non-interactive, non-login ssh connection)

Local user installation using Rbenv

There is another way if you don't want to install Ruby system-wide for some reason and use Rbenv instead:

Add procsd gem to your application Gemfile:

# Gemfile

group :development do
  # You're probably already have it
  gem 'capistrano-rbenv', require: false
  gem 'capistrano-bundler', require: false
end

# Add procsd gem
gem 'procsd', require: false

Require capistrano/rbenv and capistrano/bundler inside Capfile (if not required yet):

# Capfile

require 'capistrano/rbenv'
require 'capistrano/bundler'

And finally add procsd to rbenv and bundle bins:

# config/deploy.rb

append :rbenv_map_bins, "procsd"
append :bundle_bins, "procsd"

Usage

At the first deploy $ bundle exec cap production deploy app services will be created and started. You will be prompted to fill in remote user password (make sure that your deploy user added to the sudo group adduser deploy sudo).

Start/Stop/Restart services without sudo password

If you don't want to type password each time while deploying, you can add start/stop/restart commands to the sudoers file:

  1. Login to the remote server, cd into application folder, and type $ procsd config sudoers. Example:
deploy@server:~/sample_app/current$ procsd config sudoers

deploy ALL=NOPASSWD: /bin/systemctl start sample_app.target, /bin/systemctl stop sample_app.target, /bin/systemctl restart sample_app.target
  1. Copy sudoers rule from above to the sudoers file (just type $ sudo visudo and paste line at the bottom then save and exit). Logout from the server.

Now try to call restart task $ bundle exec cap production procsd:restart. If all is fine, task will execute without password prompt.

Note: steps above can be done automatically as well:

# config/deploy.rb

# pass `--add-to-sudoers` option to the `procsd create` command:
set :procsd_sudoers_at_create_or_restart, true

Now sudoers rule will be added at the first deploy automatically.

Examples

  • bundle exec cap production procsd:logs[-t] - Tail application logs
  • bundle exec cap production procsd:run[bash] - ssh into app server, cd into app directory and leave the bash session open

License

The gem is available as open source under the terms of the MIT License.