diff options
author | Daniil Baturin <daniil@baturin.org> | 2014-11-05 14:45:57 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2014-11-05 14:45:57 +0600 |
commit | 0c20ea86adefa872505854393f2c5a2d2b3b3783 (patch) | |
tree | b5f00f3a263c469a4fd0de1dc1f826678631b355 | |
parent | 7a5a8500091589f0ede3d5a1dbc8b6b4b3fabf1d (diff) | |
parent | d6de6f2755f326b8fb5195e051e801577939bdbf (diff) | |
download | vyatta-cfg-system-0c20ea86adefa872505854393f2c5a2d2b3b3783.tar.gz vyatta-cfg-system-0c20ea86adefa872505854393f2c5a2d2b3b3783.zip |
Merge pull request #30 from jhendryUK/manage_sysctl_options
Manage sysctl options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/system/vyatta_update_sysctl.pl | 86 | ||||
-rw-r--r-- | templates/system/sysctl/all/node.def | 5 | ||||
-rw-r--r-- | templates/system/sysctl/all/node.tag/node.def | 1 | ||||
-rw-r--r-- | templates/system/sysctl/all/node.tag/value/node.def | 8 | ||||
-rw-r--r-- | templates/system/sysctl/custom/node.def | 5 | ||||
-rw-r--r-- | templates/system/sysctl/custom/node.tag/node.def | 1 | ||||
-rw-r--r-- | templates/system/sysctl/custom/node.tag/value/node.def | 8 | ||||
-rw-r--r-- | templates/system/sysctl/net.ipv4.igmp_max_memberships/node.def | 12 | ||||
-rw-r--r-- | templates/system/sysctl/net.ipv4.ipfrag_time/node.def | 12 | ||||
-rw-r--r-- | templates/system/sysctl/node.def | 1 |
11 files changed, 140 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 diff --git a/templates/system/sysctl/all/node.def b/templates/system/sysctl/all/node.def new file mode 100644 index 00000000..47f08dbc --- /dev/null +++ b/templates/system/sysctl/all/node.def @@ -0,0 +1,5 @@ +tag: +priority: 318 +type: txt +help: List all sysctl options (BROKEN: Does not list all values) +allowed: /sbin/sysctl -N -a 2>&- diff --git a/templates/system/sysctl/all/node.tag/node.def b/templates/system/sysctl/all/node.tag/node.def new file mode 100644 index 00000000..b688551e --- /dev/null +++ b/templates/system/sysctl/all/node.tag/node.def @@ -0,0 +1 @@ +help: Value for sysctl option diff --git a/templates/system/sysctl/all/node.tag/value/node.def b/templates/system/sysctl/all/node.tag/value/node.def new file mode 100644 index 00000000..ac4daa52 --- /dev/null +++ b/templates/system/sysctl/all/node.tag/value/node.def @@ -0,0 +1,8 @@ +priority: 319 # Failure barrier only - no ordering constraints + +type: txt +help: Configure sysctl option +val_help: <integer>; Set sysctl option + +update: sudo /opt/vyatta/sbin/vyatta_update_sysctl.pl --option $VAR(../@) $VAR(@) + diff --git a/templates/system/sysctl/custom/node.def b/templates/system/sysctl/custom/node.def new file mode 100644 index 00000000..f03a3e13 --- /dev/null +++ b/templates/system/sysctl/custom/node.def @@ -0,0 +1,5 @@ +tag: +priority: 318 +type: txt +help: Define specific sysctl options to modify +val_help: <sysctl_option> ; Name of sysctl option you want to modufy diff --git a/templates/system/sysctl/custom/node.tag/node.def b/templates/system/sysctl/custom/node.tag/node.def new file mode 100644 index 00000000..b688551e --- /dev/null +++ b/templates/system/sysctl/custom/node.tag/node.def @@ -0,0 +1 @@ +help: Value for sysctl option diff --git a/templates/system/sysctl/custom/node.tag/value/node.def b/templates/system/sysctl/custom/node.tag/value/node.def new file mode 100644 index 00000000..08a5f5a3 --- /dev/null +++ b/templates/system/sysctl/custom/node.tag/value/node.def @@ -0,0 +1,8 @@ +priority: 319 # Failure barrier only - no ordering constraints + +type: txt +help: Configure sysctl option +val_help: <value>; Set sysctl option value + +update: sudo /opt/vyatta/sbin/vyatta_update_sysctl.pl --option $VAR(../@) $VAR(@) + diff --git a/templates/system/sysctl/net.ipv4.igmp_max_memberships/node.def b/templates/system/sysctl/net.ipv4.igmp_max_memberships/node.def new file mode 100644 index 00000000..22dba70d --- /dev/null +++ b/templates/system/sysctl/net.ipv4.igmp_max_memberships/node.def @@ -0,0 +1,12 @@ +# +# Configuration template for offload settings +# + +priority: 319 # Failure barrier only - no ordering constraints + +type: u32 +help: Configure net.ipv4.igmp_max_memberships option +val_help: <integer>; Set net.ipv4.igmp_max_memberships value + +update: sudo /opt/vyatta/sbin/vyatta_update_sysctl.pl --option net.ipv4.igmp_max_memberships $VAR(@) + diff --git a/templates/system/sysctl/net.ipv4.ipfrag_time/node.def b/templates/system/sysctl/net.ipv4.ipfrag_time/node.def new file mode 100644 index 00000000..ee390f44 --- /dev/null +++ b/templates/system/sysctl/net.ipv4.ipfrag_time/node.def @@ -0,0 +1,12 @@ +# +# Configuration template for offload settings +# + +priority: 319 # Failure barrier only - no ordering constraints + +type: u32 +help: Configure net.ipv4.ipfrag_time option +val_help: <integer>; Set net.ipv4.ipfrag_time to specific value + +update: sudo /opt/vyatta/sbin/vyatta_update_sysctl.pl --option net.ipv4.ipfrag_time $VAR(@) + diff --git a/templates/system/sysctl/node.def b/templates/system/sysctl/node.def new file mode 100644 index 00000000..6f6ecedc --- /dev/null +++ b/templates/system/sysctl/node.def @@ -0,0 +1 @@ +help: Sysctl options |