Git Product home page Git Product logo

puma-plugin-systemd's Introduction

⚠️ Systemd support is now built-in to Puma. This plugin is deprecated in favor of the native support.

Puma Systemd Plugin

Build results Gem version

Puma integration with systemd for better daemonising under modern Linux systemds: notify, status, watchdog.

  • Notify systemd when puma has booted and is ready to handle requests
  • Publish puma stats as systemd service status for a quick overview
  • Use the watchdog to make sure your puma processes are healthy and haven't locked up or run out of memory

Puma already natively supports socket activation.

Installation

Add this gem to your Gemfile with puma and then bundle:

gem "puma"
gem "puma-plugin-systemd"

Add it to your puma config:

# config/puma.rb

bind "tcp://127.0.0.1:9292"

workers 2
threads 8, 16

plugin :systemd

Usage

Notify

Make sure puma is being started using a systemd service unit with Type=notify, something like:

# puma.service
[Service]
Type=notify
User=puma
WorkingDirectory=/app
ExecStart=/app/bin/puma -C config/puma.rb -e production
ExecReload=/bin/kill -USR1 $MAINPID
Restart=always
KillMode=mixed

Status

Running in notify mode as above should just start publishing puma stats as systemd status. Running systemctl status puma.service or similar should result in a Status line in your status output:

app@web:~$ sudo systemctl status puma.service
● puma.service - puma
   Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2016-10-24 00:26:55 UTC; 5s ago
 Main PID: 32234 (ruby2.7)
   Status: "puma 3.6.0 cluster: 2/2 workers: 8/16 threads, 8 available, 0 backlog"
    Tasks: 10
   Memory: 167.9M
      CPU: 7.150s
   CGroup: /system.slice/puma.service
           ├─32234 puma 3.6.0 (unix:///app/tmp/sockets/puma.sock?backlog=1024) [app]
           ├─32251 puma: cluster worker 0: 32234 [app]
           └─32253 puma: cluster worker 1: 32234 [app]

Oct 24 00:26:10 web systemd[30762]: puma.service: Executing: /app/bin/puma -C config/puma.rb -e production
Oct 24 00:54:58 web puma[32234]: [32234] Puma starting in cluster mode...
Oct 24 00:54:58 web puma[32234]: [32234] * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
Oct 24 00:54:58 web puma[32234]: [32234] * Min threads: 8, max threads: 64
Oct 24 00:26:55 web puma[32234]: [32234] * Environment: production
Oct 24 00:26:55 web puma[32234]: [32234] * Process workers: 2
Oct 24 00:26:55 web puma[32234]: [32234] * Phased restart available
Oct 24 00:26:55 web puma[32234]: [32234] * Listening on unix:///app/tmp/sockets/puma.sock?backlog=1024
Oct 24 00:26:55 web puma[32234]: [32234] Use Ctrl-C to stop
Oct 24 00:26:55 web puma[32234]: [32234] * systemd: notify ready
Oct 24 00:26:55 web puma[32234]: [32251] + Gemfile in context: /app/Gemfile
Oct 24 00:26:55 web systemd[1]: Started puma.
Oct 24 00:26:55 web puma[32234]: [32234] * systemd: watchdog detected (30000000usec)
Oct 24 00:26:55 web puma[32234]: [32253] + Gemfile in context: /app/Gemfile

Watchdog

Adding a WatchdogSec=30 or similar to your systemd service file will tell puma systemd to ping systemd at half the specified interval to ensure the service is running and healthy.

Development

After checking out the repo, run script/setup to install dependencies. Then, run rake test to run the tests. You can also run script/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Example

There is an example directory which contains a Dockerfile and basic configuration for testing. To use it:

cd example

# Build an image with systemd, puma and the plugin configured
docker build --tag example .

# Start a new container from the image in the background
docker run --name example --privileged --detach --rm example

# Show puma systemd integration
docker exec example systemctl status puma

# Stop the container
docker exec example halt

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sj26/puma-plugin-systemd.

License

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

puma-plugin-systemd's People

Contributors

ehelms avatar olleolleolle avatar openbl avatar sj26 avatar yob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

puma-plugin-systemd's Issues

puma (~> 3.6.0)

Could update upgrade lock puma version?

Bundler could not find compatible versions for gem "puma":
  In snapshot (Gemfile.lock):
    puma (= 3.12.0)

  In Gemfile:
    puma (~> 3.12.0)

    puma-plugin-systemd was resolved to 0.1.1, which depends on
      puma (~> 3.6.0)

Extract systemd class

Hi @sj26. I like the Systemd class you've created here for wrapping sd_notify - it'd be useful to me in other projects if it was a gem.

Would you like to co-maintain or maintain such a gem, or would you mind if I extracted and published it? It looks like the name systemd is available on rubygems.org.

ExecRestart not in systemd documentation

The example service file in the README has an ExecRestart option but there's nothing about this option in the systemd documentation. Is it something that can be enabled somehow?

Support Puma 4

Puma 4 is out and contains some useful features. It'd be great if this was supported but I have no idea what's needed to support it. Is this feasible?

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.