summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Hendry <jhendry@mintel.com>2014-10-31 23:15:48 +0000
committerJason Hendry <jhendry@mintel.com>2014-10-31 23:15:48 +0000
commite032779c46744ea53d0558e3d61950bdbf4c6c6a (patch)
tree5b7b2d78f3a1e0cb79d0899ae47c46253ebee629
parent7a5a8500091589f0ede3d5a1dbc8b6b4b3fabf1d (diff)
downloadvyatta-cfg-system-e032779c46744ea53d0558e3d61950bdbf4c6c6a.tar.gz
vyatta-cfg-system-e032779c46744ea53d0558e3d61950bdbf4c6c6a.zip
Initial import fo vyatta_update_sysctl.pl
-rw-r--r--Makefile.am1
-rw-r--r--scripts/system/vyatta_update_sysctl.pl86
2 files changed, 87 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index aecadb89..dd9586b6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,6 +45,7 @@ sbin_SCRIPTS += scripts/system/vyatta_update_hosts.pl
sbin_SCRIPTS += scripts/system/vyatta_update_login.pl
sbin_SCRIPTS += scripts/system/vyatta_update_logrotate.pl
sbin_SCRIPTS += scripts/system/vyatta_update_resolv.pl
+sbin_SCRIPTS += scripts/system/vyatta_update_sysctl.pl
sbin_SCRIPTS += scripts/system/vyatta_update_syslog.pl
sbin_SCRIPTS += scripts/system/vyatta_update_console.pl
sbin_SCRIPTS += scripts/system/vyatta_update_ntp.pl
diff --git a/scripts/system/vyatta_update_sysctl.pl b/scripts/system/vyatta_update_sysctl.pl
new file mode 100644
index 00000000..ddf10115
--- /dev/null
+++ b/scripts/system/vyatta_update_sysctl.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+#
+# Module: vyatta_update_sysctl.pl
+#
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# A copy of the GNU General Public License is available as
+# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution
+# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'.
+# You can also obtain it by writing to the Free Software Foundation,
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Jason Hendry
+# Date: October 2014
+# Description: Script to manage sysctl values
+#
+# **** End License ****
+#
+
+use lib "/opt/vyatta/share/perl5/";
+use Vyatta::Config;
+use Vyatta::File qw(touch);
+
+use Getopt::Long;
+
+use strict;
+use warnings;
+
+my $SYSCTL = '/sbin/sysctl';
+
+my (@opts);
+
+sub usage {
+ print <<EOF;
+Usage: $0 --option=<sysctl_option> <value>
+EOF
+ exit 1;
+}
+
+GetOptions(
+ "option=s{2}" => \@opts,
+ ) or usage();
+
+set_sysctl_value(@opts) if (@opts);
+exit 0;
+
+sub set_sysctl_value {
+ my ($sysctl_opt, $nvalue) = @_;
+ my $ovalue = get_sysctl_value($sysctl_opt);
+
+ if ($nvalue ne $ovalue) {
+ my $cmd = "$SYSCTL -w $sysctl_opt=$nvalue 2>&1 1>&-";
+ system($cmd);
+ if ($? >> 8) {
+ die "exec of $SYSCTL failed: '$cmd'";
+ }
+ }
+}
+
+sub get_sysctl_value {
+ my $option = shift;
+ my $val;
+
+ open( my $sysctl, '-|', "$SYSCTL $option 2>&1" ) or die "sysctl failed: $!\n";
+ while (<$sysctl>) {
+ chomp;
+ $val = (split(/ = /, $_))[1];
+ }
+ close $sysctl;
+ return ($val);
+}
+
+# net.ipv4.ipfrag_time