modify all bin scripts to find localenv and work from git clone

This commit is contained in:
Oliver Gorwits
2013-03-04 20:52:24 +00:00
8 changed files with 112 additions and 37 deletions

View File

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

View File

@@ -2,25 +2,39 @@
use strict;
use warnings FATAL => 'all';
use Path::Class 'file';
use FindBin;
FindBin::again();
our $home;
BEGIN {
# try really hard to find a localenv if one isn't already in place.
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
eval "use Daemon::Control";
if ($@) {
exec(file($ENV{HOME}, 'bin', 'localenv'), $0, @ARGV);
use File::Spec;
my $localenv = File::Spec->catfile($FindBin::RealBin, 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
$localenv = File::Spec->catfile($home, 'perl5', 'bin', 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
die "Sorry, can't find libs required for App::Netdisco.\n";
}
}
use Path::Class;
my $log_dir = dir($ENV{HOME}, 'logs');
mkdir $log_dir if ! -d $log_dir;
my $program = file($ENV{HOME}, 'bin', 'netdisco-daemon-fg');
my $netdisco = file($FindBin::RealBin, 'netdisco-daemon-fg');
my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ());
my $log_dir = dir($home, 'logs');
mkdir $log_dir if ! -d $log_dir;
Daemon::Control->new({
name => 'Netdisco Daemon',
program => ($ENV{NETDISCO_DAEMON} || $program),
pid_file => file($ENV{HOME}, 'netdisco-daemon.pid'),
program => $netdisco,
program_args => [@args],
pid_file => file($home, 'netdisco-daemon.pid'),
stderr_file => file($log_dir, 'netdisco-daemon.log'),
stdout_file => file($log_dir, 'netdisco-daemon.log'),
})->run;

View File

@@ -1,11 +1,20 @@
#!/usr/bin/env perl
use FindBin;
use lib "$FindBin::Bin/../lib";
use App::Netdisco;
FindBin::again();
use Path::Class 'dir';
BEGIN {
# stuff useful locations into @INC
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, 'lib')->stringify;
}
# for netdisco app config
use App::Netdisco;
use Dancer qw/:moose :script/;
info "App::Netdisco version $App::Netdisco::VERSION daemon loaded.";
# callbacks and local job queue management
use App::Netdisco::Daemon::Queue ':all';
@@ -13,15 +22,13 @@ use App::Netdisco::Daemon::Queue ':all';
# needed to quench AF_INET6 symbol errors
use NetAddr::IP::Lite ':lower';
# set temporary MCE files' location in home directory
use Path::Class 'dir';
my $tmp_dir = ($ENV{NETDISCO_TEMP} || dir($ENV{HOME}, 'tmp'));
mkdir $tmp_dir if ! -d $tmp_dir;
use MCE;
use Role::Tiny::With;
info "App::Netdisco version $App::Netdisco::VERSION daemon loaded.";
# set temporary MCE files' location in home directory
my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
my $tmp_dir = ($ENV{NETDISCO_TEMP} || dir($home, 'tmp'));
mkdir $tmp_dir if ! -d $tmp_dir;
my $mce = MCE->new(
spawn_delay => 0.15,

View File

@@ -1,11 +1,36 @@
#!/usr/bin/env perl
use FindBin;
use lib "$FindBin::Bin/../lib";
use App::Netdisco;
FindBin::again();
our $home;
BEGIN {
# try really hard to find a localenv if one isn't already in place.
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
eval "use Daemon::Control";
if ($@) {
use File::Spec;
my $localenv = File::Spec->catfile($FindBin::RealBin, 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
$localenv = File::Spec->catfile($home, 'perl5', 'bin', 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
die "Sorry, can't find libs required for App::Netdisco.\n";
}
}
BEGIN {
# stuff useful locations into @INC
use Path::Class;
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, 'lib')->stringify;
}
use App::Netdisco;
use Dancer ':script';
use Dancer::Plugin::DBIC 'schema';
info "App::Netdisco version $App::Netdisco::VERSION loaded.";
use 5.010_000;
use Term::UI;
@@ -14,7 +39,6 @@ use Term::ReadLine;
use Archive::Extract;
use HTTP::Tiny;
use Try::Tiny;
use Path::Class 'file';
=head1 netdisco-deploy
@@ -31,7 +55,8 @@ Internet, and update the OUI table in the database. Hence Internet access is
required to run the script.
Similarly the latest Netdisco MIB bundle is also downloaded, placed into the
user's home directory, and Netdisco reconfigured for its use.
user's home directory (or C<$ENV{NETDISCO_HOME}>), and Netdisco reconfigured
for its use.
=cut
@@ -109,12 +134,12 @@ sub deploy_oui {
sub deploy_mibs {
my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz';
my $file = file($ENV{HOME}, 'netdisco-mibs-snapshot.tar.gz');
my $file = file($home, 'netdisco-mibs-snapshot.tar.gz');
my $resp = HTTP::Tiny->new->mirror($url, $file);
if ($resp->{success}) {
my $ae = Archive::Extract->new(archive => $file, type => 'tgz');
$ae->extract(to => $ENV{HOME});
$ae->extract(to => $home);
unlink $file;
}

View File

@@ -2,23 +2,39 @@
use strict;
use warnings FATAL => 'all';
use Path::Class;
use FindBin;
FindBin::again();
our $home;
BEGIN {
# try really hard to find a localenv if one isn't already in place.
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
eval "use Daemon::Control";
if ($@) {
exec(file($ENV{HOME}, 'bin', 'localenv'), $0, @ARGV);
use File::Spec;
my $localenv = File::Spec->catfile($FindBin::RealBin, 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
$localenv = File::Spec->catfile($home, 'perl5', 'bin', 'localenv');
exec($localenv, $0, @ARGV) if -f $localenv;
die "Sorry, can't find libs required for App::Netdisco.\n";
}
}
my $log_dir = dir($ENV{HOME}, 'logs');
use Path::Class;
my $netdisco = file($FindBin::RealBin, 'netdisco-web-fg');
my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ());
my $log_dir = dir($home, 'logs');
mkdir $log_dir if ! -d $log_dir;
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;

View File

@@ -1,9 +1,25 @@
#!/usr/bin/env perl
use FindBin;
use lib "$FindBin::Bin/../lib";
use App::Netdisco;
use strict;
use warnings FATAL => 'all';
use FindBin;
FindBin::again();
use Path::Class 'dir';
BEGIN {
# stuff useful locations into @INC
unshift @INC,
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
dir($FindBin::RealBin, '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;

View File

@@ -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} || '')

View File

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