smallseo.info

Starman

Starman is a high-performance preforking Perl PSGI web server Tatsuhiko Miyagawa / Starman - search.cpan.org

Apache/Starman - how to implement lots of different webapps with single virtual host

I have a lot of CGI web applications under apache2, which have complex jQueryUI powered interfaces and corresponding perl backend, based upon CGI::Application framework.

For user it looks like this:

  1. //localsrv.lan/some_report_xls
  2. //localsrv.lan/some_insert_db
  3. //localsrv.lan/some_perl_plsql_stuff etc...

Now I want to turn those apps psgi, which is easy, and somehow run those under Apache->ProxyPass/Starman

  • Should I run Starman for every app using lots of ports for all of them?
  • Should I somehow use mapping url with Plack::App::URLMap and how?
  • Should I create one single app out of all those hundreds to run it with Starman
  • Is there another way to do it?

Source: (StackOverflow)

Supervisor and perlbrew

I try to use supervisor with perlbrew, but I can not make it work. For perlbrew I just tried to set the environment variable that go well, but perhaps it is better to make a script that launches perlbrew and plackup, this my configuration file:

[program:MahewinSimpleBlog]
command = perlbrew use perl-5.14.2 && plackup -E deployment -s Starman --workers=10 -p 4000 -a bin/app.pl -D
directory = /home/hobbestigrou/MahewinSimpleBlog
environment = PERL5LIB ='/home/hobbestigrou/MahewinBlogEngine/lib',PERLBREW_ROOT='/home/hobbestigrou/perl5/perlbrew',PATH='/home/hobbestigrou/perl5/perlbrew/bin:/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games',MANPATH='/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/man:',PERLBREW_VERSION='0.43',PERLBREW_PERL='perl-5.14.2',PERLBREW_MANPATH='/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/man',PERLBREW_SKIP_INIT='1',PERLBREW_PATH='/home/hobbestigrou/perl5/perlbrew/bin:/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/bin',SHLVL='2'
user = hobbestigrou
stdout_file = /home/hobbestigrou/mahewinsimpleblog.log
autostart = true

In the log I see it's not looking at the right place:

Error while loading bin/app.pl: Can't locate Type/Params.pm in @INC (@INC contains: /home/hobbestigrou/MahewinSimpleBlog/lib /home/hobbestigrou/MahewinBlogEngine/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 .) at /home/hobbestigrou/MahewinBlogEngine/lib/MahewinBlogEngine/Article.pm line 5.

I do not see the problem, maybe perlbrew use done other things


Source: (StackOverflow)

uri_for includes port number on redirects

I'm attempting to implement a Catalyst application using nginx as a frontend web proxy for static files, and using Starman for my backend webserver. (I could use Apache & FastCGI and it works just fine, but I'd really like to get the whole PSGI / Plack and Starman thing ironed out)

Starman starts up okay and can handle my requests just fine on http://localhost:5000. When I fire up nginx to use as my front-end proxy, my urls become ugly and mangle with the port number (5000) whenever or wherever I use the $c->uri_for method.

Example :

$c->uri_for("/login")
becomes
http://myapp.example.com:5000/login 
rather than
http://myapp.example.com/login 

I have some logs being created so I can see what X-Forwarded-Host and X-Forwarded-For are set as. For normal requests, there are values set (coming from nginx), but whenever the $c->uri_for method is used, those values do not exist.

Has anyone else had this problem?
Am I missing something else in my configuration of either nginx or my Catalyst conf?

Thanks!

nginx config :

server {
        listen        80;
        server_name   myapp.example.com;

        location /static {
            root /data/users/MyApp/root;
            expires 30d;
        }

        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass http://localhost:5000/;
        }
    }

Event though this will be ran on the same physical server, in MyApp config I have set :

MyApp->config(using_frontend_proxy => 1)

Versions :

Catalyst : 5.80024
nginx : 0.7.67
Plack : 0.9942
Starman : 0.2006

Source: (StackOverflow)

Is there a way to use package/global variables with Dancer and Starman?

I cannot figure out a way to use package variables (or anything of the sort) in Dancer apps when run with Starman. I suppose it is somehow related to Starman's preforking but that is supposed to be a feature, not a bug.

Here's the example Dancer app:

package nafig;
use Dancer;

my $a = 0;
$b = 0;
$nafig::c = 0;

any '/' => sub {
    warn join " ", $a++, $b++, $nafig::c++;
};

start;

Then I make 3 consecutive calls to that app. First, I run it with plack reference server, and everything works as expected:

$ plackup app.pl
HTTP::Server::PSGI: Accepting connections at http://0:5000/
0 0 0 at ... blah-blah-blah
1 1 1 at ... blah-blah-blah
2 2 2 at ... blah-blah-blah

But when I do the same thing with Starman, I get the following.

$ plackup -s Starman app.pl
2013/11/17-23:33:35 Starman::Server (type Net::Server::PreFork) starting! pid(527)
Resolved [*]:5000 to [::]:5000, IPv6
Not including resolved host [0.0.0.0] IPv4 because it will be handled by [::] IPv6
Binding to TCP port 5000 on host :: with IPv6
Setting gid to "1000 1000 20 24 25 29 30 44 46 108 109 115 121 1000"
Starman: Accepting connections at http://*:5000/
0 0 0 at ... blah-blah-blah
0 0 0 at ... blah-blah-blah
0 0 0 at ... blah-blah-blah

However, when refreshing the page quickly, sometimes the values are incremented as expected. I guess, Starman remains in the same fork in those cases.

I'm surprised this question was never asked on stackoverflow before. Persistent variables seem useful to me, how do people dance without them?

Thanks in advance for any help.


Source: (StackOverflow)

Where can I find application runtime errors using Nginx, Starman, Plack and Catalyst?

I have managed successfully to server my Catalyst app on my development machine using Plack + Starman, using a daemon script I based on one I found in Dave Rolsky's Silki distribution.

I then set up nginx to reverse proxy to my Starman server, and aliased the static directory for nginx to serve. So far, so good. However, I am at a loss as to where my application STDERR is supposed to be logging to. It isn't reaching nginx (I suppose that makes sense) but I can't find much documentation as to where Starman may be logging it - if anywhere. I did have a look at Plack's Middleware modules but only saw options for access logs.

Can someone help me?


Source: (StackOverflow)

ZMQ sockets block when Starman receives HUP

I have the following code. I want to call the $pub->close method when the starman server receives the HUP signal.

  • How do I know that the child process ends?
  • Could I use an END {} block? I tried this and it seems to work when plackup restarts (after an edit). I tried this with starman. I sent the HUP signal, but the children aren't restarted.
  • Should I install a signal handlers for HUP? How does that work?

I want to clean up before the child restarts, if I don't the child process will block.

This is the .psgi file that I use.

use ZMQ;
use ZMQ::Constants ':all';
use Plack::Builder;

our $ctx = ZMQ::Context->new(1);
my $pub = $ctx->socket(ZMQ_PUB);
$pub->bind('tcp://127.0.0.1:5998');

# I want to close the socket and terminate the context
# when the server is restarted with kill -HUP pid
# It seems the children won't restart because the sockets isn't closed.
# The next two lines should be called before the child process ends.

# $pub->close;
# $ctx->term;

builder {
    $app
}

Source: (StackOverflow)

How discover on what server runnig the app.psgi?

Is any way to discover on what server running the app.psgi?

e.g, looking for some idea how to solve the next code fragment from app.psgi:

#app.psgi
use Modern::Perl;
use Plack::Builder;
my $app = sub { ... };

my $server = MyApp::GetServerType();  #<--- need some idea, how to write this...

given($server) {
    when (/plackup/) { ... do something ... };
    when (/Starman/) { ... do something other ... };
    default { die "Unknown" };
}

$app;

Checking the PLACK_ENV environment variable is not a solution...


Source: (StackOverflow)

Configuring directory aliases in Starman (or other PSGI servers)

I am used to setting aliases to different directories in Apache httpd.conf. For example, the following works for me

Alias /lib /path/to/lib

Then I can include paths such as <script src="/lib/jquery/plugin/funky.js"></script> no matter what the application path.

I am trying out Starman (and other PSGI servers such as HTTP::Server::PSGI), and can't figure out any way to set configuration parameters such as alias to directories.

Can this be done? How?


Source: (StackOverflow)

Why use nginx with Catalyst/Plack/Starman?

I am trying to deploy my little Catalyst web app using Plack/Starman. All the documentation seems to suggest I want to use this in combination with nginx. What are the benefits of this? Why not use Starman straight up on port 80?


Source: (StackOverflow)

How can Dancer app process HUP signal to close/reopen logfile

I wrote a Dancer app, with the log config:

logger:       file
logger_format: <%T> %m
log_path:     '/usr/local/myapp/log'
log_file:     'myapp.log'
log:          debug

and start it with:

plackup -E deployment -D -s Starman --workers=10 --port 8080 -a bin/app.pl

rotate the log file with logrotate

/usr/local/myapp/log/myapp.log {
    daily
    rotate 10
    create 0660 root root
    compress
    missingok
    dateext
}

but the new logfile is zero.

I tried to add postrotate in logrotate conf to send HUP and process HUP sinal in bin/app.pl with

Dancer::Logger::File::init;

but nothing help.

Can anyone tell me how to rotate the dancer's logfile?


Source: (StackOverflow)

How to proxy a starman request to Apache?

I use starman for my webapp. Apache web server listens on port 8080. I want to rewrite some request like '/request' to this Apache web-server in starman. I try to find some pm, but I found few examples to help me.


Source: (StackOverflow)

Starman eat all the memory with Dancer REST api

I have developed a RESTful application with perl framework Dancer. This application needs almost 1 GB in memory and it takes 30 seconds to be loaded. This application works pretty well in a local test with ./bin/app.pl for a single user, then I try to deploy with Starman (alone or with plackup, with and without keep-alive) for multi-tenant use in several different ways:

plackup -E production -s Starman --workers=10 -p 3000 -a bin/app.pl 
plackup -E production -s Starman --workers=10 -p 3000 -a bin/app.pl --disable-keepalive
plackup -E production -s Starman --workers=10 -p 3000 -a bin/app.pl --disable-keepalive --preload-app
starman --workers=10 -p 3000 -a bin/app.pl

Deployment success, but for each query Starman allocates some memory which never free any more, so the application go out of memory very fast.

I read all the documentation of Starman, PSGI and Dancer deployment, included a very nice explanation of NGINX/Starman/Dancer and a similar error with Starman and memory but it doesn't solve this one, because I disable keep-alive and Starman still keep the memory.

Any idea why Starman is eating my memory? Thanks!


Source: (StackOverflow)

Why starman / plackup don't recommend option -r

I want to start starman with option -r to upgrades source code without to restart server.

starman --workers 32 --port 8080 -r mytest.psgi 
!!
!! Using restarter with -r or -R options is known to cause issues with process supervisor
!! such as start_server, and it is STRONGLY discouraged to use with Starman. You have been warned.
!!
Watching ./lib mytest.psgi for file updates.
2014/11/11-20:28:00 Starman::Server (type Net::Server::PreFork) starting! pid(28380)
Resolved [*]:8080 to [0.0.0.0]:8080, IPv4
Binding to TCP port 8080 on host 0.0.0.0 with IPv4
Setting gid to "1000 1000 24 25 27 29 30 44 46 103 104 107 108 900 1000"
^C2014/11/11-20:28:01 Server closing!

My question is what is the reason for the follwing statement : "STRONGLY discouraged to use with Starman" . Can I use option -r starmann in production ?


Source: (StackOverflow)

How do i use Plack Authentication with Session middleware?

I am having my own written middleware called Authentication and session where Authentication middleware generates the session key and save the session information in cookie upon successful authentication.

Now using above cookie the Session middleware extract the session information and implements the session management.

But somehow i am not able to serialize the above middlewares, so that i can get the cookies created by Authentication middleware in Session middleware.

I tried to build them as below -

my $app = builder {
    mount "/login" => builder {
       enable "+X::Middleware::Authentication"; #This should be called first
       enable "+X::Middleware::Session";
    };
};

And the Authentication middleware simple validate the user to some database and on success generates the session key and save it in cookie.

The Session middleware looks like as -

package X::Middleware::Session;
use Plack::Session::State;

use parent qw(Plack::Middleware);

use warnings;
use strict;

use Moose;

use Data::Dumper;

sub call {
    my $self = shift;
    my($env) = @_;

    # Expecting the cookie information in $env, but its not there
    my $request = Plack::Request->new($env);
    my $session = $request->session;

    $session->{user} = "some";

    $env->{'psgix.session.options'}{change_id} = 1;
    $env->{'psgix.session.options'}{expires}   = 120;

    my $response = Plack::Response->new();

    print "Welcome to X::Middleware::Session Middleware\n\n\n";

    print "X::Middleware::Session::ENV - " . Dumper($env) . "\n";
    $response->status(200);
    return $response->finalize;
}

1;

Is there any problem i am calling the middleware?


Source: (StackOverflow)

Calling 'confess' under Plack/Starman

I have a Plack/Starman application running with TryCatch statements that call 'confess' from the Carp module. However I notice that the confess output is not printing to STDOUT. I've tried routing STDERR output to STDOUT '2>&1', but still don't see anything. I have search for possible error log files with no luck. Where in the world is this printing to? I am sure it's probably a simple answer. Where are the log files located? I am running on a Ubuntu box if that matters.

Thanks


Source: (StackOverflow)