|XP is just a number|
Re: Change cgi script to PSGI appby tobyink (Abbot)
|on Sep 11, 2014 at 09:00 UTC||Need Help??|
You have several deployment solutions, but they all boil down to an initial choice between two main options:
If you want to serve your app through Apache, mod_perl is usually a fairly simple way to set it up, and a reasonably efficient way to run it, but you've already ruled that out. You can accomplish something similar using FastCGI, though I've always found that trickier to set up.
The final Apache-based way is to deploy a PSGI script as CGI. Just rename your .psgi file to .cgi, mark it as executable (chmod +x), and make sure it includes this shebang line:
Now it's just a regular CGI script, albeit one that uses Plack a lot internally. See Plack::Handler::CGI for details. This is a really easy deployment option, which works just about anywhere. However, because your whole PSGI app needs to be loaded for each request, it's not an especially efficient solution. (For simple apps that don't load a bajillion modules, it's often perfectly acceptable.)
Using a stand-alone server though is generally the most popular option. There are various PSGI servers on CPAN, including Starman and HTTP::Server::PSGI (which comes bundled with Plack). They each have different performance profiles. Generally speaking, you trade CPU for memory. The faster ones take up more memory. The smaller ones are slower. Test out a few, and see which one performs best for your app.
As you have noted, you'll want to run this as a background process, and probably do things like monitor it, to check that it doesn't crash (and automatically restart it if it does crash), and have it auto-restart after a hardware reboot, and so on.
For this I strongly recommend using Ubic to create /etc/rcX.d/-style services. In particular, you'll want the Ubic::Service::Plack plugin (or if you deploy via Starman, Ubic::Service::Starman is another option).
For my personal site, I use an interesting blend of Perl solutions. Most of the site are static HTML pages, generated from Atom by a Perl script, and served though Apache. The e-mail contact form is a PSGI app deployed via CGI. My SPARQL endpoint is another PSGI app running on a stand-alone HTTP::Server::PSGI server, using Ubic to keep it running, and with some custom Ubic plugins to monitor its memory usage, and restart it if the process gets too big. Over-engineering much?
Anyway, I'll stop rambling, but I hope this has been of some help.
TL;DR: use Ubic