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:55:12 -0800 |
commit | a2b2ce86df549560ee4438e92a8663c0a0706b82 (patch) | |
tree | ab51605b700fd99b7366b19575ddd93846c18acf /scripts | |
parent | 96dd4d22eec0c9b8fae50f68a310680e579bdf1c (diff) | |
download | vyatta-cfg-system-a2b2ce86df549560ee4438e92a8663c0a0706b82.tar.gz vyatta-cfg-system-a2b2ce86df549560ee4438e92a8663c0a0706b82.zip |
Add ability to restart services when hostname changes
Currently only restart rsyslog but more can be added as needed.
Fixes bug 8237.
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"); +} |