<div dir="ltr"><div>Thanks Amelia (and Chad),<br><br></div>I think I'm goint to stick with the proxy method using Starman behind Apache which seems to work well. Plack::Builder also works nicely to combine apps as you have suggested. <br><br>It would be interesting to know if anyone is running a number of Dancer apps via Apache using the plack handler method as documented in the current deployment guide and how they are finding that performance wise.<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 13, 2016 at 11:51 PM, Amelia Ireland <span dir="ltr"><<a href="mailto:aireland@lbl.gov" target="_blank">aireland@lbl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What do your app.psgi scripts look like? Would it be feasible to combine them into a single file that mounts all your apps?<div><br></div><div>e.g.</div><div><div style="font-size:13px"><div>use Plack::Builder;</div><div><br></div><div>builder {<br></div></div><div style="font-size:13px"><div><span style="white-space:pre-wrap"> mount "/app1" => $app1->();<br></span></div><div><span style="white-space:pre-wrap"> </span>mount "/app2" => $app2->();<br></div><div>};<br></div><div><br></div></div></div><div>If you haven't found it yet, the PSGI/Plack advent calendar has a lot of useful recipes for running and mounting different apps on the same server: <a href="http://advent.plackperl.org/2009/12/index.html" target="_blank">http://advent.plackperl.org/2009/12/index.html</a></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 13 July 2016 at 11:25, janet davis <span dir="ltr"><<a href="mailto:oscarjwoofer@gmail.com" target="_blank">oscarjwoofer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes, it would be fantastic if this method worked and I have tried but I get the following error when switching between app1 and app2. Yes Perl 5.14 sadly, we are due to update to Debian 8 shortly which will bring us up to 5.20.2.<br><div><br>Error while loading /var/www/webapp/app2/bin/app.psgi: Can't locate <a href="http://app2.pm" target="_blank">app2.pm</a> in @INC (@INC contains: /var/www/webapp/app1/bin/../lib /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl . /etc/apache2) at /var/www/webapp/app2/bin/app.psgi line 8.\nBEGIN failed--compilation aborted at /var/www/webapp/app2/bin/app.psgi line 8.<br><br></div><div>App2 will work after a refresh, but them going back to App1 I get:<br></div><div><br></div><div>and<br><br>Error while loading /var/www/webapp/app1/bin/app.psgi: Can't locate <a href="http://app1.pm" target="_blank">app1.pm</a> in @INC (@INC contains: /var/www/webapp/app2/bin/../lib /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl . /etc/apache2) at /var/www/webapp/app1/bin/app.psgi line 8.\nBEGIN failed--compilation aborted at /var/www/webapp/app1/bin/app.psgi line 8<br></div><div><br></div><div>Here's my Apache config:<span><br><Location /app1><br> SetHandler perl-script<br> PerlResponseHandler Plack::Handler::Apache2 <br></span> PerlSetVar psgi_app /var/www/webapp/app1/bin/app.psgi <br><span></Location> <br> <Location /app2> <br> SetHandler perl-script <br> PerlResponseHandler Plack::Handler::Apache2 <br></span> PerlSetVar psgi_app /var/www/webapp/app2/bin/app.psgi <br></Location> <br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 13, 2016 at 5:14 PM, Chad Wallace <span dir="ltr"><<a href="mailto:cwallace@lodgingcompany.com" target="_blank">cwallace@lodgingcompany.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, 13 Jul 2016 14:28:23 +0100<br>
janet davis <<a href="mailto:oscarjwoofer@gmail.com" target="_blank">oscarjwoofer@gmail.com</a>> wrote:<br>
<br>
> Thanks for both of your input, it has really helped a lot.<br>
<br>
You're welcome! But I have another suggestion...<br>
<br>
After re-reading your original post, I looked up the<br>
Plack::Handler::Apache2 option, and it looks like it might be better.<br>
It's at least worth exploring.<br>
<br>
From the example in the deployment guide you mentioned, it looks like<br>
all you'd have to do to your existing virtual host is add a <Location><br>
section for each of your apps, like this:<br>
<br>
<VirtualHost><br>
ServerName www.myserver<br>
<br>
[...]<br>
<br>
<Location /app1><br>
SetHandler perl-script<br>
PerlResponseHandler Plack::Handler::Apache2<br>
PerlSetVar psgi_app /websites/app1/app.psgi<br>
</Location><br>
<Location /app2><br>
SetHandler perl-script<br>
PerlResponseHandler Plack::Handler::Apache2<br>
PerlSetVar psgi_app /websites/app2/app.psgi<br>
</Location><br>
<Location /app3><br>
SetHandler perl-script<br>
PerlResponseHandler Plack::Handler::Apache2<br>
PerlSetVar psgi_app /websites/app3/app.psgi<br>
</Location><br>
<br>
[...]<br>
<br>
</VirtualHost><br>
<br>
That way, your plack apps will start and stop with your apache server.<br>
<br>
I don't have any experience with this approach, so hopefully someone<br>
else can weigh in on the pros and cons. It seems much simpler to me.<br>
<br>
One drawback I can think of is that your apache processes would all<br>
load a copy of perl, Plack, Dancer and all the rest. It may be better<br>
for memory usage to use the proxy method, especially if you have dozens<br>
of apache workers, but only need a few Dancer workers. The impact of<br>
that would depend on the relative weight of your existing website vs.<br>
the new apps, and also whether you already use mod_perl and a lot of<br>
the same modules....<br>
<br>
You should definitely try both methods and see which is best. And be<br>
sure to let us know what you find!<br>
<br>
<br>
> On Wed, Jul 13, 2016 at 12:25 AM, Chad Wallace<br>
> <<a href="mailto:cwallace@lodgingcompany.com" target="_blank">cwallace@lodgingcompany.com</a>> wrote:<br>
><br>
> > On Tue, 12 Jul 2016 22:07:56 +0100<br>
> > janet davis <<a href="mailto:oscarjwoofer@gmail.com" target="_blank">oscarjwoofer@gmail.com</a>> wrote:<br>
> ><br>
> > > The only problem is the uri_base doesn't point to the public<br>
> > > directory in my application root it points to / so no css/js etc.<br>
> > ><br>
> > > I have:<br>
> > > ProxyPass /app1 <a href="http://localhost:5000" rel="noreferrer" target="_blank">http://localhost:5000</a><br>
> > > ProxyPassReverse /app1 <a href="http://localhost:5000" rel="noreferrer" target="_blank">http://localhost:5000</a><br>
> > > And I can reach app1 on <a href="http://myserver.com/app1" rel="noreferrer" target="_blank">myserver.com/app1</a><br>
> > ><br>
> > > Is there anywhere in the config that I can specify the correct<br>
> > > uri_base per app?<br>
> ><br>
> > There's the behind_proxy config option (see Dancer2::Config).<br>
> ><br>
> > > I will try using Plack Builder with some example apps. Are there<br>
> > > any performance implications if I run a lot of Dancer apps in<br>
> > > this way (15+) alongside my cgi scripts? I don't want to go down<br>
> > > this route and then discover that I have issues with server<br>
> > > resources.<br>
> ><br>
> > I'm guessing you'll get better performance with them combined. They<br>
> > should at least use less memory that way, because the single process<br>
> > would load all modules only once, rather than loading one process<br>
> > per app, each with its own copy of perl, Plack, Dancer, Moo, etc.<br>
> ><br>
> > Adding the mounts with Plack::Builder probably doesn't add too much<br>
> > overhead. From what I've seen, Plack and Dancer are both designed<br>
> > to perform and scale well.<br>
> ><br>
> > You could test both methods and compare the results.<br>
> ><br>
> ><br>
> > > On Tue, Jul 12, 2016 at 9:21 PM, Chad Wallace<br>
> > > <<a href="mailto:cwallace@lodgingcompany.com" target="_blank">cwallace@lodgingcompany.com</a>> wrote:<br>
> > ><br>
> > > > On Tue, 12 Jul 2016 19:55:31 +0100<br>
> > > > janet davis <<a href="mailto:oscarjwoofer@gmail.com" target="_blank">oscarjwoofer@gmail.com</a>> wrote:<br>
> > > ><br>
> > > > > Hi there,<br>
> > > > ><br>
> > > > > I have a web server running Apache with a single vhost that<br>
> > > > > serves a lot of Perl cgi scripts from cgi-bin.<br>
> > > > ><br>
> > > > > I've been trying out Dancer, which I really like, but I can't<br>
> > > > > figure out the best way to deploy apps in my Apache<br>
> > > > > environment. I want to keep my Apache cgi configuration to<br>
> > > > > serve legacy scripts but I want to start building new<br>
> > > > > projects based on psgi in something like Dancer.<br>
> > > > ><br>
> > > > > I want Apache to use www.myserver/cgi-bin/appname/<a href="http://script.pl" rel="noreferrer" target="_blank">script.pl</a><br>
> > > > > for old code (which currently works) and www.myserver/app1<br>
> > > > > for newer Dancer based apps. Please don't think I'm being<br>
> > > > > lazy by asking, I have read the documentation and looked at<br>
> > > > > the example for deploying multiple apps via fcgi but I am<br>
> > > > > still confused as I have limited experience with Apache - I<br>
> > > > > am working on that. What's the best way to set this up,<br>
> > > > > bearing in mind that I may want to run say 10-15 Dancer apps<br>
> > > > > from my server alongside my cgi-scripts? Do I have to set up<br>
> > > > > a vhost for each app? I have Apache::Plack::Handler but I'm<br>
> > > > > not sure whether I should be using Plack::Builder to mount my<br>
> > > > > apps (which is mentioned in an older Dancer Cookbook, but not<br>
> > > > > the current deployment guide. Can someone help me get on the<br>
> > > > > right track please?<br>
> > > ><br>
> > > > I'm not sure it matches what you currently have in mind, but<br>
> > > > what I would do is set up www.myserver/app1 with mod_proxy to a<br>
> > > > standalone Plack/Dancer process for the app. You would need<br>
> > > > something like this in your VirtualHost for each app:<br>
> > > ><br>
> > > > ProxyPass /app1 <a href="http://localhost:5000/app1" rel="noreferrer" target="_blank">http://localhost:5000/app1</a><br>
> > > ><br>
> > > > You'd also have to manage starting, stopping and reloading each<br>
> > > > of your apps on its own, with a dedicated port, like 5000 in<br>
> > > > the line above.<br>
> > > ><br>
> > > > If you wanted to combine your apps into one, you can do that<br>
> > > > with Plack::Builder in a single app.psgi script. Then you get<br>
> > > > the benefit of only having one script to start and stop, and<br>
> > > > one port. I currently do that with one of my apps to separate<br>
> > > > the AJAX-specific stuff, based on code I found in<br>
> > > > Dancer2::Cookbook[1]:<br>
> > > ><br>
> > > > #!/usr/bin/env perl<br>
> > > ><br>
> > > > use strict;<br>
> > > > use warnings;<br>
> > > ><br>
> > > > use FindBin;<br>
> > > > use lib "$FindBin::Bin/../lib";<br>
> > > ><br>
> > > > use Plack::Builder;<br>
> > > > use newtlc;<br>
> > > > use newtlc::API;<br>
> > > ><br>
> > > > builder {<br>
> > > > mount '/' => newtlc->to_app;<br>
> > > > mount '/api' => newtlc::API->to_app;<br>
> > > > };<br>
> > > ><br>
> > > ><br>
> > > > [1]<br>
> > > ><br>
> > > ><br>
> > <a href="https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Cookbook.pod#App-specific-feature" rel="noreferrer" target="_blank">https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Cookbook.pod#App-specific-feature</a><br>
> ><br>
> ><br>
> > --<br>
> ><br>
> > C. Chad Wallace, B.Sc.<br>
> > The Lodging Company<br>
> > <a href="http://www.lodgingcompany.com/" rel="noreferrer" target="_blank">http://www.lodgingcompany.com/</a><br>
> > OpenPGP Public Key ID: 0x262208A0<br>
> ><br>
> > _______________________________________________<br>
> > dancer-users mailing list<br>
> > <a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
> > <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
> ><br>
<span><font color="#888888"><br>
<br>
--<br>
<br>
C. Chad Wallace, B.Sc.<br>
The Lodging Company<br>
<a href="http://www.lodgingcompany.com/" rel="noreferrer" target="_blank">http://www.lodgingcompany.com/</a><br>
OpenPGP Public Key ID: 0x262208A0<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</font></span></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>