rename netdisco-daemon to netdisco-backend
This commit is contained in:
		
							
								
								
									
										109
									
								
								bin/netdisco-backend-fg
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										109
									
								
								bin/netdisco-backend-fg
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,109 @@ | ||||
| #!/usr/bin/env perl | ||||
|  | ||||
| use strict; | ||||
| use warnings; | ||||
|  | ||||
| use FindBin; | ||||
| FindBin::again(); | ||||
| use Path::Class 'dir'; | ||||
|  | ||||
| # get a segfault if we load this later | ||||
| use if $^O eq 'linux', 'Sys::Proctitle'; | ||||
|  | ||||
| BEGIN { | ||||
|   # stuff useful locations into @INC | ||||
|   unshift @INC, | ||||
|     dir($FindBin::RealBin)->parent->subdir('lib')->stringify, | ||||
|     dir($FindBin::RealBin, 'lib')->stringify; | ||||
|  | ||||
|   unshift @INC, | ||||
|     split m/:/, ($ENV{NETDISCO_INC} || ''); | ||||
| } | ||||
|  | ||||
| use App::Netdisco; | ||||
| use Dancer qw/:moose :script/; | ||||
| warning sprintf "App::Netdisco %s backend", ($App::Netdisco::VERSION || 'HEAD'); | ||||
|  | ||||
| use App::Netdisco::Util::Daemon; | ||||
| 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 MCE::Signal '-setpgrp'; | ||||
| use MCE::Flow Sereal => 1; | ||||
| use MCE::Queue; | ||||
|  | ||||
| # 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; | ||||
|  | ||||
| # process-table text | ||||
| prctl 'netdisco-daemon: master'; | ||||
|  | ||||
| # shared local job queue | ||||
| my $queue = MCE::Queue->new; | ||||
|  | ||||
| # support a scheduler-only node | ||||
| setting('workers')->{'no_manager'} = 1 | ||||
|   if setting('workers')->{tasks} eq '0'; | ||||
|  | ||||
| # MCE::Util has a limit of ncpu if AUTO is used in max_workers, | ||||
| # so we parse the field ourselves. | ||||
| my $max_workers = parse_max_workers( setting('workers')->{tasks} ) || 0; | ||||
|  | ||||
| mce_flow { | ||||
|   task_name => [qw/ scheduler manager poller /], | ||||
|   max_workers => [ 1, 1, $max_workers ], | ||||
|   tmp_dir => $tmp_dir, | ||||
|   on_post_exit => sub { MCE->restart_worker }, | ||||
| }, _mk_wkr('Scheduler'), _mk_wkr('Manager'), _mk_wkr('Poller'); | ||||
|  | ||||
| sub _mk_wkr { | ||||
|   my $role = shift; | ||||
|   return sub { | ||||
|     my $self = shift; | ||||
|     $self->{queue} = $queue; | ||||
|  | ||||
|     prctl sprintf 'netdisco-daemon: 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->worker_begin if $self->can('worker_begin'); | ||||
|     $self->worker_body; | ||||
|   }; | ||||
| } | ||||
|  | ||||
| =head1 NAME | ||||
|  | ||||
| netdisco-daemon-fg - Job Control for Netdisco | ||||
|  | ||||
| =head1 SEE ALSO | ||||
|  | ||||
| =over 4 | ||||
|  | ||||
| =item * | ||||
|  | ||||
| L<App::Netdisco> | ||||
|  | ||||
| =back | ||||
|  | ||||
| =cut | ||||
		Reference in New Issue
	
	Block a user