From c4e6e4c8ebe2719d0a59aac212368bb99121cd51 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2013 20:31:00 +0000 Subject: [PATCH] try really hard to find a localenv if one isn't already in place --- Netdisco/bin/netdisco-daemon | 29 ++++++++++++++++++++++------- Netdisco/bin/netdisco-web | 24 +++++++++++++++++++----- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Netdisco/bin/netdisco-daemon b/Netdisco/bin/netdisco-daemon index e85bd003..e42bc152 100755 --- a/Netdisco/bin/netdisco-daemon +++ b/Netdisco/bin/netdisco-daemon @@ -2,25 +2,40 @@ use strict; use warnings FATAL => 'all'; -use Path::Class 'file'; +use FindBin; +FindBin::again(); + +our $home; + +# try really hard to find a localenv if one isn't already in place. BEGIN { + $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; diff --git a/Netdisco/bin/netdisco-web b/Netdisco/bin/netdisco-web index c181c097..7b698fed 100755 --- a/Netdisco/bin/netdisco-web +++ b/Netdisco/bin/netdisco-web @@ -6,17 +6,31 @@ use warnings FATAL => 'all'; use FindBin; FindBin::again(); -use Path::Class; -use Daemon::Control; +our $home; + +# try really hard to find a localenv if one isn't already in place. +BEGIN { + $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"; + } +} + +use Path::Class; -my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); 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; -my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ()); - Daemon::Control->new({ name => 'Netdisco Web', program => 'plackup',