Skip to content

Instantly share code, notes, and snippets.

@hesco
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hesco/d54fc374e9e3506560b4 to your computer and use it in GitHub Desktop.
Save hesco/d54fc374e9e3506560b4 to your computer and use it in GitHub Desktop.
I seem unable to pull my listen_socket from the configuration. Can anyone please advise?
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN {
unshift @INC, '/opt/local/mojo/lib/perl5';
unshift @INC, "$FindBin::Bin/../lib";
unshift @INC, "$FindBin::Bin/../local";
}
# Start command line interface for application
require Mojolicious::Commands;
# Mojolicious::Commands->start_app('TFC', 'daemon', '-l', 'http://*:8007');
my $mode = $ENV{'MOJO_MODE'};
unless( defined( $mode ) ) {
die "Got |$mode|, please 'export MOJO_MODE=<environment>` and try again";
}
my $app = Mojolicious::Commands->new->app;
my $listen_socket = $app->config->{'default'}->{'listen'} || 8007;
# $app->start( qw/TFC daemon -l/, "http://*:$listen_socket" );
Mojolicious::Commands->start_app('TFC', 'daemon', '-l', "http://*:$listen_socket" );
-----
less conf.d/tfc_dev.conf --
[default]
environment=dev
listen=8009
------
lib/TFC.pm --
sub startup {
my $self = shift;
$self->plugin('INIConfig', {file => 'conf.d/tfc_' . $self->mojo_mode . '.conf'});
}
sub mojo_mode {
my $self = shift;
return $ENV{'MOJO_MODE'};
}
-----
was able to make this work:
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN {
unshift @INC, '/opt/local/mojo/lib/perl5';
unshift @INC, "$FindBin::Bin/../lib";
unshift @INC, "$FindBin::Bin/../local";
}
my $mode = $ENV{'MOJO_MODE'};
unless( defined( $mode ) ) {
die "Got |$mode|, please 'export MOJO_MODE=<environment>` and try again";
}
my %listen_socket = (
'prod' => 80,
'ci_sqlite3' => 8005,
'ci_pg' => 8006,
'uat' => 8007,
'development' => 8008,
'dev' => 8009,
);
# Start command line interface for application
require Mojolicious::Commands;
my $listen_socket = $listen_socket{ $mode };
Mojolicious::Commands->start_app('TFC', 'daemon', '-l', "http://*:$listen_socket" );
-----
although it unfortunately replicates configuration in the script which
more properly belongs in the config files, I think. But this will get me going again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment