Git Product home page Git Product logo

capistrano-simple_systemd's Introduction

capistrano-simple_systemd Gem Version

Capistrano tasks to control mutiple services with systemd

Installation

Add this line to your application's Gemfile:

gem 'capistrano-simple_systemd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano-simple_systemd

Usage

Add this line to your Capfile:

require "capistrano/simple_systemd"

Service files are defined as ERB templates ending with .service.erb in config/systemd.
Sample erb template

[Unit]
Description=SMS Service
After=network.target

[Service]
Type=simple
User=deploy
Environment=RACK_ENV=<%= fetch(:stage) %>
WorkingDirectory=<%= current_path %>
ExecStart=<%= "#{fetch(:home_dir)}/.rvm/bin/rvm #{fetch(:rvm_ruby_version)} do bundle exec #{current_path}/bin/sms_service"%>
TimeoutSec=10
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sms-service

[Install]
WantedBy=multi-user.target

PLEASE NOTE: Currently only files with the .service.erb extension are considered as service file templates. Others like .target.erb aren't supported yet

The following tasks are provided out of the box

cap systemd:reload-daemons # run sudo systemctl daemon-reload
cap systemd:upload         # upload all provided service files
cap systemd:remove         # remove all provided service files
cap systemd:enable         # enable all provided service files
cap systemd:disable        # disable all provided service files

The following tasks will be created for each service template detected in the config/systemd directory

cap systemd:{service}:disable
cap systemd:{service}:enable
cap systemd:{service}:reload
cap systemd:{service}:reload-or-restart
cap systemd:{service}:restart
cap systemd:{service}:start
cap systemd:{service}:stop
cap systemd:{service}:upload
cap systemd:{service}:remove

Where service is the base name of the service template.
For example, placing puma.service.erb in the template directory will yield the following tasks

cap systemd:puma:disable
cap systemd:puma:enable
cap systemd:puma:reload
cap systemd:puma:reload-or-restart
cap systemd:puma:restart
cap systemd:puma:start
cap systemd:puma:stop
cap systemd:puma:upload
cap systemd:puma:remove

Run

cap {stage} systemd:upload

Or

cap {stage} setup

to compile and upload the service files. Service files will be prefixed with whichever value is in service_file_prefix and uploaded to /etc/systemd/system. The variable service_file_prefix by default is set to whatever is in the application configuration variable.
So if application is set to paypoint then puma.service.erb will be uploaded to /etc/systemd/system/paypoint-puma.service.
service_file_prefix can be configured. E.g.

set :service_file_prefix, 'paypoint-app'

Services are enabled after upload by invoking systemd:{service}:enable. This behaviour can be disabled by setting enable_services_after_upload to false.

set :enable_services_after_upload, false

Contributing

All contributions are welcome. Improvements are especially welcome. To contribute

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

License

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

capistrano-simple_systemd's People

Contributors

darkwasp99 avatar dependabot[bot] avatar gkosae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.