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

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)

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);

# 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 {

Source: (StackOverflow)

Serialization of Plack Middlewares

I am trying to serialize the middleware like this -

URL where the request has sent - "'
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  

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


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

end script


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.


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.



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

get '/sessiontest' => sub {

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

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 {
    rotate 10
    create 0660 root root

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


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 []:8080, IPv4
Binding to TCP port 8080 on host 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";
    return $response->finalize;


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.


Source: (StackOverflow)

Perl supervisor plackup starman perlbrew [closed]

I would like to know if there is a Perl tool like supervisord to manage processes.


I have seen a Perl program called Supervisor, but I don't know if it is as good as the Python one:


I want to be able to start a plack server and have a monitor that restart it if necessary.

I use perlbrew, I thought of making a shell script to start the server and then have a configuration like this:

directory = /home/username/my_app
user = username
command = /home/username/wmy_app/starman.sh

Did you used Supervisord for Perl projects with plack, starman and perlbrew. What do you suggest?

My question is open to understand what would be best for my plack server in production.


Source: (StackOverflow)

Starman and MovableType 5.2

MovableType 5.2 has builtin PSGI support (via a mt.psgi in the main directory) and I've been trying to take advantage of it using starman/plackup.

Starman w/ MT fires up, but I get odd Not Founds and a silent hang & fail when I run mt-upgrade.cgi.

How I am running starman:

cd /home/ec2-user/mysite/perl/components/movabletype
plackup -s Starman --port 8045 --error-log /home/ec2-user/mysite/perl/logs/starman.log --pid /home/ec2-user/mysite/perl/var/starman.pid -a mt.psgi

Mystery 1: My browser returns "Not Found" for index.html, but mt-static and mt.cgi is reachable.

X http://mysite:8045/mt/index.html ... Not Found 
✓ http://mysite:8045/mt-static ... listing of static assets 
✓ http://mysite:8045/mt/mt.cgi ... redirects to ... 
X http://mysite:8045/mt/mt-upgrade.cgi?__mode=install ... fails

Mystery 2: Due to the redirect I believe that MT code is running. But it is mostly silent in the starman log even though I have tried different MT debug options. Worse, the mt-upgrade.cgi seems to be reached then fails with this lone message to the starman log:

[mypid] Bootstrap CGI script in non-buffering mode: /home/ec2-user/mysite/perl/components/movabletype/mt-upgrade.cgi

This non-buffering message seems informational and normal, and is coming from the MT codebase.

I have also run directly under starman and get the same result.

Any ideas or help would be appreciated!



linux AMI on an amazon ec2.

perl-5.16.0 under perlbrew.

CPAN modules:

cpanm starman
cpanm CGI::PSGI
cpanm CGI::Parse::PSGI
cpanm CGI::Compile
yum install expat-devel
cpanm XML::Parser
cpanm SOAP::Lite
cpanm SOAP::Transport::HTTP
cpanm XMLRPC::Transport::HTTP::Plack
cpanm DBI
sudo yum install postgresql9-devel
cpanm DBD::Pg
cpanm Task::Plack

MT config:

CGIPath    http://mysite:8045/mt

StaticWebPath    http://mysite:8045/mt-static

PIDFilePath /home/ec2-user/mysite/perl/var/starman.pid

DebugMode 1

ObjectDriver DBI::postgres
Database db
DBUser dbuser
DBPassword dbpass
DBHost dbhost.mysite

Source: (StackOverflow)

How do you use Plack::Middleware::Session with a Starman Server?

I have a Starman based server -

use strict;
use warnings;
use Data::Printer;
use Plack::Builder;

my $app = sub {
    my $env = shift;
    my $session = $env->{'psgix.session'};

    # Print environment variables

    return [
        [ 'Content-Type' => 'text/plain' ],
        [ "Hello, you've been here for ", $session->{counter}++, "th   time!" ],

my $default = sub {
    my $env = shift;
    return [
        '200', [ 'Content-Type' => 'text/html' ],
        ["Welcome to default page"],

builder {
    mount "/validate" => builder {
        enable "Middleware::Authentication"
        enable "Session";
    mount "/" => builder { $default };

My own middleware "Authentication" authenticate the user and return session information(expiry time, session key etc) for the session management, So how can i make use of these information in the Session Middleware?

Source: (StackOverflow)