Puma Systemd Plugin
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
ExecRestart=/bin/kill -USR2 $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
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.
Testing
There are few automated tests yet.
There is an example directory which contains a Dockerfile and basic
configuration for testing. To use it:
# Build an image with systemd and puma configured
docker build -t puma-plugin-systemd-example -f example/Dockerfile .
# Start a new container from the image in the background
docker run --name puma-plugin-systemd --privileged --detach --rm puma-plugin-systemd
# Show puma systemd integration
docker exec puma-plugin-systemd-example systemctl status puma
# Stop the container
docker exec puma-plugin-systemd-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.