Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 25, 2021 02:20 pm GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To