diff options
author | James Davidson <james.davidson@vyatta.com> | 2013-01-29 09:50:46 -0800 |
---|---|---|
committer | James Davidson <james.davidson@vyatta.com> | 2013-01-29 09:59:41 -0800 |
commit | 28ed69c424c61faf7edbb6039fb13717efbb435b (patch) | |
tree | ed42a8e1f246926fe1945683cb71379965453062 /scripts | |
parent | 8bc99945b85ab7b75f52d017f9e023f7ff419c70 (diff) | |
download | vyatta-cfg-system-28ed69c424c61faf7edbb6039fb13717efbb435b.tar.gz vyatta-cfg-system-28ed69c424c61faf7edbb6039fb13717efbb435b.zip |
Add ability to restart services when hostname changes
Currently only restart rsyslog but more can be added as needed.
Fixes bug 8237.
(cherry picked from commit a2b2ce86df549560ee4438e92a8663c0a0706b82)
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/system/vyatta_update_hosts.pl | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/scripts/system/vyatta_update_hosts.pl b/scripts/system/vyatta_update_hosts.pl index 7c8bc8e6..22b141ab 100755 --- a/scripts/system/vyatta_update_hosts.pl +++ b/scripts/system/vyatta_update_hosts.pl @@ -13,7 +13,7 @@ # General Public License for more details. # # This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2012 Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2012-2013 Vyatta, Inc. # All Rights Reserved. # # Description: @@ -24,16 +24,19 @@ # use strict; +use English; use lib "/opt/vyatta/share/perl5/"; use File::Temp qw(tempfile); use Vyatta::File qw(touch); use Vyatta::Config; +use Getopt::Long; my $HOSTS_CFG = '/etc/hosts'; my $HOSTS_TMPL = "/tmp/hosts.XXXXXX"; my $HOSTNAME_CFG = '/etc/hostname'; my $MAILNAME_CFG = '/etc/mailname'; +my $restart_services = 1; sub set_hostname { my ( $hostname ) = @_; @@ -52,6 +55,13 @@ sub set_mailname { close ($f); } +if ($EUID != 0) { + printf("This program must be run by root.\n"); + exit 1; +} + +GetOptions("restart-services!" => \$restart_services); + my $vc = new Vyatta::Config(); $vc->setLevel('system'); @@ -91,8 +101,14 @@ print $out $hosts_line; close ($in); close ($out); -system("sudo cp $tempname $HOSTS_CFG") == 0 +system("cp $tempname $HOSTS_CFG") == 0 or die "Can't copy $tempname to $HOSTS_CFG: $!"; set_hostname $host_name; set_mailname $mail_name; + +# Restart services that use the system hostname; +# add more ase needed. +if ($restart_services) { + system("invoke-rc.d rsyslog restart"); +} |