App-EventStreamr
view release on metacpan or search on metacpan
bin/station-mgr.pl view on Meta::CPAN
$self->{config}{run} = 1;
}
# Until found check for dvswitch - continuously hitting dvswitch with an unknown client caused high cpu load
unless ( $self->{dvswitch}{running} && ! $self->{dvswitch}{check} ) {
if ( $utils->port($self->{config}->{mixer}{host},$self->{config}->{mixer}{port}) ) {
$logger->info("DVswitch found Running");
$self->{dvswitch}{running} = 1;
$self->{dvswitch}{check} = 0; # We can set this to 1 and it will check dvswitch again.
}
}
# Uncomment to enable heartbeat
## Post a hearbeat to the controller/mixer
#if ((time % 10) == 0) {
# $logger->debug("Heartbeat!") if ($logger->is_debug());
# $self->{heartbeat} = time;
# post_config();
#}
# Update date if it's changed - I wonder if there is a better way to trigger this? Cron (requires more OS config)?
unless ( $self->{date} == strftime "%Y%m%d", localtime) {
$self->{date} = strftime "%Y%m%d", localtime;
$self->{device_control}{record}{recordpath} = 0;
$self->{config}{device_control}{record}{run} = 2;
$self->{config}{device_control}{sync}{run} = 2;
}
sleep 1;
}
# ---- SUBROUTINES ----------------------------------------------------------
sub sig_exit {
$logger->info("manager exiting...");
$daemons->{main}{run} = 0;
$daemon->Kill_Daemon($self->{device_control}{api}{pid});
$daemon->Kill_Daemon($self->{device_control}{devmon}{pid});
$daemon->Kill_Daemon($self->{device_control}{sync}{pid});
}
sub sig_pipe {
$logger->debug( "caught SIGPIPE" ) if ( $logger->is_debug() );
}
sub self_update {
$logger->info("Performing self update");
$logger->debug("Update host: $Bin/../../baseimage/update-host.sh") if ($logger->is_debug());
system("$Bin/../../baseimage/update-host.sh");
sig_exit();
my $options;
$options = "--debug" if $DEBUG;
$options = "$options --no-daemon" unless $DAEMON;
my $script = File::Basename::basename($0);
$logger->debug("Restart Manger: $Bin/$script $options") if ($logger->is_debug());
exec("$Bin/$script $options") or $logger->logdie("Couldn't restart: $!");
}
sub print_usage {
say "
Usage: station-mgr.pl [OPTIONS]
Options:
--no-deaemon disable daemon
--debug turn on debugging
--help this help text
";
exit 0;
}
# Config triggers
sub post_config {
# Refresh devices
$self->{devices} = $devices->all();
# Post to manager api
my $json = to_json($self);
my %post_data = (
content => $json,
'content-type' => 'application/json',
'content-length' => length($json),
);
my $post = $http->post("http://127.0.0.1:3000/internal/settings", \%post_data);
$logger->info("Config Posted to API");
$logger->debug({filter => \&Data::Dumper::Dumper,
value => $post}) if ($logger->is_debug());
# Status information
my $status;
$status->{status} = $self->{status};
$status->{macaddress} = $self->{config}{macaddress};
$status->{nickname} = $self->{config}{nickname};
# Uncomment for heartbeat
#$status->{heartbeat} = $self->{heartbeat};
# Post Headers
my %headers = (
'station-mgr' => 1,
'Content-Type' => 'application/json',
);
$logger->debug({filter => \&Data::Dumper::Dumper,
value => $status}) if ($logger->is_debug());
# Status Post Data
$json = to_json($status);
%post_data = (
content => $json,
headers => \%headers,
);
# Post Status to Mixer
$post = $http->post("http://$self->{config}{mixer}{host}:3000/status/$self->{config}{macaddress}", \%post_data);
$logger->info("Status Posted to Mixer API -> http://$self->{config}{mixer}{host}:3000/status/$self->{config}{macaddress}");
$logger->debug({filter => \&Data::Dumper::Dumper,
value => $post}) if ($logger->is_debug());
# Post Status + devices to Controller
( run in 2.343 seconds using v1.01-cache-2.11-cpan-2398b32b56e )