Skip to content

Commit 4ff24a7

Browse files
committed
Add Restart Puma Server By Touching Restart File as a Rails TIL
1 parent 2916fbc commit 4ff24a7

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1603 TILs and counting..._
13+
_1604 TILs and counting..._
1414

1515
See some of the other learning resources I work on:
1616
- [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
10741074
- [Rescue From](rails/rescue-from.md)
10751075
- [Rescue From With A Separate Method](rails/rescue-from-with-a-separate-method.md)
10761076
- [Respond With JSON Regardless of Content Type](rails/respond-with-json-regardless-of-content-type.md)
1077+
- [Restart Puma Server By Touching Restart File](rails/restart-puma-server-by-touching-restart-file.md)
10771078
- [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md)
10781079
- [Rollback A Couple Migrations](rails/rollback-a-couple-migrations.md)
10791080
- [Rollback A Specific Migration Out Of Order](rails/rollback-a-specific-migration-out-of-order.md)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Restart Puma Server By Touching Restart File
2+
3+
Puma includes a plugin that allows us to restart the web server by touching the
4+
`tmp/restart.txt` file.
5+
6+
In one terminal pane I have my Rails server running. In another terminal pane
7+
from the Rails directory, where there exists a `tmp` folder, I run the
8+
following command.
9+
10+
```bash
11+
$ touch tmp/restart.txt
12+
```
13+
14+
Then in the pane running the Rails server, I see the following after a second:
15+
16+
```
17+
* Restarting...
18+
=> Booting Puma
19+
=> Rails 8.0.1 application starting in development
20+
...
21+
```
22+
23+
What is happening is that `touch` updates the modified time of that file, which
24+
already exists in the `temp` directory. When the plugin notices (it checks
25+
every 2 seconds) that the modified time is now fresher than the original
26+
modified time when the plugin started, then it calls `launcher.restart`.
27+
28+
[source](https://github.com/puma/puma/blob/ca201ef69757f8830b636251b0af7a51270eb68a/lib/puma/plugin/tmp_restart.rb)

0 commit comments

Comments
 (0)