项目作者: vifreefly

项目描述 :
Capistrano integration for Procsd
高级语言: Ruby
项目地址: git://github.com/vifreefly/capistrano-procsd.git
创建时间: 2018-11-08T23:41:29Z
项目社区:https://github.com/vifreefly/capistrano-procsd

开源协议:MIT License

下载


Capistrano::Procsd

Capistrano integration for Procsd. All available tasks:

  1. cap procsd:create[arguments] # Create app services
  2. cap procsd:create_or_restart # Create or restart (if already created) app services
  3. cap procsd:destroy # Destroy app services
  4. cap procsd:list # List all services
  5. cap procsd:logs[arguments] # Check app services logs
  6. cap procsd:restart # Restart app services
  7. cap procsd:run[cmd] # Run command on the remote server
  8. cap procsd:start # Start app services
  9. cap procsd:status[arguments] # Check status of app services
  10. cap procsd:stop # Stop app services

Configuration

Add to your application Gemfile somewhere:

  1. # Gemfile
  2. group :development do
  3. gem 'capistrano-procsd', require: false
  4. end

Require procsd tasks inside Capfile:

  1. # Capfile
  2. require 'capistrano/procsd'

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

  1. # config/deploy.rb
  2. 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:

  1. # Install ruby system-wide from apt repositories:
  2. $ sudo apt install ruby
  3. # Install procsd gem system-wide:
  4. $ sudo gem install procsd
  5. # Check the procsd installed path:
  6. $ sudo which procsd
  7. /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:

  1. # Gemfile
  2. group :development do
  3. # You're probably already have it
  4. gem 'capistrano-rbenv', require: false
  5. gem 'capistrano-bundler', require: false
  6. end
  7. # Add procsd gem
  8. gem 'procsd', require: false

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

  1. # Capfile
  2. require 'capistrano/rbenv'
  3. require 'capistrano/bundler'

And finally add procsd to rbenv and bundle bins:

  1. # config/deploy.rb
  2. append :rbenv_map_bins, "procsd"
  3. 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:
  1. deploy@server:~/sample_app/current$ procsd config sudoers
  2. 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:

  1. # config/deploy.rb
  2. # pass `--add-to-sudoers` option to the `procsd create` command:
  3. 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.