diff --git a/hack/lib/etcd.sh b/hack/lib/etcd.sh index 0685da4f138..e887426a083 100755 --- a/hack/lib/etcd.sh +++ b/hack/lib/etcd.sh @@ -22,13 +22,22 @@ ETCD_PORT=${ETCD_PORT:-2379} kube::etcd::validate() { # validate if in path - which etcd >/dev/null || { + command -v etcd >/dev/null || { kube::log::usage "etcd must be in your PATH" exit 1 } # validate etcd port is free - if netstat -nat | grep "[\.:]${ETCD_PORT:?} .*LISTEN" >/dev/null 2>&1; then + local port_check_command + if command -v ss &> /dev/null && ss -Version | grep 'iproute2' &> /dev/null; then + port_check_command="ss" + elif command -v netstat &>/dev/null; then + port_check_command="netstat" + else + kube::log::usage "unable to identify if etcd is bound to port ${ETCD_PORT}. unable to find ss or netstat utilities." + exit 1 + fi + if ${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${ETCD_PORT:?}" >/dev/null 2>&1; then kube::log::usage "unable to start etcd as port ${ETCD_PORT} is in use. please stop the process listening on this port and retry." kube::log::usage "`netstat -nat | grep "[\.:]${ETCD_PORT:?} .*LISTEN"`" exit 1