Merge "Add element for setting sysctl values"
This commit is contained in:
commit
80976d9d44
12
elements/sysctl/README.rst
Normal file
12
elements/sysctl/README.rst
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
======
|
||||||
|
sysctl
|
||||||
|
======
|
||||||
|
|
||||||
|
Add a sysctl-set-value command which can be run from within an element.
|
||||||
|
Running this command will cause the sysctl value to be set on boot (by
|
||||||
|
writing the value to /etc/sysctl.d).
|
||||||
|
|
||||||
|
Example usage
|
||||||
|
|
||||||
|
::
|
||||||
|
sysctl-set-value net.ipv4.ip_forward 1
|
49
elements/sysctl/bin/sysctl-set-value
Executable file
49
elements/sysctl/bin/sysctl-set-value
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copied from tripleo-image-element's sysctl element
|
||||||
|
#
|
||||||
|
# Validate and manage setting sysctl settings.
|
||||||
|
#
|
||||||
|
# The script is called with name/value pairs which are stored
|
||||||
|
# in the system default sysctl.d directory. Before adding new
|
||||||
|
# settings a validation is done to ensure that conflicting
|
||||||
|
# sysctl settings have not been requested. Once finished sysctl
|
||||||
|
# is used to activate the changes.
|
||||||
|
|
||||||
|
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
set -eu
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
NAME=${1:-}
|
||||||
|
VALUE=${2:-}
|
||||||
|
# Optional comment used to describe the setting
|
||||||
|
COMMENT=${3:-"This file was created by diskimage-builder."}
|
||||||
|
|
||||||
|
if [ -z "$NAME" -o -z "$VALUE" ]; then
|
||||||
|
echo "NAME and VALUE are required."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILENAME="/etc/sysctl.d/${NAME}.conf"
|
||||||
|
|
||||||
|
if [ -f $FILENAME ]; then
|
||||||
|
# check to make sure the settings match... otherwise fail
|
||||||
|
if ! grep -q "^$NAME = $VALUE" $FILENAME; then
|
||||||
|
echo "Conflicting sysctl.conf setting for $NAME == $VALUE. Found:"
|
||||||
|
grep "^$NAME" $FILENAME
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
|
||||||
|
if ! sysctl -a | grep -q "^$NAME"; then
|
||||||
|
echo "Invalid sysctl key: $NAME"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sysctl-write-value $NAME "$VALUE" "$COMMENT"
|
||||||
|
|
||||||
|
sysctl -p $FILENAME
|
||||||
|
|
||||||
|
fi
|
32
elements/sysctl/bin/sysctl-write-value
Executable file
32
elements/sysctl/bin/sysctl-write-value
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copied from tripleo-image-element's sysctl element
|
||||||
|
#
|
||||||
|
# Validate and manage setting sysctl settings.
|
||||||
|
#
|
||||||
|
# The script is called with name/value pairs which are stored
|
||||||
|
# in the system default sysctl.d directory. This script performs
|
||||||
|
# no checking, just writing out the file.
|
||||||
|
|
||||||
|
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
set -eu
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
NAME=${1:-}
|
||||||
|
VALUE=${2:-}
|
||||||
|
# Optional comment used to describe the setting
|
||||||
|
COMMENT=${3:-"This file was created by diskimage-builder."}
|
||||||
|
|
||||||
|
if [ -z "$NAME" -o -z "$VALUE" ]; then
|
||||||
|
echo "Usage: sysctl-write-value <name> <value> [comment]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILENAME="/etc/sysctl.d/${NAME}.conf"
|
||||||
|
|
||||||
|
cat > $FILENAME <<EOF_CAT
|
||||||
|
# $COMMENT
|
||||||
|
$NAME = $VALUE
|
||||||
|
EOF_CAT
|
Loading…
Reference in New Issue
Block a user