diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 15a9846f..9e2bbed1 100755 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -1588,6 +1588,12 @@ When C<< anvil-jobs >> picks up a job, it will record it's PID here. This is a numeric value between C<< 0 >> and C<< 100 >>. The job will update this as it runs, with C<< 100 >> indicating that the job is complete. A value of C<< 0 >> will indicate that the job needs to be started. When the daemon picks up the job, it will set this to C<< 1 >>. Any value in between is set by the job itself. +=head3 job_status (optional) + +This is used to tell the user the current status of the job. It can be included when C<< update_progress_only >> is set. + +The expected format is C<< ,!!var1!foo!!,...,!!varN!bar!!\n >>, one key/variable set per line. The new lines will be converted to C<<
\n >> automatically in Striker. + =head3 job_title (required*) This is a string key to display in the title of the box showing that the job is running. @@ -1602,6 +1608,10 @@ This is the C<< job_uuid >> to update. If it is not specified but the C<< job_na * This or C<< job_name >> must be passed +=head3 update_progress_only (optional) + +When set, the progress percentage and, optionally, the C<< job_data >>, will be updated only. + =cut sub insert_or_update_jobs { @@ -1625,6 +1635,7 @@ sub insert_or_update_jobs my $job_progress = defined $parameter->{job_progress} ? $parameter->{job_progress} : 0; my $job_title = defined $parameter->{job_title} ? $parameter->{job_title} : ""; my $job_description = defined $parameter->{job_description} ? $parameter->{job_description} : ""; + my $job_status = defined $parameter->{job_status} ? $parameter->{job_status} : ""; my $update_progress_only = defined $parameter->{update_progress_only} ? $parameter->{update_progress_only} : 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { id => $id, @@ -1641,6 +1652,7 @@ sub insert_or_update_jobs job_progress => $job_progress, job_title => $job_title, job_description => $job_description, + job_status => $job_status, update_progress_only => $update_progress_only, }}); @@ -1774,6 +1786,7 @@ INSERT INTO job_progress, job_title, job_description, + job_status, modified_date ) VALUES ( ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid).", @@ -1787,7 +1800,8 @@ INSERT INTO ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).", ".$anvil->data->{sys}{use_db_fh}->quote($job_title).", ".$anvil->data->{sys}{use_db_fh}->quote($job_description).", - ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." + ".$anvil->data->{sys}{use_db_fh}->quote($job_status).", + ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." ); "; $query =~ s/'NULL'/NULL/g; @@ -1808,7 +1822,8 @@ SELECT job_name, job_progress, job_title, - job_description + job_description, + job_status FROM jobs WHERE @@ -1834,6 +1849,7 @@ WHERE my $old_job_progress = $row->[7]; my $old_job_title = $row->[8]; my $old_job_description = $row->[9]; + my $old_job_status = $row->[10]; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_job_host_uuid => $old_job_host_uuid, old_job_command => $old_job_command, @@ -1845,6 +1861,7 @@ WHERE old_job_progress => $old_job_progress, old_job_title => $old_job_title, old_job_description => $old_job_description, + old_job_status => $old_job_status, }}); # Anything change? @@ -1862,6 +1879,19 @@ SET WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." "; + if ($job_status) + { + $query = " +UPDATE + jobs +SET + job_progress = ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).", + job_status = ".$anvil->data->{sys}{use_db_fh}->quote($job_status).", + modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." +WHERE + job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." +"; + } $query =~ s/'NULL'/NULL/g; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__}); @@ -1878,7 +1908,8 @@ WHERE ($old_job_name ne $job_name) or ($old_job_progress ne $job_progress) or ($old_job_title ne $job_title) or - ($old_job_description ne $job_description)) + ($old_job_description ne $job_description) or + ($old_job_status ne $job_status)) { # Something changed, save. my $query = " @@ -1895,6 +1926,7 @@ SET job_progress = ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).", job_title = ".$anvil->data->{sys}{use_db_fh}->quote($job_title).", job_description = ".$anvil->data->{sys}{use_db_fh}->quote($job_description).", + job_status = ".$anvil->data->{sys}{use_db_fh}->quote($job_status).", modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." diff --git a/share/words.xml b/share/words.xml index 1a3612d2..54e6583b 100644 --- a/share/words.xml +++ b/share/words.xml @@ -36,6 +36,9 @@ Author: Madison Kelly Wrote the journald config file: [#!variable!file!#] to disable rate limiting to ensure high log levels are not lost. The md5sum of: [#!variable!file!#] has changed since the daemon started. Exiting to reload. + The reconfigure of the network has begun. + The hostname: [#!variable!hostname!#] has been set. + Failed to set the hostname: [#!variable!hostname!#]! The hostname is currently [#!variable!bad_hostname!#]. This is probably a program error. Starting: [#!variable!program!#]. diff --git a/tools/anvil-configure-network b/tools/anvil-configure-network index 8d895520..a86d55a4 100755 --- a/tools/anvil-configure-network +++ b/tools/anvil-configure-network @@ -4,6 +4,8 @@ # # Exit codes; # 0 = Normal exit. +# 1 = Job was already picked up by another running instance. +# 2 = The host name did not update properly. # use strict; @@ -81,15 +83,59 @@ sub reconfigure_network }}); # Set the hostname - my $hostnam = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 2}); + my $hostname = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 2}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { hostname => $hostname }}); if ($hostname eq $new_hostname) { # Success + $anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->{job}{uuid}, + update_progress_only => 1, + job_progress => 10, + job_status => "message_0016,!!hostname!$new_hostname!!\n", + }); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0016", variables => { hostname => $new_hostname }}); } else { # Failed + $anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->{job}{uuid}, + update_progress_only => 1, + job_progress => 100, + job_status => "message_0017,!!hostname!$new_hostname!!,!!bad_hostname!$hostname!!\nfailed\n", + }); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "message_0017", variables => { + hostname => $new_hostname, + bad_hostname => $hostname, + }}); + $anvil->nice_exit({code => 2}); + } + + # Now configure the network. + foreach my $network (1..$bcn_count) + { + my $link1_key = "bcn".$network."_iface1_mac"; + my $link2_key = "bcn".$network."_iface2_mac"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + link1_key => $link1_key, + link2_key => $link2_key, + }}); + my $create_bond = 0; + if ((exists $anvil->data->{variables}{form}{config_step2}{$link2_key}{value}) && ($anvil->Validate->is_mac({mac => $anvil->data->{variables}{form}{config_step2}{$link2_key}{value}}))) + { + # Bonded + } + elsif ((exists $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}) && ($anvil->Validate->is_mac({mac => $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}}))) + { + # Single + } + else + { + # Doesn't exist, skip. + } } + =cut print Dumper $anvil->data->{variables}; @@ -196,6 +242,9 @@ LIMIT 1;"; job_progress => $job_progress, }}); + # This will be used when updating the job + $anvil->{job}{uuid} = $job_uuid; + # See if the job was picked up by another running instance. if ($job_picked_up_by) { @@ -261,10 +310,12 @@ AND } # Record that we've picked up this job. - $query = "UPDATE jobs SET job_picked_up_by = ".$$.", job_progress = 1, job_picked_up_at = ".time." WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid).";"; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); - - $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + $anvil->Database->insert_or_update_jobs({ + job_uuid => $anvil->{job}{uuid}, + update_progress_only => 1, + job_progress => 1, + job_status => "message_0015\n", + }); return(0); } diff --git a/tools/anvil-daemon b/tools/anvil-daemon index 99d7ed33..32589d56 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -89,6 +89,8 @@ sub keep_running # Run any pending jobs by calling 'anvil-jobs' with the 'job_uuid' as a background process. + # Check the local network and running services and tune the firewall as things change. + return(0); } diff --git a/tools/anvil.sql b/tools/anvil.sql index 498de87f..09a4cb45 100644 --- a/tools/anvil.sql +++ b/tools/anvil.sql @@ -283,9 +283,10 @@ CREATE TABLE jobs ( job_picked_up_at numeric not null default 0, -- This is unix timestamp of when the job was picked up. job_updated numeric not null default 0, -- This is unix timestamp that is perdiodically updated for jobs that take a long time. It is used to help determine when a job is hung. job_name text not null, -- This is the 'x::y::z' style job name. - job_progress numeric not null, -- An approximate percentage completed. Useful for jobs that that a while and are able to provide data for progress bars. When set to '100', the job is considered completed. + job_progress numeric not null default 0, -- An approximate percentage completed. Useful for jobs that that a while and are able to provide data for progress bars. When set to '100', the job is considered completed. job_title text not null, -- This is a word key for the title of this job job_description text not null, -- This is a word key that describes this job. + job_status text, -- This is a field used to report the status of the job. It is expected to be 'key,!!var1!foo!!,...,!!varN!bar!!' format, one per line. If the last line is 'failed', the job will be understood to have failed. modified_date timestamp with time zone not null, FOREIGN KEY(job_host_uuid) REFERENCES hosts(host_uuid) @@ -305,6 +306,7 @@ CREATE TABLE history.jobs ( job_progress numeric, job_title text, job_description text, + job_status text, modified_date timestamp with time zone not null ); ALTER TABLE history.jobs OWNER TO #!variable!user!#; @@ -327,6 +329,7 @@ BEGIN job_progress, job_title, job_description, + job_status, modified_date) VALUES (history_jobs.job_uuid, @@ -340,6 +343,7 @@ BEGIN history_jobs.job_progress, history_jobs.job_title, history_jobs.job_description, + history_jobs.job_status, history_jobs.modified_date); RETURN NULL; END;