Files
scylladb/dist/common/scripts/scylla_sysconfig_setup
Takuya ASADA 0f9b095867 dist/common/scripts: prevent ignoreing flag that passed after another flag which requires parameter
When user mistakenly forgot to pass parameter for a flag, our scripts misparses
next flag as the parameter.
ex) Correct usage is '--ntp-domain <domain> --setup-nic', but passed
    '--ntp-domain --setup-nic'.
Result of that, next flag will ignore by scripts.
To prevent such behavior, reject any parameter that start with '--'.

Fixes #2609

Signed-off-by: Takuya ASADA <syuu@scylladb.com>
Message-Id: <20170815114751.6223-1-syuu@scylladb.com>
2017-08-15 18:27:32 +03:00

107 lines
2.9 KiB
Bash
Executable File

#!/bin/bash -e
#
# Copyright (C) 2015 ScyllaDB
. /usr/lib/scylla/scylla_lib.sh
print_usage() {
echo "scylla_sysconfig_setup --nic eth0 --mode posix --nr-hugepages 64 --user scylla --group scylla --homedir /var/lib/scylla --confdir /etc/scylla --setup-nic"
echo " --nic specify NIC"
echo " --mode network mode (posix, dpdk)"
echo " --nr-hugepages number of hugepages"
echo " --user user (dpdk requires root)"
echo " --group group (dpdk requires root)"
echo " --homedir scylla home directory"
echo " --confdir scylla config directory"
echo " --setup-nic setup NIC's interrupts, RPS, XPS"
echo " --ami AMI instance mode"
exit 1
}
if [ $# -eq 0 ]; then
print_usage
fi
while [ $# -gt 0 ]; do
case "$1" in
"--nic")
verify_args $@
NIC="$2"
shift 2
;;
"--mode")
verify_args $@
NETWORK_MODE="$2"
shift 2
;;
"--nr-hugepages")
verify_args $@
NR_HUGEPAGES="$2"
shift 2
;;
"--user")
verify_args $@
USER="$2"
shift 2
;;
"--group")
verify_args $@
GROUP="$2"
shift 2
;;
"--homedir")
verify_args $@
SCYLLA_HOME="$2"
shift 2
;;
"--confdir")
verify_args $@
SCYLLA_CONF="$2"
shift 2
;;
"--setup-nic")
SET_NIC=yes
shift 1
;;
"--ami")
AMI=yes
shift 1
;;
*)
print_usage
;;
esac
done
echo Setting parameters on $SYSCONFIG/scylla-server
if [ $SET_NIC = "yes" ]; then
RPS_CPUS=$(/usr/lib/scylla/posix_net_conf.sh --cpu-mask $NIC)
if [ "$RPS_CPUS" != "" ]; then
CPUSET=$(echo $RPS_CPUS | /usr/lib/scylla/hex2list.py)
/usr/lib/scylla/scylla_cpuset_setup --cpuset $CPUSET
fi
fi
if [ "$NETWORK_MODE" == "dpdk" ]; then
ETHDRV=`/usr/lib/scylla/dpdk-devbind.py --status | grep if=$NIC | sed -e "s/^.*drv=//" -e "s/ .*$//"`
ETHPCIID=`/usr/lib/scylla/dpdk-devbind.py --status | grep if=$NIC | awk '{print $1}'`
else
# this will empty previous values
ETHDRV=""
ETHPCIID=""
fi
sed -e s#^NETWORK_MODE=.*#NETWORK_MODE=$NETWORK_MODE# \
-e s#^IFNAME=.*#IFNAME=$NIC# \
-e s#^ETHDRV=.*#ETHDRV=$ETHDRV# \
-e s#^ETHPCIID=.*#ETHPCIID=$ETHPCIID# \
-e s#^NR_HUGEPAGES=.*#NR_HUGEPAGES=$NR_HUGEPAGES# \
-e s#^USER=.*#USER=$USER# \
-e s#^GROUP=.*#GROUP=$GROUP# \
-e s#^SCYLLA_HOME=.*#SCYLLA_HOME=$SCYLLA_HOME# \
-e s#^SCYLLA_CONF=.*#SCYLLA_CONF=$SCYLLA_CONF# \
-e s#^SET_NIC=.*#SET_NIC=$SET_NIC# \
-e "s#^SCYLLA_ARGS=.*#SCYLLA_ARGS=\"$SCYLLA_ARGS\"#" \
-e s#^AMI=.*#AMI=$AMI# \
$SYSCONFIG/scylla-server > /tmp/scylla-server
mv /tmp/scylla-server $SYSCONFIG/scylla-server