How can I handle application cleanup on Phusion Passenger restarts? - passenger

I use Phusion Passenger + Apache to run various applications. At deployment time we take advantage of it's file based restart by touching <<app_dir>>/tmp/restart.txt.
One thing has always eluded me... what does Passenger do to the old process? I've been troubleshooting some cleanup tasks in one of our applications that don't seem to run when passenger stops the process.
The application traps SIGINT and SIGTERM signals so I'm guessing that Passenger isn't using either of them. Does anyone know for certain what passenger does to processes at restart or have experience with the same issue (application cleanup at Passenger restart)?
Any information, ideas, or thoughts would be appreciated.
Thanks,
Tim Birkett.

Related

Passenger keep-alive? (Disable passenger's auto shutdown)

I'm building a service which integrates within slack slash commands. Through the night, passenger automatically shuts down my rails application.
So the next day, the first request will result in a timeout, because passenger is still booting my app.
Is there any way to always keep the application running?
Note: I'm using mod_passenger not passenger standalone.
Either set a minimum number of instances to keep around with PassengerMinInstances or disable idle shutdown all together with PassengerPoolIdleTime

Managing an EventMachine Process with Capistrano

I'm trying to deploy an EventMachine application with Capistrano. Deploying the code looks fairly easily it's how to handle the running process I'm struggling with. I want Capistrano to restart the process if it's already running, otherwise start the process.
I came across a gem called daemon-kit which easily turns a program into a daemon and handles the starting/stopping. It even has recipes for Capistrano!

Does Phusion Passenger start a new Ruby instance for each visitor?

I'm very new to Phusion Passenger. I just know it keeps a limited number of worker threads, and shuts them down after a hour or so of inactivity.
But does it start a new Ruby instance for every request that comes in? Wouldn't that pose a problem if there are multiple users using my app? Is it beneficial to keep around as many instances as possible up and running, so I don't run into any performance issues?
please read this document:
http://www.modrails.com/documentation/Architectural%20overview.html#_spawning_and_caching_of_code_and_applications
Simply said, it does not create ruby instance for every request, because it is not CGI.
I hope this helps.

How to run an EventMachine application on your own production server?

I have just written my first EventMachine application. In development, to start the server, all I do is:
ruby myapp.rb
Which runs my application until I kill it with control+C. In production, this doesn't seem like the right way to do it.
How would I go about running this on my production server?
Check out daemons: http://daemons.rubyforge.org/ - a simple gem written for precisely this use case.
At PostRank we always used God to start/restart our production EventMachine APIs.
I prefer to have a completely external process handling my daemons rather than using something like the daemons library but that's a personnal preference.
You have many solutions out there, here those I know of, all of them will restart your application when it crash more or les quickly and some offer a management interface whether it is a cli or a web interface:
supervisord (http://supervisord.org/): he one I prefer so far
daemontools (http://cr.yp.to/daemontools.html): works well but can be anoying to configure
god as mentionned (http://god.rubyforge.org/): Never used it most for this horrible and cryptic config file syntax
And the last one is whatever comes with your linux distrib, init can run an application and restart it when it dies, you have neary no control over it but it can do the job.
You can type "man inittab" to learn more.

How can I run something in a thread with passenger?

I'm using Phusion Passenger with my nginx to deploy rails/sinatra applications, and I'm currently having a problem.
I want to run a class that checks for new submissions to reddit.com every 30 seconds. But since passenger shuts down the application after x seconds of idle time, it won't keep checking.
Yes, I've tried to set passenger_pool_idle_time to 0, but it still shuts it down.
If you want more details, see the application at github
Thanks in advance.
you could use cron to call into your server ever so often, to make sure it's still running. What may be happening is that passenger is starting up an initial process, then forking it for each worker process it needs later. After awhile, it kills the initial process (thinking it has spawned all the children it ever needs), so setting it to not do that might fix it.

Resources