An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
June 25, 2021 02:20 pm GMT
Original Link: https://dev.to/kwstannard/restart-your-rails-server-automatically-5g57
Restart your rails server automatically
I have been working on changes to my config files and testing some middleware and it gets tedious trying remembering to stop and restart the server for each change. Enter fswatch to the rescue.
fswatch -o config other/paths | ruby -e 'while (pid=fork{ exec("be rails s") }) && gets do Process.kill("TERM", pid); Process.waitend'
fswatch sends a message into the pipe anytime the files change. The -o flag batches all changes found into a single message so that we aren't restarting excessively.
The ruby process controls the rails subprocess. fork
will create a Ruby subprocess and then exec
replaces the Ruby process with a Rails subprocess. Any time fswatch sees changes, it will send a string into the pipe and ruby picks it up with gets and sends a TERM signal to Rails to shut it down. Once Rails has shut down, we loop back and start a new Rails subprocess.
Original Link: https://dev.to/kwstannard/restart-your-rails-server-automatically-5g57
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To