From d82fe1e2b0c259299d81dca5fdeef343c20643af Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2013 00:19:18 +0000 Subject: [PATCH] refactor web start scripts to be more portable --- Netdisco/Makefile.PL | 6 ++++-- Netdisco/bin/netdisco-web | 21 ++++++++++++--------- Netdisco/bin/netdisco-web-fg | 25 ++++++++++++++++++++++--- Netdisco/lib/App/Netdisco.pm | 2 +- Netdisco/lib/App/Netdisco/Web.pm | 5 ----- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Netdisco/Makefile.PL b/Netdisco/Makefile.PL index b87519ed..5c8d137c 100644 --- a/Netdisco/Makefile.PL +++ b/Netdisco/Makefile.PL @@ -4,6 +4,8 @@ name 'App-Netdisco'; license 'bsd'; all_from 'lib/App/Netdisco.pm'; +requires 'App::cpanminus' => 0; +requires 'App::local::lib::helper' => 0; requires 'DBD::Pg' => 0; requires 'DBD::SQLite' => 0; requires 'DBIx::Class' => 0; @@ -20,11 +22,11 @@ requires 'MCE' => 1.305; requires 'Net::MAC' => 0; requires 'NetAddr::IP' => 0; requires 'Path::Class' => 0; -requires 'Plack' => 0; requires 'Role::Tiny' => 0; +requires 'Socket6' => 0; +requires 'Starman' => 0; requires 'SNMP::Info' => '2.11'; requires 'SQL::Translator' => 0; -requires 'Socket6' => 0; requires 'Template' => 0; requires 'YAML' => 0; requires 'namespace::clean' => 0; diff --git a/Netdisco/bin/netdisco-web b/Netdisco/bin/netdisco-web index b8fed430..c181c097 100755 --- a/Netdisco/bin/netdisco-web +++ b/Netdisco/bin/netdisco-web @@ -2,23 +2,26 @@ use strict; use warnings FATAL => 'all'; + +use FindBin; +FindBin::again(); + use Path::Class; +use Daemon::Control; -BEGIN { - eval "use Daemon::Control"; - if ($@) { - exec(file($ENV{HOME}, 'bin', 'localenv'), $0, @ARGV); - } -} +my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); +my $netdisco = file($FindBin::RealBin, 'netdisco-web-fg'); -my $log_dir = dir($ENV{HOME}, 'logs'); +my $log_dir = dir($home, 'logs'); mkdir $log_dir if ! -d $log_dir; +my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ()); + Daemon::Control->new({ name => 'Netdisco Web', program => 'plackup', - program_args => [file($ENV{HOME}, 'bin', 'netdisco-web-fg')], - pid_file => file($ENV{HOME}, 'netdisco-web.pid'), + program_args => [@args, $netdisco->stringify], + pid_file => file($home, 'netdisco-web.pid'), stderr_file => file($log_dir, 'netdisco-web.log'), stdout_file => file($log_dir, 'netdisco-web.log'), })->run; diff --git a/Netdisco/bin/netdisco-web-fg b/Netdisco/bin/netdisco-web-fg index b001df42..076e662d 100755 --- a/Netdisco/bin/netdisco-web-fg +++ b/Netdisco/bin/netdisco-web-fg @@ -1,9 +1,28 @@ #!/usr/bin/env perl -use FindBin; -use lib "$FindBin::Bin/../lib"; -use App::Netdisco; +use strict; +use warnings FATAL => 'all'; +BEGIN { + # stuff useful locations into @INC and $PATH + use Config; + use FindBin; + FindBin::again(); + use Path::Class 'dir'; + + my $location = $FindBin::RealBin; + $ENV{PATH} = $location . $Config{path_sep} . $ENV{PATH}; + unshift @INC, + dir($location)->parent->subdir('lib')->stringify, + dir($location, 'lib')->stringify; +} + +use App::Netdisco; use Dancer; +debug sprintf "App::Netdisco %s", ($App::Netdisco::VERSION || 'HEAD'); + +my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); +set('session_dir', dir($home, 'netdisco-web-sessions')); + use App::Netdisco::Web; dance; diff --git a/Netdisco/lib/App/Netdisco.pm b/Netdisco/lib/App/Netdisco.pm index c7fac57c..262fda60 100644 --- a/Netdisco/lib/App/Netdisco.pm +++ b/Netdisco/lib/App/Netdisco.pm @@ -7,7 +7,7 @@ use 5.010_000; use File::ShareDir 'dist_dir'; use Path::Class; -our $VERSION = '2.005000_002'; +our $VERSION = '2.005000_003'; BEGIN { if (not length ($ENV{DANCER_APPDIR} || '') diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index 06a89d63..347ed3dc 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -15,11 +15,6 @@ use App::Netdisco::Web::Device; use App::Netdisco::Web::TypeAhead; use App::Netdisco::Web::PortControl; -# need to set at runtime the sessions dir in user home -# because YAML config (session_dir) cannot interpolate $ENV{HOME} -use Path::Class 'dir'; -set('session_dir', dir($ENV{HOME}, 'netdisco-web-sessions')); - sub _load_web_plugins { my $plugin_list = shift;