* Created System->hostname() to get and optionally set the hostname (static and pretty).
* Got anvil-configure-network setting the new hostname. * Updated anvil-configure-network to exit only if the job was picked up by a still-running PID. Signed-off-by: Digimer <digimer@alteeve.ca>
This commit is contained in:
parent
217dfaedc7
commit
d86750ba01
@ -767,6 +767,7 @@ sub _set_paths
|
|||||||
'firewall-cmd' => "/usr/bin/firewall-cmd",
|
'firewall-cmd' => "/usr/bin/firewall-cmd",
|
||||||
gethostip => "/usr/bin/gethostip",
|
gethostip => "/usr/bin/gethostip",
|
||||||
hostname => "/usr/bin/hostname",
|
hostname => "/usr/bin/hostname",
|
||||||
|
hostnamectl => "/usr/bin/hostnamectl",
|
||||||
ip => "/usr/sbin/ip",
|
ip => "/usr/sbin/ip",
|
||||||
'iptables-save' => "/usr/sbin/iptables-save",
|
'iptables-save' => "/usr/sbin/iptables-save",
|
||||||
journalctl => "/usr/bin/journalctl",
|
journalctl => "/usr/bin/journalctl",
|
||||||
|
@ -20,6 +20,7 @@ my $THIS_FILE = "System.pm";
|
|||||||
# determine_host_type
|
# determine_host_type
|
||||||
# enable_daemon
|
# enable_daemon
|
||||||
# get_ips
|
# get_ips
|
||||||
|
# hostname
|
||||||
# is_local
|
# is_local
|
||||||
# manage_firewall
|
# manage_firewall
|
||||||
# ping
|
# ping
|
||||||
@ -421,10 +422,73 @@ sub get_ips
|
|||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::networks::${in_iface}::mac" => $anvil->data->{sys}{networks}{$in_iface}{mac} }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::networks::${in_iface}::mac" => $anvil->data->{sys}{networks}{$in_iface}{mac} }});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 hostname
|
||||||
|
|
||||||
|
Get our set the local hostname. The current host name (or the new hostname if C<< set >> was used) is returned as a string.
|
||||||
|
|
||||||
|
Parameters;
|
||||||
|
|
||||||
|
=head3 set (optional)
|
||||||
|
|
||||||
|
If set, this will become the new host name.
|
||||||
|
|
||||||
|
=head3 pretty (optional)
|
||||||
|
|
||||||
|
If set, this will be set as the "pretty" host name.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
sub hostname
|
||||||
|
{
|
||||||
|
my $self = shift;
|
||||||
|
my $parameter = shift;
|
||||||
|
my $anvil = $self->parent;
|
||||||
|
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->_is_local()" }});
|
||||||
|
|
||||||
|
my $pretty = $parameter->{pretty} ? $parameter->{pretty} : "";
|
||||||
|
my $set = $parameter->{set} ? $parameter->{set} : "";
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||||||
|
pretty => $pretty,
|
||||||
|
set => $set,
|
||||||
|
}});
|
||||||
|
|
||||||
|
# Set
|
||||||
|
if ($set)
|
||||||
|
{
|
||||||
|
# TODO: Sanity check the host name
|
||||||
|
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." set-hostname $set";
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
|
||||||
|
|
||||||
|
my $output = $anvil->System->call({shell_call => $shell_call});
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pretty
|
||||||
|
if ($pretty)
|
||||||
|
{
|
||||||
|
# TODO: Escape this for bash properly
|
||||||
|
# $pretty =~ s/"/\\"/g;
|
||||||
|
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." set-hostname --pretty \"$pretty\"";
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
|
||||||
|
|
||||||
|
my $output = $anvil->System->call({shell_call => $shell_call});
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get
|
||||||
|
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." --static";
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
|
||||||
|
|
||||||
|
my $hostname = $anvil->System->call({shell_call => $shell_call});
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { hostname => $hostname }});
|
||||||
|
|
||||||
|
return($hostname);
|
||||||
|
}
|
||||||
|
|
||||||
=head2 is_local
|
=head2 is_local
|
||||||
|
|
||||||
This method takes a host name or IP address and looks to see if it matches the local system. If it does, it returns C<< 1 >>. Otherwise it returns C<< 0 >>.
|
This method takes a host name or IP address and looks to see if it matches the local system. If it does, it returns C<< 1 >>. Otherwise it returns C<< 0 >>.
|
||||||
|
@ -217,6 +217,7 @@ The database connection error was:
|
|||||||
<key name="log_0144">PostgreSQL server is not installed, unable to proceed.</key>
|
<key name="log_0144">PostgreSQL server is not installed, unable to proceed.</key>
|
||||||
<key name="log_0145"><![CDATA[[ Warning ] - Unable to use the database on the host: [#!variable!host!#]. The local Anvil! version is: [#!variable!local_version!#], and the target host's is: [#!variable!target_version!#]. If you are upgrading, we will resync and use it once the host and our version is again the same.]]></key>
|
<key name="log_0145"><![CDATA[[ Warning ] - Unable to use the database on the host: [#!variable!host!#]. The local Anvil! version is: [#!variable!local_version!#], and the target host's is: [#!variable!target_version!#]. If you are upgrading, we will resync and use it once the host and our version is again the same.]]></key>
|
||||||
<key name="log_0146">A job to configure the network was found, but it has already been picked up by: [#!variable!pid!#].</key>
|
<key name="log_0146">A job to configure the network was found, but it has already been picked up by: [#!variable!pid!#].</key>
|
||||||
|
<key name="log_0147">A job to configure the network was found, and it was picked up by: [#!variable!pid!#], but that process is not running and it appears to only be: [#!variable!percent!# %] complete. Taking the job.</key>
|
||||||
|
|
||||||
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
|
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
|
||||||
<key name="t_0000">Test</key>
|
<key name="t_0000">Test</key>
|
||||||
|
@ -61,24 +61,35 @@ sub reconfigure_network
|
|||||||
{
|
{
|
||||||
my ($anvil) = @_;
|
my ($anvil) = @_;
|
||||||
|
|
||||||
my $prefix = $anvil->data->{variables}{form}{config_step1}{prefix}{value};
|
my $prefix = $anvil->data->{variables}{form}{config_step1}{prefix}{value};
|
||||||
my $sequence = $anvil->data->{variables}{form}{config_step1}{sequence}{value};
|
my $sequence = $anvil->data->{variables}{form}{config_step1}{sequence}{value};
|
||||||
my $domain = $anvil->data->{variables}{form}{config_step1}{domain}{value};
|
my $domain = $anvil->data->{variables}{form}{config_step1}{domain}{value};
|
||||||
my $organization = $anvil->data->{variables}{form}{config_step1}{organization}{value};
|
my $organization = $anvil->data->{variables}{form}{config_step1}{organization}{value};
|
||||||
my $bcn_count = 1; # TODO: This should be coming from the form, even though it's only '1' for now.
|
my $bcn_count = 1; # TODO: This should be coming from the form, even though it's only '1' for now.
|
||||||
my $ifn_count = $anvil->data->{variables}{form}{config_step1}{ifn_count}{value};
|
my $ifn_count = $anvil->data->{variables}{form}{config_step1}{ifn_count}{value};
|
||||||
my $new_hostname = $prefix."-striker".sprintf("%02d", $sequence).".".$domain;
|
my $new_hostname = $prefix."-striker".sprintf("%02d", $sequence).".".$domain;
|
||||||
|
my $pretty_hostname = $organization." - Striker ".sprintf("%02d", $sequence);
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||||||
prefix => $prefix,
|
prefix => $prefix,
|
||||||
sequence => $sequence,
|
sequence => $sequence,
|
||||||
domain => $domain,
|
domain => $domain,
|
||||||
organization => $organization,
|
organization => $organization,
|
||||||
bcn_count => $bcn_count,
|
bcn_count => $bcn_count,
|
||||||
ifn_count => $ifn_count,
|
ifn_count => $ifn_count,
|
||||||
new_hostname => $new_hostname,
|
new_hostname => $new_hostname,
|
||||||
|
pretty_hostname => $pretty_hostname,
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
# Set the hostname
|
||||||
|
my $hostnam = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 2});
|
||||||
|
if ($hostname eq $new_hostname)
|
||||||
|
{
|
||||||
|
# Success
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
# Failed
|
||||||
|
}
|
||||||
=cut
|
=cut
|
||||||
print Dumper $anvil->data->{variables};
|
print Dumper $anvil->data->{variables};
|
||||||
|
|
||||||
@ -128,24 +139,6 @@ $VAR1 = {
|
|||||||
'value' => 'striker'
|
'value' => 'striker'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'config_step1' => {
|
|
||||||
'domain' => {
|
|
||||||
'value' => 'alteeve.com'
|
|
||||||
},
|
|
||||||
'sequence' => {
|
|
||||||
'value' => '1'
|
|
||||||
},
|
|
||||||
'ifn_count' => {
|
|
||||||
'value' => '1'
|
|
||||||
},
|
|
||||||
'prefix' => {
|
|
||||||
'value' => 'an'
|
|
||||||
},
|
|
||||||
'organization' => {
|
|
||||||
'value' => 'Alteeve'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
@ -207,17 +200,23 @@ LIMIT 1;";
|
|||||||
if ($job_picked_up_by)
|
if ($job_picked_up_by)
|
||||||
{
|
{
|
||||||
# Check if the PID is still active.
|
# Check if the PID is still active.
|
||||||
my ($pids) = $anvil->System->pids({program_name => $THIS_FILE, ignore_me => 1});
|
$anvil->System->pids({ignore_me => 1});
|
||||||
my $count = @{$pids};
|
|
||||||
print "count: [".$count."], my pid: [".$$."]\n";
|
|
||||||
|
|
||||||
# Any other instance running?.
|
# Is the PID that picked up the job still alive?
|
||||||
if ($count)
|
if (exists $anvil->{pids}{$job_picked_up_by})
|
||||||
{
|
{
|
||||||
# Yup, exit.
|
print Dumper $anvil->{pids}{$job_picked_up_by};
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0146", variables => { pid => $job_picked_up_by }});
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0146", variables => { pid => $job_picked_up_by }});
|
||||||
$anvil->nice_exit({code => 1});
|
$anvil->nice_exit({code => 1});
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
# The previous job is gone, we'll take this over.
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0147", variables => {
|
||||||
|
pid => $job_picked_up_by,
|
||||||
|
percent => $job_progress,
|
||||||
|
}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# This will store the variables from the database
|
# This will store the variables from the database
|
||||||
|
Loading…
Reference in New Issue
Block a user