From 43ca40e28c455850ea3ebdbbf9636c33fc47acdb Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 5 Jan 2013 20:13:48 +0000 Subject: [PATCH] new scripts which self-localenv, and a daemon web server --- Netdisco/Changes | 1 + Netdisco/bin/netdisco-daemon | 7 ++++++- Netdisco/bin/netdisco-deploy | 1 + Netdisco/bin/netdisco-web | 21 +++++++++++++------ Netdisco/bin/netdisco-web-fg | 9 +++++++++ Netdisco/lib/App/Netdisco.pm | 39 +++++++++++++++++++++--------------- 6 files changed, 55 insertions(+), 23 deletions(-) create mode 100755 Netdisco/bin/netdisco-web-fg diff --git a/Netdisco/Changes b/Netdisco/Changes index 879873b4..f81037db 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,7 @@ * Rewrite of the daemon to use Daemon::Control and MCE (cleaner netdisco code and fewer deps) + * Added daemonized version of the web-app server also using Daemon::Control * Version bump so that we'll be releasing odd numbered beta dists [BUG FIXES] diff --git a/Netdisco/bin/netdisco-daemon b/Netdisco/bin/netdisco-daemon index b82ce269..932330ba 100755 --- a/Netdisco/bin/netdisco-daemon +++ b/Netdisco/bin/netdisco-daemon @@ -3,7 +3,12 @@ use strict; use warnings FATAL => 'all'; -use Daemon::Control; +BEGIN { + eval "use Daemon::Control"; + if ($@) { + exec("$ENV{HOME}/bin/localenv", $0, @ARGV); + } +} my $program = "$ENV{HOME}/bin/netdisco-daemon-fg"; diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy index 97895714..03544407 100755 --- a/Netdisco/bin/netdisco-deploy +++ b/Netdisco/bin/netdisco-deploy @@ -41,6 +41,7 @@ say ' * Internet access'; say ' * Database added to PostgreSQL for Netdisco'; say ' * User added to PostgreSQL with rights to the Netdisco Database'; say ' * "environments/development.yml" file configured with Database dsn/user/pass'; +say ' * A full backup of any existing Netdisco database data'; say ''; say 'You will be asked to confirm all changes to your system.'; say ''; diff --git a/Netdisco/bin/netdisco-web b/Netdisco/bin/netdisco-web index b001df42..8ede034c 100755 --- a/Netdisco/bin/netdisco-web +++ b/Netdisco/bin/netdisco-web @@ -1,9 +1,18 @@ #!/usr/bin/env perl -use FindBin; -use lib "$FindBin::Bin/../lib"; -use App::Netdisco; +use strict; +use warnings FATAL => 'all'; -use Dancer; -use App::Netdisco::Web; -dance; +BEGIN { + eval "use Daemon::Control"; + if ($@) { + exec("$ENV{HOME}/bin/localenv", $0, @ARGV); + } +} + +Daemon::Control->new({ + name => 'Netdisco Web', + program => 'plackup', + program_args => ["$ENV{HOME}/bin/netdisco-web-fg"], + pid_file => "$ENV{HOME}/netdisco-web.pid", +})->run; diff --git a/Netdisco/bin/netdisco-web-fg b/Netdisco/bin/netdisco-web-fg new file mode 100755 index 00000000..b001df42 --- /dev/null +++ b/Netdisco/bin/netdisco-web-fg @@ -0,0 +1,9 @@ +#!/usr/bin/env perl + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use App::Netdisco; + +use Dancer; +use App::Netdisco::Web; +dance; diff --git a/Netdisco/lib/App/Netdisco.pm b/Netdisco/lib/App/Netdisco.pm index 7e50934c..9ff8e925 100644 --- a/Netdisco/lib/App/Netdisco.pm +++ b/Netdisco/lib/App/Netdisco.pm @@ -93,7 +93,7 @@ e.g. C<~netdisco/bin>: Test the installation by running the following command, which should only produce a status message (and throw up no errors): - ~/bin/localenv netdisco-daemon status + ~/bin/netdisco-daemon status =head1 Configuration @@ -126,16 +126,13 @@ from the current release of Netdisco, and apply it yourself: =head1 Startup -Run the following command to start the web server: +Run the following command to start the web-app server as a daemon: - DANCER_ENVDIR=~/environments ~/bin/localenv plackup ~/bin/netdisco-web + DANCER_ENVDIR=~/environments ~/bin/netdisco-web start -Other ways to run and host the web application can be found in the -L page. See also the L documentation. +Run the following command to start the job control daemon (port control, etc): -Run the following command to start the daemon: - - DANCER_ENVDIR=~/environments ~/bin/localenv netdisco-daemon start + DANCER_ENVDIR=~/environments ~/bin/netdisco-daemon start =head1 Tips and Tricks @@ -143,25 +140,35 @@ The main black navigation bar has a search box which is smart enough to work out what you're looking for in most cases. For example device names, node IP or MAC addreses, VLAN numbers, and so on. -For SQL debugging try the following command: +For SQL debugging try the following commands: DBIC_TRACE_PROFILE=console DBIC_TRACE=1 \ - DANCER_ENVDIR=~/environments plackup ~/bin/netdisco-web + DANCER_ENVDIR=~/environments ~/bin/localenv plackup ~/bin/netdisco-web-fg + + DBIC_TRACE_PROFILE=console DBIC_TRACE=1 \ + DANCER_ENVDIR=~/environments ~/bin/localenv netdisco-daemon-fg -To run the job daemon in the foreground, start the C -program instead of C. +Other ways to run and host the web application can be found in the +L page. See also the L documentation. + +With the default configuration user authentication is disabled and the default +"guest" user has no special privilege. To grant port and device control rights +to this user, create a row in the C table of the Netdisco database with +a username of C and the C flag set to true: + + netdisco=> insert into users (username, port_control) values ('guest', true); =head1 Future Work +Bundled with this app is a L layer for the Netdisco database. +This could be a starting point for an "official" DBIC layer. Helper functions +and canned searches have been added to support the web interface. + The intention is to support "plugins" for additonal features, most notably columns in the Device Port listing, but also new menu items and tabs. The design of this is sketched out but not implemented. The goal is to avoid patching core code to add localizations or less widely used features. -Bundled with this app is a L layer for the Netdisco database. -This could be a starting point for an "official" DBIC layer. Helper functions -and canned searches have been added to support the web interface. - =head1 Caveats Some sections are not yet implemented, e.g. the I tab.