0

One of the benefits that's always listed when comparing mod_perl vs. fastcgi, is that for mod_perl you have to completely reload the app and have downtime, but with fastcgi you can reload the app without having downtime. However, I cannot find any examples of how to do this. Is this possible to reload a Catalyst app that's being run using fastcgi without any downtime? I followed this guide to get my Catalyst app up and running. Thanks!

srchulo
  • 5,143
  • 4
  • 43
  • 72

2 Answers2

0

Yes. An application running under FastCGI (regardless of whether it uses Catalyst or not) can simply exit; and FastCGI will immediately spawn a replacement process, provided that FastCGI has an AppClass defined for that application and the AppClass is configured with a positive -processes count.

If there is no AppClass or -processes is 0, a replacement process will be created when the next request comes in for the application's URI. This may cause a slight delay for that first request while waiting for the app to start up, but the request will still be handled normally.

In either case, there should be no moment at which an incoming request will be lost or otherwise fail, provided that the application is allowed to exit after completing the current request rather than being interrupted in mid-request (e.g., with kill -9).

Dave Sherohman
  • 45,363
  • 14
  • 64
  • 102
  • so if I were to `kill` each of the pids of my application running underneath FastCGI, these would reload with whatever changes have been made to my application and then I can continue to use it normally? – srchulo May 30 '13 at 18:06
  • Correct. If application processes go away for any reason (killed, exited, crashed...), FastCGI will automatically spawn replacements. – Dave Sherohman May 30 '13 at 19:59
  • I see that FastCGI is respawning processes whenever I kill them, however these processes do not seem to have reloaded in the new code, because I am not seeing the changes that I made. However, if I kill the FastCGI process and then start it up again, then I do see the changes. – srchulo May 30 '13 at 20:19
  • 1
    Yes, that's correct. The new child processes are forked from the parent, and unless you restart the parent, code changes are not seen. The secret is to start a new parent, then kill off the old one. – RET May 30 '13 at 23:35
0

I was able to create a script that does what I want by combining this guide's script and part of the bash script found in this answer. If you put the script in /etc/init.d and then change the appropriate vars at the top, this script can be pretty useful. Calling:

service script reload

or

/etc/init.d/script reload

Allows you to have no downtime while the new code loads up. The script can be found here. You just need to download the script, change the variables at the top, do

chmod +x script

and move it into /etc/init.d, and then you're good to go! :)

Community
  • 1
  • 1
srchulo
  • 5,143
  • 4
  • 43
  • 72