How to restart puma after deploy?

Ruby on-RailsDeploymentCapistrano3Puma

Ruby on-Rails Problem Overview


I'm using Rails, Puma, Capistrano3. I have installed the gem capistrano3-puma as well. I started Puma with Puma Jungle https://github.com/puma/puma/tree/master/tools/jungle/upstart

How do I restart Puma during deployment?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

You can restart manually using the following command

bundle exec pumactl -P /home/deploy/.pids/puma.pid restart

Make sure you point to the correct pid path.

Solution 2 - Ruby on-Rails

Production

If you are using capistrano on production you can:

cap production deploy:restart

Development

If you are on a development environment you can start to look for the pid

ps aux | grep puma

You will see something like this:

user 11654  0.0 13.4 870204 137016 ?       Sl   Jul07   0:39 puma 2.13.4 (tcp://0.0.0.0:3000) [NameOfYourApp]

The number next to the username, in this case 11654 is the process id (PID) of puma server. You can kill it manually and restart the server after. Run this command:

kill -s 15 11654

This command is saying kill the process with id 11654 using signal SIGTERM (code 15). SIGTERM kills the process 'kindly' closing all files, connections, cleaning buffers, etc.

Last you run this command:

puma -e development -p 3000 -d

Puma will be started again in development mode, listening on port 3000 and the execution will be demonized.

Solution 3 - Ruby on-Rails

I ran into the issue where I need to restart puma after some environment changes and did not want to do a full deploy of the application.

I only wanted to restart puma and nginx. Here are the commands that worked for me:

$ bundle exec cap production deploy:restart
$ bundle exec cap production puma:restart

Hope that helps someone

Solution 4 - Ruby on-Rails

As far as I know, if you are using capistrano3-puma gem, you do not need to restart puma explicitly after deployment. There is a task add_default_hooks which does puma:smart_restart after deployment.

You can see the task list by cap -vT. I think cap puma:restart will do the work.

Solution 5 - Ruby on-Rails

cap production puma:stop
cap production puma:start

or

cap production puma:restart

Solution 6 - Ruby on-Rails

Generic answer that will work on any platform and it is supported by Puma server itself, is to use tmp_restart plugin.

Add to your config/puma.rb

plugin :tmp_restart

After that just touch the file (touch tmp/restart.txt) when you want to restart the puma app.

Source: https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmystdeimView Question on Stackoverflow
Solution 1 - Ruby on-RailsJamesDullaghanView Answer on Stackoverflow
Solution 2 - Ruby on-RailsRené MichelView Answer on Stackoverflow
Solution 3 - Ruby on-RailsRay HunterView Answer on Stackoverflow
Solution 4 - Ruby on-RailsSharvy AhmedView Answer on Stackoverflow
Solution 5 - Ruby on-RailsAbdul BasitView Answer on Stackoverflow
Solution 6 - Ruby on-RailsDino ReicView Answer on Stackoverflow