Created
February 16, 2012 02:05
-
-
Save anonymous/1840950 to your computer and use it in GitHub Desktop.
Pasted form Komodo IDE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ABSTRACT: put some title here when you have time | |
use strict; | |
use warnings; | |
package ANAIO::Cli::Command::web; | |
use 5.001000; | |
use ANAIO::Cli -command; | |
use ANAIO::Config; | |
use Data::Dumper 'Dumper'; | |
$Data::Dumper::Terse = 1; | |
$Data::Dumper::Indent = 0; | |
use Path::Class; | |
use File::Basename 'dirname'; | |
use File::Spec; | |
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), 'lib'; | |
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), '..', 'lib'; | |
use Mojo::Server::Hypnotoad; | |
# VERSION | |
sub abstract { | |
'Start/Stop the Hypnotoad Web Server' | |
} | |
sub opt_spec { | |
return ( | |
[ "start", "Start the Web Server" ], | |
[ "stop", "Stop the Web Server" ], | |
); | |
} | |
sub validate_args { | |
my ( $self, $opt, $args ) = @_; | |
my $params = {}; | |
#$params->{server} = $opt->server() || ''; | |
# | |
#my $input = Pooka::Parameters->new(params => $params); | |
# | |
#$input->queue(qw(+server)); | |
# | |
#unless ($input->validate()) { | |
# $self->usage_error($input->errors_to_string); | |
#} | |
} | |
sub execute { | |
my ( $self, $opt, $args ) = @_; | |
return unless $opt->{stop} xor $opt->{start}; | |
# load config | |
my $config = ANAIO::Config->new; | |
# configure environment | |
$ENV{HYPNOTOAD_EXE} = "$0 web"; | |
$ENV{HYPNOTOAD_APP} = "$0-web"; | |
$ENV{HYPNOTOAD_PID} = "$0-web.pid"; | |
$ENV{HYPNOTOAD_CONFIG} = "$0-web.conf"; | |
$ENV{HYPNOTOAD_STOP} = 1 if $opt->{stop}; | |
do { | |
# Hypnotoad pid/config-file hackery (should be unnecessary) | |
my $toad = $config->settings->{server}->{hypnotoad}; | |
my $file = file($ENV{HYPNOTOAD_CONFIG}); | |
if (my $fh = $file->openw()) { | |
$toad->{pid_file} = $ENV{HYPNOTOAD_PID}; | |
$toad->{lock_file} = $ENV{HYPNOTOAD_APP} . ".lock"; | |
print $fh Dumper($toad); | |
$config->save; | |
} | |
}; | |
# Start hypnotoad | |
Mojo::Server::Hypnotoad->new->run; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment