[Dancer-users] using Starman for powering dancer apps

Mr. Puneet Kishor punk.kish at gmail.com
Mon Jul 4 00:59:21 CEST 2011


I have been using Dancer exclusively with Apache until now, but in a new environment, I want to experiment with Starman (or any other perl-based server) via Apache proxy. The machine in question is running Apache, and I am not inclined to tinker with that more than the minimum necessary. 

I created an app "foo" in ~/Documents/www. I am able to run it like so 

~/Documents/www/foo$ plackup -E deployment -s Starman --workers=10 -p 5001 -a bin/app.pl
2011/07/03-17:43:13 Starman::Server (type Net::Server::PreFork) starting! pid(3374)
Binding to TCP port 5001 on host *
Setting gid to "501 501 501 401 204 100 98 80 61 12 102 402"

Going to http://127.0.0.1:5001/ gives me my app "foo"

Now, I added the following in the apache conf file

----
ProxyRequests Off

<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>
    
ProxyPass        /foo http://127.0.0.1:5001
ProxyPassReverse /foo http://127.0.0.1:5001
----

and then, going to http://mycomputer.local/foo also returns my app "foo" correctly. Ok, then I added another app "bar" under ~/Documents/www (sibling to "foo"). Now, I am trying to run multiple apps as per the instructions at [http://search.cpan.org/~sukria/Dancer-1.3060/lib/Dancer/Deployment.pod] under the heading "Running multiple apps with Plack::Builder". I created the following web.psgi file in ~/bin

----
use Dancer ':syntax';
use Plack::Builder;

setting apphandler => 'PSGI';

my $app1 = sub {
	my $env = shift;
	setting appdir => '/Users/punkish/Documents/www/foo',
	setting appname => 'foo';
	load_app "foo";
	Dancer::Config->load;
	my $request = Dancer::Request->new( env => $env );
	Dancer->dance( $request );
};

my $app2 = sub {
	my $env = shift;
	setting appdir => '/Users/punkish/Documents/www/bar',
	setting appname => 'bar';
	load_app "bar";
	Dancer::Config->load;
	my $request = Dancer::Request->new( env => $env );
	Dancer->dance( $request );
};

builder {
	mount "/foo" => builder {$app1};
	mount "/bar" => builder {$app2};
};
----

and then I entered the following command:

~/bin$ plackup -E deployment -s Starman --workers=10 -p 5001 -a ~/bin/web.psgi

But, now I get "Not Found" error. So, besides generally seeking guidance for this, I have the following specific questions --

One, in "setting appdir => '/Users/punkish/Documents/www/foo'" what exactly is my appdir? Is '/Users/punkish/Documents/www/foo' correct?

Two, are both "foo" and "bar" going to be accessible at http://127.0.0.1:5001/? Do I just add the following lines to my httpd.conf

----
ProxyPass        /foo http://127.0.0.1:5001
ProxyPassReverse /foo http://127.0.0.1:5001
ProxyPass        /bar http://127.0.0.1:5001
ProxyPassReverse /bar http://127.0.0.1:5001
----

Three, how do I run plackup in the background? I want to run it, but be able to close the shell, and even logout and have it running.

Four, if I have a single web.psgi as above, one disadvantage is that if I tinker with any one app, and have to turn off or restart Starman, it will affect all the apps powered by Starman. Perhaps a better situation would be to have a separate Starman process for each app. What is the best practice here?

Puneet.




More information about the Dancer-users mailing list