1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Restart Puma Server By Touching Restart File as a Rails TIL

This commit is contained in:
jbranchaud
2025-03-01 09:48:48 -06:00
parent 2916fbc3b5
commit 4ff24a7336
2 changed files with 30 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1603 TILs and counting..._
_1604 TILs and counting..._
See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -1074,6 +1074,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Rescue From](rails/rescue-from.md)
- [Rescue From With A Separate Method](rails/rescue-from-with-a-separate-method.md)
- [Respond With JSON Regardless of Content Type](rails/respond-with-json-regardless-of-content-type.md)
- [Restart Puma Server By Touching Restart File](rails/restart-puma-server-by-touching-restart-file.md)
- [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md)
- [Rollback A Couple Migrations](rails/rollback-a-couple-migrations.md)
- [Rollback A Specific Migration Out Of Order](rails/rollback-a-specific-migration-out-of-order.md)

View File

@@ -0,0 +1,28 @@
# Restart Puma Server By Touching Restart File
Puma includes a plugin that allows us to restart the web server by touching the
`tmp/restart.txt` file.
In one terminal pane I have my Rails server running. In another terminal pane
from the Rails directory, where there exists a `tmp` folder, I run the
following command.
```bash
$ touch tmp/restart.txt
```
Then in the pane running the Rails server, I see the following after a second:
```
* Restarting...
=> Booting Puma
=> Rails 8.0.1 application starting in development
...
```
What is happening is that `touch` updates the modified time of that file, which
already exists in the `temp` directory. When the plugin notices (it checks
every 2 seconds) that the modified time is now fresher than the original
modified time when the plugin started, then it calls `launcher.restart`.
[source](https://github.com/puma/puma/blob/ca201ef69757f8830b636251b0af7a51270eb68a/lib/puma/plugin/tmp_restart.rb)