Check if netstat or iproute2 is available

This commit is contained in:
Christoph Blecker 2018-02-14 10:33:04 -08:00
parent 1aa2a027ed
commit ceacae42a6
No known key found for this signature in database
GPG Key ID: B34A59A9D39F838B

View File

@ -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