* Fixed a couple remaining issues from the recent merger. Specifically, '$$anvil' was fixed from a bad regex and the path/names of our tools were fixed.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent db8632ca1b
commit 2b9c6c26dc
  1. 3
      Anvil/Tools.pm
  2. 9
      Anvil/Tools/System.pm
  3. 2
      anvil.conf
  4. 32
      tools/anvil-daemon
  5. 62
      tools/anvil-update-states

@ -719,7 +719,8 @@ sub _set_paths
units => "/usr/lib/systemd/system", units => "/usr/lib/systemd/system",
}, },
exe => { exe => {
'anvil-update-states' => "/sbin/anvil/anvil-update-states", 'anvil-prep-database' => "/usr/sbin/anvil/anvil-prep-database",
'anvil-update-states' => "/usr/sbin/anvil/anvil-update-states",
'anvil-report-memory' => "/usr/sbin/anvil-report-memory", 'anvil-report-memory' => "/usr/sbin/anvil-report-memory",
'chmod' => "/usr/bin/chmod", 'chmod' => "/usr/bin/chmod",
'chown' => "/usr/bin/chown", 'chown' => "/usr/bin/chown",

@ -120,11 +120,12 @@ sub call
my $parameter = shift; my $parameter = shift;
my $anvil = $self->parent; my $anvil = $self->parent;
my $debug = 2;
my $line = defined $parameter->{line} ? $parameter->{line} : __LINE__; my $line = defined $parameter->{line} ? $parameter->{line} : __LINE__;
my $shell_call = defined $parameter->{shell_call} ? $parameter->{shell_call} : ""; my $shell_call = defined $parameter->{shell_call} ? $parameter->{shell_call} : "";
my $secure = defined $parameter->{secure} ? $parameter->{secure} : 0; my $secure = defined $parameter->{secure} ? $parameter->{secure} : 0;
my $source = defined $parameter->{source} ? $parameter->{source} : $THIS_FILE; my $source = defined $parameter->{source} ? $parameter->{source} : $THIS_FILE;
$anvil->Log->variables({source => $source, line => $line, level => 3, secure => $secure, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $source, line => $line, level => $debug, secure => $secure, list => { shell_call => $shell_call }});
my $output = "#!error!#"; my $output = "#!error!#";
if (not $shell_call) if (not $shell_call)
@ -136,7 +137,7 @@ sub call
{ {
# Make the system call # Make the system call
$output = ""; $output = "";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => $secure, key => "log_0011", variables => { shell_call => $shell_call }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>) while(<$file_handle>)
{ {
@ -144,7 +145,7 @@ sub call
my $line = $_; my $line = $_;
$line =~ s/\n$//; $line =~ s/\n$//;
$line =~ s/\r$//; $line =~ s/\r$//;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => $secure, key => "log_0017", variables => { line => $line }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, key => "log_0017", variables => { line => $line }});
$output .= $line."\n"; $output .= $line."\n";
} }
close $file_handle; close $file_handle;
@ -152,7 +153,7 @@ sub call
$output =~ s/\n$//s; $output =~ s/\n$//s;
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => $secure, list => { output => $output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, list => { output => $output }});
return($output); return($output);
} }

@ -16,7 +16,7 @@ database::2::password = Initial1
database::2::ping_before_connect = 1 database::2::ping_before_connect = 1
# This is the schema for the ScanCore database. # This is the schema for the ScanCore database.
sys::database::schema = /etc/scancore/scancore.sql sys::database::schema = /usr/sbin/anvil/anvil.sql
# This puts a limit on how many queries (writes, generally) to make in a single batch transaction. This is # This puts a limit on how many queries (writes, generally) to make in a single batch transaction. This is
# useful when doing very large transacions, like resync'ing a large table, by limiting how long a given # useful when doing very large transacions, like resync'ing a large table, by limiting how long a given

@ -20,15 +20,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$| = 1; $| = 1;
my $anvil = Anvil::Tools->new(); my $anvil = Anvil::Tools->new();
$$anvil->Log->level({set => 2}); $anvil->Log->level({set => 2});
# Paths
$$anvil->data->{path}{tools}{'an-prep-database'} = "/usr/sbin/striker/an-prep-database";
$$anvil->data->{path}{tools}{'scancore-update-states'} = "/usr/sbin/striker/scancore-update-states";
$$anvil->data->{path}{config}{'striker.conf'} = "/etc/striker/striker.conf";
# Read our config.
$$anvil->Storage->read_config({file => $$anvil->data->{path}{config}{'striker.conf'}});
# There are some things we only want to run on (re)start and don't need to always run. # There are some things we only want to run on (re)start and don't need to always run.
run_once($anvil); run_once($anvil);
@ -41,14 +33,14 @@ while(1)
# Exit if called with '--run-once' # Exit if called with '--run-once'
if ($$anvil->data->{switches}{'run-once'}) if ($anvil->data->{switches}{'run-once'})
{ {
$$anvil->nice_exit({code => 0}); $anvil->nice_exit({code => 0});
} }
sleep 2; sleep 2;
} }
$$anvil->nice_exit({code => 0}); $anvil->nice_exit({code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #
@ -60,12 +52,12 @@ sub run_once
my ($anvil) = @_; my ($anvil) = @_;
# Check that the database is ready. # Check that the database is ready.
my $shell_call = $$anvil->data->{path}{tools}{'an-prep-database'}; my $shell_call = $anvil->data->{path}{exe}{'anvil-prep-database'};
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $database_output = $$anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); my $database_output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
if ($database_output) if ($database_output)
{ {
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_output => $database_output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_output => $database_output }});
} }
return(0); return(0);
@ -88,13 +80,13 @@ sub update_state_file
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $shell_call = $$anvil->data->{path}{tools}{'scancore-update-states'}; my $shell_call = $anvil->data->{path}{exe}{'anvil-update-states'};
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $states_output = $$anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); my $states_output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
if ($states_output) if ($states_output)
{ {
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { states_output => $states_output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { states_output => $states_output }});
} }
return(0); return(0);

@ -14,12 +14,12 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/; $running_directory =~ s/^\./$ENV{PWD}/;
} }
my $$anvil = Anvil::Tools->new(); my $anvil = Anvil::Tools->new();
$$anvil->Log->level({set => 2}); $anvil->Log->level({set => 2});
$$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
my $connections = $$anvil->Database->connect({ my $connections = $anvil->Database->connect({
sql_file => $$anvil->data->{sys}{database}{schema}, sql_file => $anvil->data->{sys}{database}{schema},
test_table => "network_interfaces", test_table => "network_interfaces",
}); });
@ -40,9 +40,9 @@ sub report_network
my ($anvil) = @_; my ($anvil) = @_;
# Write out the data in json format. # Write out the data in json format.
my $directory = $$anvil->data->{path}{sysfs}{network_interfaces}; my $directory = $anvil->data->{path}{sysfs}{network_interfaces};
local(*DIRECTORY); local(*DIRECTORY);
$$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});
opendir(DIRECTORY, $directory); opendir(DIRECTORY, $directory);
while(my $file = readdir(DIRECTORY)) while(my $file = readdir(DIRECTORY))
{ {
@ -50,17 +50,17 @@ sub report_network
next if $file eq ".."; next if $file eq "..";
next if $file eq "lo"; next if $file eq "lo";
my $full_path = "$directory/$file"; my $full_path = "$directory/$file";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { full_path => $full_path }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { full_path => $full_path }});
if (-d $full_path) if (-d $full_path)
{ {
# Pull out the data I want. # Pull out the data I want.
my $interface = $file; my $interface = $file;
my $mac_address = $$anvil->Storage->read_file({file => $full_path."/address"}); my $mac_address = $anvil->Storage->read_file({file => $full_path."/address"});
my $link_state = $$anvil->Storage->read_file({file => $full_path."/carrier"}); my $link_state = $anvil->Storage->read_file({file => $full_path."/carrier"});
my $mtu = $$anvil->Storage->read_file({file => $full_path."/mtu"}); my $mtu = $anvil->Storage->read_file({file => $full_path."/mtu"});
my $duplex = $$anvil->Storage->read_file({file => $full_path."/duplex"}); # full or half? my $duplex = $anvil->Storage->read_file({file => $full_path."/duplex"}); # full or half?
my $operational = $$anvil->Storage->read_file({file => $full_path."/operstate"}); # up or down my $operational = $anvil->Storage->read_file({file => $full_path."/operstate"}); # up or down
my $speed = $link_state ? $$anvil->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
if ($speed > 100000) if ($speed > 100000)
{ {
# NOTE: This is probably 0 now... Though someday >100 Gbps will be reasonable # NOTE: This is probably 0 now... Though someday >100 Gbps will be reasonable
@ -70,7 +70,7 @@ sub report_network
# Find the media, if possible. # Find the media, if possible.
my $media = "unknown"; my $media = "unknown";
my $ethtool = $$anvil->System->call({shell_call => $$anvil->data->{path}{exe}{ethtool}}); my $ethtool = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{ethtool}});
foreach my $line (split/\n/, $ethtool) foreach my $line (split/\n/, $ethtool)
{ {
if ($line =~ /Supported ports: \[ (.*?) \]/i) if ($line =~ /Supported ports: \[ (.*?) \]/i)
@ -81,7 +81,7 @@ sub report_network
} }
# Log # Log
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
interface => $interface, interface => $interface,
mac_address => $mac_address, mac_address => $mac_address,
link_state => $link_state, link_state => $link_state,
@ -92,7 +92,7 @@ sub report_network
media => $media, media => $media,
}}); }});
$$anvil->Database->insert_or_update_network_interfaces({ $anvil->Database->insert_or_update_network_interfaces({
network_interface_name => $interface, network_interface_name => $interface,
network_interface_duplex => $duplex, network_interface_duplex => $duplex,
network_interface_link_state => $link_state, network_interface_link_state => $link_state,
@ -110,7 +110,7 @@ sub report_network
### TODO: Create $anvil "ip" table and record IPs on this system, linking back to $anvil interface, bond or ### TODO: Create $anvil "ip" table and record IPs on this system, linking back to $anvil interface, bond or
### bridge. ### bridge.
# Run 'ip addr' to see what IPs are in use. # Run 'ip addr' to see what IPs are in use.
$$anvil->System->get_ips; $anvil->System->get_ips;
# Write out the XML file and JSON file. # Write out the XML file and JSON file.
my $order = 1; my $order = 1;
@ -132,14 +132,14 @@ SELECT
FROM FROM
network_interfaces network_interfaces
WHERE WHERE
network_interface_host_uuid = ".$$anvil->data->{sys}{use_db_fh}->quote($$anvil->Get->host_uuid)." network_interface_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
ORDER BY ORDER BY
modified_date DESC modified_date DESC
;"; ;";
$$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
my $results = $$anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
@ -155,7 +155,7 @@ ORDER BY
my $network_interface_medium = defined $row->[7] ? $row->[7] : ""; my $network_interface_medium = defined $row->[7] ? $row->[7] : "";
my $network_interface_bond_uuid = defined $row->[8] ? $row->[8] : ""; my $network_interface_bond_uuid = defined $row->[8] ? $row->[8] : "";
my $network_interface_bridge_uuid = defined $row->[9] ? $row->[9] : ""; my $network_interface_bridge_uuid = defined $row->[9] ? $row->[9] : "";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network_interface_mac_address => $network_interface_mac_address, network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name, network_interface_name => $network_interface_name,
network_interface_speed => $network_interface_speed, network_interface_speed => $network_interface_speed,
@ -175,16 +175,16 @@ ORDER BY
$network_json =~ s/,$//s; $network_json =~ s/,$//s;
$network_json .= "]}\n"; $network_json .= "]}\n";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }});
$network_xml .= "</network>\n"; $network_xml .= "</network>\n";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_xml => $network_xml }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_xml => $network_xml }});
### TODO: Set the 'status/network.json' name into 'striker.conf' ### TODO: Set the 'status/network.json' name into 'striker.conf'
# Write the JSON file. # Write the JSON file.
my $output_json = $$anvil->data->{path}{directories}{html}."/status/network.json"; my $output_json = $anvil->data->{path}{directories}{html}."/status/network.json";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_json }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_json }});
$$anvil->Storage->write_file({ $anvil->Storage->write_file({
file => $output_json, file => $output_json,
body => $network_json, body => $network_json,
overwrite => 1, overwrite => 1,
@ -194,9 +194,9 @@ ORDER BY
}); });
# Write the XML file. # Write the XML file.
my $output_xml = $$anvil->data->{path}{directories}{html}."/status/network.xml"; my $output_xml = $anvil->data->{path}{directories}{html}."/status/network.xml";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_xml }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_xml }});
$$anvil->Storage->write_file({ $anvil->Storage->write_file({
file => $output_xml, file => $output_xml,
body => $network_xml, body => $network_xml,
overwrite => 1, overwrite => 1,

Loading…
Cancel
Save