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)

Serialization of Plack Middlewares

I am trying to serialize the middleware like this -

URL where the request has sent - "127.1.1.1/login/'
On REQUEST_URI = 'login/'

I am executing the Auth and Session middleware like below -

my $app = builder {

    mount "/login" => builder {
        enable "+XYZ::Middleware::Auth";
        mount "/" => builder {
            enable "+XYZ::Middleware::Session";
        };
    };    
};

my $runner = Plack::Runner->new(
    server => 'Starman',
    env    => 'deployment',
    workers => 16  
);
$runner->run($app);

But seems like the session middleware is not executing and the code is stuck on Auth middleware only. As I am processing the $env variable in Auth middleware and then adding some session parameters to $env in Session middleware and finally sending this response to the client.

I want Auth middleware to execute before Session middleware i.e. Auth middleware should execute on login path and then Session middleware should execute on / path. Any idea where I have done the blunder?


Source: (StackOverflow)

'upstart' script for Starman starts, but won't stop if allowed to run for more than a few hours

I need a bit of help with an ubuntu 'upstart' script that runs a Perl Dancer application (myapp) with Starman. This sits behind an nginx front-end.

I'd like it to start automatically when the system starts, stop gracefully when the system stops, and restart itself if it crashes. I'd also like to be able to start|stop|restart it using the standard:

service myapp stop |start|restart

The version below will start, and will also stop/restart if within a few minutes of starting. However it won't stop if allowed to run for more than a few hours.

$ cat /etc/init/myapp.conf

description "myapp on plack/starman"

setuid www-data
start on runlevel [12345]
stop on runlevel [016]

expect fork

script

    exec /usr/bin/plackup -E production -s Starman --workers=3 -l /tmp/myapp.sock -a /home/myapp/www/bin/app.pl

end script

respawn

Ideas? Thanks in advance for any tips.


Source: (StackOverflow)

Dynamic package loading under plackup with Starman

I am running a web app under plackup with starman and trying to dynamically load and instantiate packages based on user requests. I am using 'require $packageName;' to load the package where $packageName contains the name of the package, the names are stored in a config file. I then execute a known set of commands on the instance as all classes inherit from a base class and contain a set of known methods.

This works fine under Apache, but for some reason plackup is saying it cannot locate the package even though @INC contains the library path and the package names are absolute from the last directory in the lib path. That is, the package name would be Base::My::Package.

Anyone experience this issue? Do I need to update some other path within Starman? I am executing plackup with the -I flag as well as updating my environment PERL5LIB variable. I also tried 'use lib /...' in the main app class, but none of these work.

Thanks


Source: (StackOverflow)

Using sessions with perl Dancer/plack/Starman and multiple workers

I'm running a perl Dancer application using Starman via plack (hopefully that is describing things correctly), and mostly this has been a painless experience. I've just recently been trying to get sessions working (really simple stuff - I just want to store a couple of strings, and I am using session: "Simple"), and I am running into really strange issues when running Starman with multiple workers.

Using the following very simple code (at the bottom) results in the following:

Standalone app: Works fine - counter increments when you click on it.

Starman - 1 worker: Works fine

Starman - 2+ workers: The session appears to exist for approximately 1 second, and is subsequently destroyed - the counter always "expires" after a very very short period of time. It doesn't appear to be a worker-specific session, it just resets to nothing. If you hammer the link more than once a second, it increments normally forever (or for as long as I could be bothered to test it).

Am I doing anything wrong, or is this just not going to work? It isn't terribly critical, but it would be nice to be able to get simple sessions working.

Thanks,

Dave

##
## Code to reproduce via:
## plackup -D -E env -s Starman --workers=3 -p 3000 -a myapp.pl
##

get '/sessiontest' => sub {
    return(&sessiontest());
};

sub sessiontest {
  my $testcounter = session 'testcounter' || 0;
  $testcounter++;
  session 'testcounter' => $testcounter;
  info "SESSION COUNTER($testcounter)";
  my $return = <<EOF;
<html>
<body>
<a rel='nofollow' href=\"/sessiontest\">$testcounter</a>
</body>
</html>
EOF
  return($return);
}

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)