From 86a605ba68532d1dd2f9875e7b20c3a81c9f5d31 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 6 May 2017 16:26:43 +0100 Subject: [PATCH] rename daemon to backend in code --- Build.PL | 2 ++ bin/netdisco-backend | 12 +++---- bin/netdisco-backend-fg | 38 ++++++++++----------- lib/App/Netdisco.pm | 15 ++++---- lib/App/Netdisco/Daemon/Worker/Common.pm | 10 +++--- lib/App/Netdisco/Daemon/Worker/Manager.pm | 10 +++--- lib/App/Netdisco/Daemon/Worker/Scheduler.pm | 10 +++--- lib/App/Netdisco/Manual/Deployment.pod | 2 +- lib/App/Netdisco/Manual/Developing.pod | 14 ++++---- lib/App/Netdisco/Manual/Systemd.pod | 20 +++++------ share/environments/deployment.yml | 2 +- 11 files changed, 69 insertions(+), 66 deletions(-) diff --git a/Build.PL b/Build.PL index c890744d..dad71c53 100644 --- a/Build.PL +++ b/Build.PL @@ -89,6 +89,8 @@ Module::Build->new( 'bin/netdisco-db-deploy', 'bin/netdisco-deploy', 'bin/netdisco-do', + 'bin/netdisco-backend-fg', + 'bin/netdisco-backend', 'bin/netdisco-daemon-fg', 'bin/netdisco-daemon', 'bin/netdisco-web-fg', diff --git a/bin/netdisco-backend b/bin/netdisco-backend index a21e554b..7f43b614 100755 --- a/bin/netdisco-backend +++ b/bin/netdisco-backend @@ -46,21 +46,21 @@ use File::Copy; use App::Netdisco::Environment; my $config = ($ENV{PLACK_ENV} || $ENV{DANCER_ENVIRONMENT}) .'.yml'; -my $netdisco = file($FindBin::RealBin, 'netdisco-daemon-fg'); +my $netdisco = file($FindBin::RealBin, 'netdisco-backend-fg'); my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ()); my $log_dir = dir($home, 'logs'); mkdir $log_dir if ! -d $log_dir; -my $log_file = file($log_dir, 'netdisco-daemon.log'); +my $log_file = file($log_dir, 'netdisco-backend.log'); my $uid = (stat($netdisco->stringify))[4] || 0; my $gid = (stat($netdisco->stringify))[5] || 0; Daemon::Control->new({ - name => 'Netdisco Daemon', + name => 'Netdisco Backend', program => \&restarter, program_args => [@args], - pid_file => file($home, 'netdisco-daemon.pid'), + pid_file => file($home, 'netdisco-backend.pid'), stderr_file => $log_file, stdout_file => $log_file, redirect_before_fork => 0, @@ -72,7 +72,7 @@ my $child = 0; sub restarter { my ($daemon, @program_args) = @_; - $0 = 'netdisco-daemon'; + $0 = 'netdisco-backend'; $child = fork_and_start($daemon, @program_args); exit(1) unless $child; @@ -171,7 +171,7 @@ sub rotate_logs { =head1 NAME -netdisco-daemon - Job Control Daemon for Netdisco +netdisco-backend - Job Control Daemon for Netdisco =head1 SEE ALSO diff --git a/bin/netdisco-backend-fg b/bin/netdisco-backend-fg index 17e6aebd..f2c2a05d 100755 --- a/bin/netdisco-backend-fg +++ b/bin/netdisco-backend-fg @@ -24,25 +24,25 @@ use App::Netdisco; use Dancer qw/:moose :script/; warning sprintf "App::Netdisco %s backend", ($App::Netdisco::VERSION || 'HEAD'); -use App::Netdisco::Util::Daemon; +use App::Netdisco::Util::Backend; use NetAddr::IP::Lite ':lower'; # to quench AF_INET6 symbol errors use Role::Tiny::With; # preload all worker modules into shared memory -use App::Netdisco::Daemon::Job (); -use App::Netdisco::Daemon::Util (); -use App::Netdisco::Daemon::Worker::Common (); -use App::Netdisco::Daemon::Worker::Interactive::DeviceActions (); -use App::Netdisco::Daemon::Worker::Interactive::PortActions (); -use App::Netdisco::Daemon::Worker::Manager (); -use App::Netdisco::Daemon::Worker::Poller::Arpnip (); -use App::Netdisco::Daemon::Worker::Poller::Common (); -use App::Netdisco::Daemon::Worker::Poller::Device (); -use App::Netdisco::Daemon::Worker::Poller::Expiry (); -use App::Netdisco::Daemon::Worker::Poller::Macsuck (); -use App::Netdisco::Daemon::Worker::Poller::Nbtstat (); -use App::Netdisco::Daemon::Worker::Poller (); -use App::Netdisco::Daemon::Worker::Scheduler (); +use App::Netdisco::Backend::Job (); +use App::Netdisco::Backend::Util (); +use App::Netdisco::Backend::Worker::Common (); +use App::Netdisco::Backend::Worker::Interactive::DeviceActions (); +use App::Netdisco::Backend::Worker::Interactive::PortActions (); +use App::Netdisco::Backend::Worker::Manager (); +use App::Netdisco::Backend::Worker::Poller::Arpnip (); +use App::Netdisco::Backend::Worker::Poller::Common (); +use App::Netdisco::Backend::Worker::Poller::Device (); +use App::Netdisco::Backend::Worker::Poller::Expiry (); +use App::Netdisco::Backend::Worker::Poller::Macsuck (); +use App::Netdisco::Backend::Worker::Poller::Nbtstat (); +use App::Netdisco::Backend::Worker::Poller (); +use App::Netdisco::Backend::Worker::Scheduler (); use MCE::Signal '-setpgrp'; use MCE::Flow Sereal => 1; @@ -54,7 +54,7 @@ my $tmp_dir = ($ENV{NETDISCO_TEMP} || dir($home, 'tmp')); mkdir $tmp_dir if ! -d $tmp_dir; # process-table text -prctl 'netdisco-daemon: master'; +prctl 'netdisco-backend: master'; # shared local job queue my $queue = MCE::Queue->new; @@ -80,12 +80,12 @@ sub _mk_wkr { my $self = shift; $self->{queue} = $queue; - prctl sprintf 'netdisco-daemon: worker #%s %s: init', MCE->wid, lc($role); + prctl sprintf 'netdisco-backend: worker #%s %s: init', MCE->wid, lc($role); info sprintf 'applying role %s to worker %s', $role, MCE->wid; # post-fork, become manager, scheduler, poller, etc Role::Tiny->apply_roles_to_object( - $self => "App::Netdisco::Daemon::Worker::$role"); + $self => "App::Netdisco::Backend::Worker::$role"); $self->worker_begin if $self->can('worker_begin'); $self->worker_body; @@ -94,7 +94,7 @@ sub _mk_wkr { =head1 NAME -netdisco-daemon-fg - Job Control for Netdisco +netdisco-backend-fg - Job Control for Netdisco =head1 SEE ALSO diff --git a/lib/App/Netdisco.pm b/lib/App/Netdisco.pm index d88c98da..7f20a2ca 100644 --- a/lib/App/Netdisco.pm +++ b/lib/App/Netdisco.pm @@ -134,10 +134,10 @@ Link some of the newly installed apps into a handy location: ln -s ~/perl5/bin/{localenv,netdisco-*} ~/bin/ Test the installation by running the following command, which should only -produce a status message (it's just a test - you'll start the daemon properly, -later on): +produce a status message (it's just a test - you'll start the daemons +properly, later on): - ~/bin/netdisco-daemon status + ~/bin/netdisco-backend status =head1 Configuration @@ -167,8 +167,8 @@ details. The database either needs configuring if new, or updating from the current release of Netdisco (1.x). You also need vendor MAC address prefixes (OUI -data) and some MIBs if you want to run the daemon. The following script will -take care of all this for you: +data) and some MIBs if you want to run the backend daemon. The following +script will take care of all this for you: ~/bin/netdisco-deploy @@ -185,7 +185,7 @@ Run the following command to start the web-app server as a backgrounded daemon Run the following command to start the job control daemon (port control, etc): - ~/bin/netdisco-daemon start + ~/bin/netdisco-backend start You should take care not to run this Netdisco daemon and the Netdisco 1.x daemon at the same time. Similarly, if you use the device discovery with @@ -207,6 +207,7 @@ Notes|App::Netdisco::Manual::ReleaseNotes>. Then, the process is as follows: # upgrade Netdisco ~/bin/localenv cpanm --notest App::Netdisco + ln -s ~/perl5/bin/{localenv,netdisco-*} ~/bin/ # apply database schema updates ~/bin/netdisco-deploy @@ -215,7 +216,7 @@ Notes|App::Netdisco::Manual::ReleaseNotes>. Then, the process is as follows: ~/bin/netdisco-web restart # restart job daemon (if you use it) - ~/bin/netdisco-daemon restart + ~/bin/netdisco-backend restart =head1 Tips and Tricks diff --git a/lib/App/Netdisco/Daemon/Worker/Common.pm b/lib/App/Netdisco/Daemon/Worker/Common.pm index 93df83d4..d9d5b299 100644 --- a/lib/App/Netdisco/Daemon/Worker/Common.pm +++ b/lib/App/Netdisco/Daemon/Worker/Common.pm @@ -1,9 +1,9 @@ -package App::Netdisco::Daemon::Worker::Common; +package App::Netdisco::Backend::Worker::Common; use Dancer qw/:moose :syntax :script/; use Try::Tiny; -use App::Netdisco::Util::Daemon; +use App::Netdisco::Util::Backend; use Role::Tiny; use namespace::clean; @@ -18,7 +18,7 @@ sub worker_body { my $wid = $self->wid; while (1) { - prctl sprintf 'netdisco-daemon: worker #%s poller: idle', $wid; + prctl sprintf 'netdisco-backend: worker #%s poller: idle', $wid; my $job = $self->{queue}->dequeue(1); next unless defined $job; @@ -26,7 +26,7 @@ sub worker_body { try { $job->started(scalar localtime); - prctl sprintf 'netdisco-daemon: worker #%s poller: working on #%s: %s', + prctl sprintf 'netdisco-backend: worker #%s poller: working on #%s: %s', $wid, $job->job, $job->summary; info sprintf "pol (%s): starting %s job(%s) at %s", $wid, $action, $job->job, $job->started; @@ -50,7 +50,7 @@ sub close_job { my ($self, $job) = @_; my $now = scalar localtime; - prctl sprintf 'netdisco-daemon: worker #%s poller: wrapping up %s #%s: %s', + prctl sprintf 'netdisco-backend: worker #%s poller: wrapping up %s #%s: %s', $self->wid, $job->action, $job->job, $job->status; info sprintf "pol (%s): wrapping up %s job(%s) - status %s at %s", $self->wid, $job->action, $job->job, $job->status, $now; diff --git a/lib/App/Netdisco/Daemon/Worker/Manager.pm b/lib/App/Netdisco/Daemon/Worker/Manager.pm index 93badee3..58b5bb76 100644 --- a/lib/App/Netdisco/Daemon/Worker/Manager.pm +++ b/lib/App/Netdisco/Daemon/Worker/Manager.pm @@ -1,9 +1,9 @@ -package App::Netdisco::Daemon::Worker::Manager; +package App::Netdisco::Backend::Worker::Manager; use Dancer qw/:moose :syntax :script/; use List::Util 'sum'; -use App::Netdisco::Util::Daemon; +use App::Netdisco::Util::Backend; use Role::Tiny; use namespace::clean; @@ -35,12 +35,12 @@ sub worker_body { my $wid = $self->wid; if (setting('workers')->{'no_manager'}) { - prctl sprintf 'netdisco-daemon: worker #%s manager: inactive', $wid; + prctl sprintf 'netdisco-backend: worker #%s manager: inactive', $wid; return debug "mgr ($wid): no need for manager... quitting" } while (1) { - prctl sprintf 'netdisco-daemon: worker #%s manager: gathering', $wid; + prctl sprintf 'netdisco-backend: worker #%s manager: gathering', $wid; my $num_slots = 0; $num_slots = parse_max_workers( setting('workers')->{tasks} ) @@ -78,7 +78,7 @@ sub worker_body { } debug "mgr ($wid): sleeping now..."; - prctl sprintf 'netdisco-daemon: worker #%s manager: idle', $wid; + prctl sprintf 'netdisco-backend: worker #%s manager: idle', $wid; sleep( setting('workers')->{sleep_time} || 1 ); } } diff --git a/lib/App/Netdisco/Daemon/Worker/Scheduler.pm b/lib/App/Netdisco/Daemon/Worker/Scheduler.pm index a622fdbf..12c610d6 100644 --- a/lib/App/Netdisco/Daemon/Worker/Scheduler.pm +++ b/lib/App/Netdisco/Daemon/Worker/Scheduler.pm @@ -1,9 +1,9 @@ -package App::Netdisco::Daemon::Worker::Scheduler; +package App::Netdisco::Backend::Worker::Scheduler; use Dancer qw/:moose :syntax :script/; use Algorithm::Cron; -use App::Netdisco::Util::Daemon; +use App::Netdisco::Util::Backend; use Role::Tiny; use namespace::clean; @@ -39,7 +39,7 @@ sub worker_body { my $wid = $self->wid; unless (setting('schedule')) { - prctl sprintf 'netdisco-daemon: worker #%s scheduler: inactive', $wid; + prctl sprintf 'netdisco-backend: worker #%s scheduler: inactive', $wid; return debug "sch ($wid): no need for scheduler... quitting" } @@ -47,11 +47,11 @@ sub worker_body { # sleep until some point in the next minute my $naptime = 60 - (time % 60) + int(rand(45)); - prctl sprintf 'netdisco-daemon: worker #%s scheduler: idle', $wid; + prctl sprintf 'netdisco-backend: worker #%s scheduler: idle', $wid; debug "sched ($wid): sleeping for $naptime seconds"; sleep $naptime; - prctl sprintf 'netdisco-daemon: worker #%s scheduler: queueing', $wid; + prctl sprintf 'netdisco-backend: worker #%s scheduler: queueing', $wid; # NB next_time() returns the next *after* win_start my $win_start = time - (time % 60) - 1; diff --git a/lib/App/Netdisco/Manual/Deployment.pod b/lib/App/Netdisco/Manual/Deployment.pod index 1aaa315e..bb2b01f9 100644 --- a/lib/App/Netdisco/Manual/Deployment.pod +++ b/lib/App/Netdisco/Manual/Deployment.pod @@ -7,7 +7,7 @@ App::Netdisco::Manual::Deployment - Tips and Tricks for Deployment The Netdisco applications will generate RC scripts suitable for Linux systems: bin/netdisco-web get_init_file - bin/netdisco-daemon get_init_file + bin/netdisco-backend get_init_file On C-based systems please see L. diff --git a/lib/App/Netdisco/Manual/Developing.pod b/lib/App/Netdisco/Manual/Developing.pod index 2ef40ab8..b580b281 100644 --- a/lib/App/Netdisco/Manual/Developing.pod +++ b/lib/App/Netdisco/Manual/Developing.pod @@ -51,14 +51,14 @@ directory You might also want to set C to C in your config to quieten some of the web client callbacks. -For the daemon, it's very similar: +For the backend daemon, it's very similar: - DBIC_TRACE=1 ~/bin/localenv bin/netdisco-daemon-fg + DBIC_TRACE=1 ~/bin/localenv bin/netdisco-backend-fg You can point at a different database without editing C: NETDISCO_DBNAME=testdb DBIC_TRACE=1 ~/bin/localenv plackup -R share,lib -p 5001 bin/netdisco-web-fg - NETDISCO_DBNAME=testdb DBIC_TRACE=1 ~/bin/localenv bin/netdisco-daemon-fg + NETDISCO_DBNAME=testdb DBIC_TRACE=1 ~/bin/localenv bin/netdisco-backend-fg It's recommended to delete the "C<~/perl5/lib/perl5/App/Netdisco>" directory to avoid accidentally picking up old Netdisco code. For working on @@ -398,7 +398,7 @@ database connection management features mentioned above. The job daemon is backwards compatible with the old Netdisco database job requests table. All code for the job daemon lives under the -L namespace and like the rest of Netdisco is broken +L namespace and like the rest of Netdisco is broken down into manageable chunks. =head2 Running the Job Daemon @@ -407,10 +407,10 @@ Like the web application, the job daemon is fully self contained and runs via two simple scripts shipped with the distribution - one for foreground and one for background execution (see the user docs for instructions). -The C script uses L to daemonize so you can +The C script uses L to daemonize so you can fire-and-forget the Netdisco job daemon without much trouble at all. This -script in turn calls C which is the real application, that -runs in the foreground if called on its own. +script in turn calls C which is the real application, +that runs in the foreground if called on its own. =head2 Daemon Engineering diff --git a/lib/App/Netdisco/Manual/Systemd.pod b/lib/App/Netdisco/Manual/Systemd.pod index 38b10aad..9fde22e9 100644 --- a/lib/App/Netdisco/Manual/Systemd.pod +++ b/lib/App/Netdisco/Manual/Systemd.pod @@ -10,21 +10,21 @@ instructions apply to your local installation and use at your own risk. =head1 Files -=head2 C<< /etc/systemd/system/netdisco-daemon.service >> +=head2 C<< /etc/systemd/system/netdisco-backend.service >> This should be set mode 644 and owned by user and group C. [Unit] - Description=Netdisco Daemon Service - AssertFileIsExecutable=/home/netdisco/bin/netdisco-daemon + Description=Netdisco Backend Service + AssertFileIsExecutable=/home/netdisco/bin/netdisco-backend After=syslog.target network-online.target [Service] Type=forking User=netdisco Group=netdisco - ExecStart=/home/netdisco/bin/netdisco-daemon start - ExecStop=/home/netdisco/bin/netdisco-daemon stop + ExecStart=/home/netdisco/bin/netdisco-backend start + ExecStop=/home/netdisco/bin/netdisco-backend stop Restart=on-failure RestartSec=60 @@ -38,7 +38,7 @@ This should be set mode 644 and owned by user and group C. [Unit] Description=Netdisco Web Service AssertFileIsExecutable=/home/netdisco/bin/netdisco-web - After=syslog.target network-online.target netdisco-daemon.service + After=syslog.target network-online.target netdisco-backend.service [Service] Type=forking @@ -56,15 +56,15 @@ This should be set mode 644 and owned by user and group C. To enable Netdisco in systemd: - systemctl enable netdisco-daemon.service + systemctl enable netdisco-backend.service systemctl enable netdisco-web.service To start Netdisco: - systemctl start netdisco-daemon.service + systemctl start netdisco-backend.service systemctl start netdisco-web.service -May also need to run C depending on the order you do -these steps. +May also need to run C depending on the +order you do these steps. =cut diff --git a/share/environments/deployment.yml b/share/environments/deployment.yml index 501caac5..fa41ac7e 100644 --- a/share/environments/deployment.yml +++ b/share/environments/deployment.yml @@ -64,7 +64,7 @@ discover_no_type: - '(?i)phone' - '(?i)(?:wap|wireless)' -# number of SNMP workers to run in parallel (in netdisco-daemon). +# number of SNMP workers to run in parallel (in netdisco-backend). # the default is twice the number of CPU cores. increase this if # your system has few cores and the schedule is taking too long. # ```````````````````````````````````````````````````````````````