From 6fca92ac3c407e1a9e42ca870246e9fdb8fc2fbc Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Wed, 8 Aug 2018 08:16:50 +0900 Subject: [PATCH] dist/common/scripts/scylla_ec2_check: support custom NIC ifname on EC2 This is bash version of commit 88fe3c2694ad3253407f5eafb7ab3a337416b7ed. Since some AMIs using consistent network device naming, primary NIC ifname is not 'eth0'. But we hardcoded NIC name as 'eth0' on scylla_ec2_check, we need to add --nic option to specify custom NIC ifname. Fixes #3658 Signed-off-by: Takuya ASADA Message-Id: <20180807231650.13697-1-syuu@scylladb.com> --- dist/ami/files/.bash_profile | 2 +- dist/common/scripts/scylla_ec2_check | 30 +++++++++++++++++-- dist/common/scripts/scylla_lib.sh | 4 +++ dist/common/scripts/scylla_setup | 44 ++++++++++++++++------------ 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/dist/ami/files/.bash_profile b/dist/ami/files/.bash_profile index 6069f7d9bd..2cc6cb2f47 100644 --- a/dist/ami/files/.bash_profile +++ b/dist/ami/files/.bash_profile @@ -120,7 +120,7 @@ else fi fi echo -n " " -/usr/lib/scylla/scylla_ec2_check +/usr/lib/scylla/scylla_ec2_check --nic eth0 if [ $? -eq 0 ]; then echo fi diff --git a/dist/common/scripts/scylla_ec2_check b/dist/common/scripts/scylla_ec2_check index 26968b0fde..2e6677d2dc 100755 --- a/dist/common/scripts/scylla_ec2_check +++ b/dist/common/scripts/scylla_ec2_check @@ -2,6 +2,12 @@ . /usr/lib/scylla/scylla_lib.sh +print_usage() { + echo "scylla_ec2_check --nic eth0" + echo " --nic specify NIC" + exit 1 +} + get_en_interface_type() { TYPE=`curl -s http://169.254.169.254/latest/meta-data/instance-type|cut -d . -f 1` SUBTYPE=`curl -s http://169.254.169.254/latest/meta-data/instance-type|cut -d . -f 2` @@ -18,7 +24,7 @@ get_en_interface_type() { } is_vpc_enabled() { - MAC=`cat /sys/class/net/eth0/address` + MAC=`cat /sys/class/net/$1/address` VPC_AVAIL=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/|grep vpc-id` [ -n "$VPC_AVAIL" ] } @@ -27,9 +33,27 @@ if ! is_ec2; then exit 0 fi +if [ $# -eq 0 ]; then + print_usage +fi +while [ $# -gt 0 ]; do + case "$1" in + "--nic") + verify_args $@ + NIC="$2" + shift 2 + ;; + esac +done + +if ! is_valid_nic $NIC; then + echo "NIC $NIC doesn't exist." + exit 1 +fi + TYPE=`curl -s http://169.254.169.254/latest/meta-data/instance-type` EN=`get_en_interface_type` -DRIVER=`ethtool -i eth0|awk '/^driver:/ {print $2}'` +DRIVER=`ethtool -i $NIC|awk '/^driver:/ {print $2}'` if [ "$EN" = "" ]; then tput setaf 1 tput bold @@ -39,7 +63,7 @@ if [ "$EN" = "" ]; then echo "More documentation available at: " echo "http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking" exit 1 -elif ! is_vpc_enabled; then +elif ! is_vpc_enabled $NIC; then tput setaf 1 tput bold echo "VPC is not enabled!" diff --git a/dist/common/scripts/scylla_lib.sh b/dist/common/scripts/scylla_lib.sh index 91187dba3a..202ec9803c 100644 --- a/dist/common/scripts/scylla_lib.sh +++ b/dist/common/scripts/scylla_lib.sh @@ -91,6 +91,10 @@ create_perftune_conf() { /usr/lib/scylla/perftune.py --tune net --nic "$nic" $mode --dump-options-file > /etc/scylla.d/perftune.yaml } +is_valid_nic() { + [ -d /sys/class/net/$1 ] +} + . /etc/os-release if is_debian_variant || is_gentoo_variant; then SYSCONFIG=/etc/default diff --git a/dist/common/scripts/scylla_setup b/dist/common/scripts/scylla_setup index 4327abfb11..a76260437f 100755 --- a/dist/common/scripts/scylla_setup +++ b/dist/common/scripts/scylla_setup @@ -39,6 +39,27 @@ print_usage() { exit 1 } +interactive_choose_nic() { + NICS=$(for i in /sys/class/net/*;do nic=`basename $i`; if [ "$nic" != "lo" ]; then echo $nic; fi; done) + NR_NICS=`echo $NICS|wc -w` + if [ $NR_NICS -eq 0 ]; then + echo "NIC not found." + exit 1 + elif [ $NR_NICS -eq 1 ]; then + NIC=$NICS + else + echo "Please select NIC from following list: " + while true; do + echo $NICS + echo -n "> " + read NIC + if is_valid_nic $NIC; then + break + fi + done + fi +} + interactive_ask_service() { echo $1 echo $2 @@ -125,6 +146,7 @@ run_setup_script() { return 0 } +NIC="eth0" AMI=0 SET_NIC=0 DEV_MODE=0 @@ -265,7 +287,8 @@ if is_ec2; then EC2_CHECK=$? fi if [ $EC2_CHECK -eq 1 ]; then - /usr/lib/scylla/scylla_ec2_check + interactive_choose_nic + /usr/lib/scylla/scylla_ec2_check --nic $NIC fi fi @@ -452,24 +475,6 @@ if [ $INTERACTIVE -eq 1 ]; then interactive_ask_service "Do you want to setup sysconfig?" "Answer yes to do system wide configuration customized for Scylla. Answer no to do nothing." "yes" &&: SYSCONFIG_SETUP=$? if [ $SYSCONFIG_SETUP -eq 1 ]; then - NICS=$(for i in /sys/class/net/*;do nic=`basename $i`; if [ "$nic" != "lo" ]; then echo $nic; fi; done) - NR_NICS=`echo $NICS|wc -w` - if [ $NR_NICS -eq 0 ]; then - echo "NIC not found." - exit 1 - elif [ $NR_NICS -eq 1 ]; then - NIC=$NICS - else - echo "Please select NIC from following list: " - while true; do - echo $NICS - echo -n "> " - read NIC - if [ -e /sys/class/net/$NIC ]; then - break - fi - done - fi interactive_ask_service "Do you want to optimize NIC queue settings?" "Answer yes to enable network card optimization and improve performance. Answer no to skip this optimization." "yes" &&: SET_NIC=$? fi @@ -479,6 +484,7 @@ if [ $SYSCONFIG_SETUP -eq 1 ]; then if [ $SET_NIC -eq 1 ]; then SETUP_ARGS="--setup-nic" fi + interactive_choose_nic run_setup_script "NIC queue" /usr/lib/scylla/scylla_sysconfig_setup --nic $NIC $SETUP_ARGS fi