README.adoc in puma-daemon-0.2.2 vs README.adoc in puma-daemon-0.2.3
- old
+ new
@@ -2,29 +2,74 @@
:toc:
:toclevels: 4
:sectnums:
:icons: font
-image:https://github.com/kigster/puma-daemon/workflows/Ruby/badge.svg[link=https://github.com/kigster/puma-daemon/actions?query=workflow%3ARuby]
-image:https://codecov.io/gh/kigster/puma-daemon/branch/master/graph/badge.svg?token=asxarMSGbz[link=https://codecov.io/gh/kigster/puma-daemon]
-image:https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkigster%2Fpuma-daemon.svg?type=shield[link=https://app.fossa.com/projects/git%2Bgithub.com%2Fkigster%2Fpuma-daemon?ref=badge_shield]
-image:https://badge.fury.io/rb/puma-daemon.svg["Gem Version", link="https://badge.fury.io/rb/puma-daemon"]
+[cols="2,7",width="100%",align="center",options="header"]
+|===
-image:https://codecov.io/gh/kigster/puma-daemon/commit/9ebd665764786a9815b159b699087148e19e671a/graphs/sunburst.svg[sunbirst]
+|Badge
+|Type
-== Motivation
+|Test Suite
+|image:https://github.com/kigster/puma-daemon/workflows/Ruby/badge.svg[link=https://github.com/kigster/puma-daemon/actions?query=workflow%3ARuby,width="150"]
-In version 5.0 of the popular Ruby HTTP server https://github.com/puma/puma[Puma] the developers chose to https://github.com/puma/puma/pull/2170/files[drop the daemonization] support from Puma. They did that because the code wasn't actively maintained. Other and perhaps better options now exist (such as `systemd`, etc), not to mention that many people have switched to Kubernetes and Docker, where you generally want to start all servers in the foreground.
-And yet, on occasion, it was rather useful and straightforward to use the built-in daemonization feature that was cross-platform and is now gone. Some folks are still using this feature and are therefore stuck with Puma version 4, or must wrap Puma either in the `systemd` manifest or `launchctl plist` on Mac OS-X, or a Docker container. Well, **not anymore!**
+|Licensing
+|image:https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkigster%2Fpuma-daemon.svg?type=shield[link=https://app.fossa.com/projects/git%2Bgithub.com%2Fkigster%2Fpuma-daemon?ref=badge_shield,width="190"]
-NOTE: Add this gem to your dependencies, and make a one line change either in your `config/puma.rb` file, or use `pumad` binary to start Puma as per usual, and you can even leave `-d` flags there (they are ignored when started via `pumad`, and Puma always goes to the background when started that way).
+|Gem Version
+|image:https://badge.fury.io/rb/puma-daemon.svg["Gem Version",link="https://badge.fury.io/rb/puma-daemon",width="220s"]
-One of the nice features of the old daemonization functionality was that it worked across all platforms.
+|Test Coverage
+|image:https://codecov.io/gh/kigster/puma-daemon/branch/master/graph/badge.svg?token=asxarMSGbz[link=https://codecov.io/gh/kigster/puma-daemon,width="220"]
-So, if you want to use the latest and greatest Puma 5+, but have it self-daemonize, this gem is for you.
+|Coverage Areas
+|image:https://codecov.io/gh/kigster/puma-daemon/branch/master/graphs/sunburst.svg?token=asxarMSGbz[sunbirst,width="30%",link=https://codecov.io/gh/kigster/puma-daemon,float=left] image:https://codecov.io/gh/kigster/puma-daemon/branch/master/graphs/icicle.svg?token=asxarMSGbz[coverage-graph,width="60%",link=https://codecov.io/gh/kigster/puma-daemon,float=right]
+|===
+
+NOTE: You can read this in a nicely formatted https://github.com/kigster/puma-daemon/blob/master/README.pdf[README.pdf] document.
+
+== Usage for the Impatient
+
+1. Add `gem 'puma-daemon'` to your Gemfile. If you prefer, you can add `require: false` (your Rails instances such as Sidekiq will have no use for this gem).
+
+2. You have two options to daemonize Puma using this gem:
+
+a. In your `config/puma.rb` file, add the following line: `require 'puma/daemon'` at the top, and at the bottom call `daemonize`.
+b. Wherever you use `puma` to start it (except using puma-ctl) replace `puma` with `pumad` and daemonization will be enabled automatically.
+
+
+== Introduction
+
+Let's start with the facts: https://github.com/puma/puma[Puma] is the most popular server to run Ruby and Rails applications. It's both multi-threaded and multi-process, making it one of the only servers that can truly saturate your web hardware. While 100% saturation is probably not what you want, the alternative is paying a fortune for under-utilized hardware. A good rule of thumb is to keep your web servers busy around 70-80% most of the time. Puma let's you do that by configuring the number of workers and threads within each worker.
+
+=== What is Daemonization?
+
+Unix processes have the ability to daemonize and go into the background.
+
+This is not a trivial task: to properly daemonize a process must detach the from controlling terminal and run in the background as a system daemon.
+
+In Ruby this is accomplished with the https://ruby-doc.org/core-3.0.1/Process.html#method-c-daemon[Process.daemon] method, which receives two boolean arguments:
+
+* Unless the first argument `nochdir` is `true`, it will change the current working directory to the root (“/”).
+* Unless the second argument `noclose` is true, `daemon()` will also redirect standard input, standard output and standard error to `/dev/null`.
+* Finally, it will return zero on success, or raise one of ` Errno::*` and pass the control to the subsequent Ruby code, which will now continue executing within a daemon.
+
+=== Why was it removed from Puma v5?
+
+For production deployments, tools like `systemd` offer much better alternative, including ability to cap overall memory and CPU consumed by the Puma and all of its workers using Linux cgroups.
+
+The proliferation of Docker deployments meant that Puma is run on the foreground within a Docker container.
+
+Finally, the code which previously daemonized Puma in version 4 was not really maintained, and for this reason was removed from Puma version 5.
+
+=== What does `puma-daemon` do?
+
+We thought that while the core Puma removing daemonization was the right move, it felt useful in some occastions and so we created this gem to restore the daemonization functionality to Puma v5+.
+
== Compatibility
=== Ruby Versions
We did not restore the daemon functionality for JRuby; so at the moment this will work with the MRI distribution, and possibly others that support https://ruby-doc.org/core-2.6.1/Process.html#method-c-daemon[`Process.daemon(true, true)`].
@@ -35,21 +80,23 @@
Currently Puma versions 5 and 6 are supported.
=== Known Issues
-Please see the list of open issues on the https://github.com/kigster/puma-daemon/issues[Issues Page]. Any help is always welcomed.
+Please see the list of open issues on the https://github.com/kigster/puma-daemon/issues[Issues Page].
+Any help is always welcomed.
-== Design Decisions
+=== How it works?
This gem's goal was to surgically augment Puma's source code to restore daemonization by merely requiring `puma/daemon`.
-We accomplished this goal by adding the daemonization call to the routine `output_header()` which is invoked by both `Puma::Single` runner and the `Puma::Cluster` runner at the very beginning of the launch process. While relatively brittle, particularly if the future versions of Puma change this, this approach seems to work with the currently released version of Puma (5 and 6).
+We accomplished this goal by adding the daemonization call to the routine `output_header()` which is invoked by both `Puma::Single` runner and the `Puma::Cluster` runner at the very beginning of the launch process.
+While relatively brittle, particularly if the future versions of Puma change this, this approach seems to work with the currently released version of Puma (5 and 6).
If you run into problems, please https://github.com/kigster/puma-daemon/issues/new[submit an issue].
-== Installation
+== Examples
Add this line to your application's Gemfile:
[source,ruby]
----
@@ -68,34 +115,24 @@
daemonize
----
And then execute:
- $ bundle install
- $ bundle exec puma -C config/puma.rb
+[source,bash]
+----
+bundle install -j 12
+bundle exec puma -C config/puma.rb [rackup.ru]
+----
-Make sure you have `config.ru` Rackup file in the current folder. Checkout the shell script inside the `example` folder for more info.
+Make sure you have `config.ru` Rackup file in the current folder.
+Checkout the shell script inside the `example` folder for more info.
-== Usage
-There were two ways you could daemonize Puma in the past:
+NOTE: Please see the https://github.com/kigster/puma-daemon/tree/master/example[`example`] directory in the source of the gem. It contains `single.sh` and `cluster.sh` scripts that boot Puma via `pumad` binary.
- 1. By specifying `daemonize` or `daemonize(true)` in your config file.
- 2. By specifying `-d` or `--daemonize` on the command line.
+=== Using Config File
-Both of these ways are supported, as long as you do `require 'puma/daemon'` in your puma config file, and — in the case of `-d` flag, you pass it to `pumad` executable, not `puma`.
-
-The recommended way to daemonize is via the provided `pumad` executable, or via the require in `puma.rb` and a subsequent call to `daemonize()` method.
-
-Please note that you must include `puma-daemon` in your Gemfile, but you may specify it as `require: false` — it will only activate if you explicitly require it in your Puma config file.
-
-=== Examples
-
-Please see the https://github.com/kigster/puma-daemon/tree/master/example[`example`] directory in the source of the gem. It contains `single.sh` and `cluster.sh` scripts that boot Puma via `pumad` binary.
-
-=== Daemonizing via the Config File
-
If you want to specify `daemonize` in your config file, simply include `require 'puma/daemon'` at the top of your config file:
[source,ruby]
----
# file: config/puma.rb
@@ -121,27 +158,29 @@
[62235] * Min threads: 0
[62235] * Max threads: 16
[62235] * Environment: development
[62235] * Master PID: 62235
[62235] * Puma Daemon: Daemonizing...
-[62235] * Gem: puma-daemon v0.2.0
+[62235] * Gem: puma-daemon v0.2.2
[62235] * Gem: puma v6.1.1
[62258] * Workers: 4
[62258] * Restarts: (✔) hot (✔) phased
[62258] * Listening on unix:///tmp/puma.sock
[62258] * Listening on http://0.0.0.0:9292
----
Note that using this method you can decide whether to daemonize or not by passing true or false to the `daemonize` method.
-=== Daemonizing on the Command Line
+=== Using Command Line
If you prefer to make a decision whether to daemonize or not on the command line, you only have to make one chance: replace `puma` with `pumad`.
-NOTE: We did not want to conflict with the `puma` gem by introducing another executable under the same name. The executable this gem provides is called `pumad` (where 'd' stands for daemon, and follows standard UNIX convention, as in eg `sshd`, `ftpd`, etc).
+NOTE: We did not want to conflict with the `puma` gem by introducing another executable under the same name.
+The executable this gem provides is called `pumad` (where 'd' stands for daemon, and follows standard UNIX convention, as in eg `sshd`, `ftpd`, etc).
-If you replace `puma` with `pumad`, you no longer need to pass any additional command line flag (`-d` and `--daemonize`) to daemonize. You can continue passing them or you can remove them (these flags are stripped out before ARGV is passed onto Puma's CLI parser.)
+If you replace `puma` with `pumad`, you no longer need to pass any additional command line flag (`-d` and `--daemonize`) to daemonize.
+You can continue passing them or you can remove them (these flags are stripped out before ARGV is passed onto Puma's CLI parser.)
[source,bash]
----
❯ cd example
❯ ../exe/pumad -C $(pwd)/puma.rb -w 0 config.ru
@@ -151,26 +190,35 @@
* Min threads: 0
* Max threads: 16
* Environment: development
* PID: 63179
* Puma Daemon: Daemonizing...
-* Gem: puma-daemon v0.2.0
+* Gem: puma-daemon v0.2.2
* Gem: puma v6.1.1
* Listening on unix:///tmp/puma.sock
* Listening on http://0.0.0.0:9292
----
As you can see, at the end it says "Daemonizing".
-If you start puma this way, you can still specify `daemonize(false)` in the configuration file to turn it off, but the default is to daemonize. Also, if you start with `pumad` you do not need to include `require 'puma/daemon'` in your configuration file, as the `pumad` binary loads all dependencies prior to parsing the config.
+If you start puma this way, you can still specify `daemonize(false)` in the configuration file to turn it off, but the default is to daemonize.
+Also, if you start with `pumad` you do not need to include `require 'puma/daemon'` in your configuration file, as the `pumad` binary loads all dependencies prior to parsing the config.
-== Development
+== Contributing
-After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
+NOTE: You do need a working `make` utility to use the below commands.
-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 the created tag, and push the `.gem` file to https://rubygems.org[rubygems.org].
+ * After checking out the repo, run `make puma-v5` or `make puma-v6` to configure your dependent vesion of Puma.
-== Contributing
+ * After that, run `bin/setup` to install dependencies.
+
+ * Then, run `rake spec` to run the tests.
+
+ * You can also run `bin/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 the created tag, and push the `.gem` file to https://rubygems.org[rubygems.org].
Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/puma-daemon.
== License