magibney commented on code in PR #1328: URL: https://github.com/apache/solr/pull/1328#discussion_r1096098937
########## solr/bin/solr: ########## @@ -2158,6 +2158,35 @@ function mk_writable_dir() { fi } +# Check whether at least one of lsof/netstat/ss are available +function get_port_tool() { + for tool in 'lsof' 'ss' 'netstat'; do + if [[ -x "$(command -v $tool)" ]]; then + echo $tool + return + fi + done +} + +# Will get the PID of the java process running on the specified port, if one is running +# Otherwise empty result. Use get_port_tool to check whether lsof/ss/netstat is installed first +function check_port_in_use() { + local tool=$1 + local port=$2 + + case $tool in + lsof) + lsof -iTCP:${port} 2>/dev/null -sTCP:LISTEN 2>/dev/null | grep -ow "java\s*\?[0-9]\+" | grep -ow "[0-9]\+" Review Comment: `lsof -iTCP:${port} 2>/dev/null -sTCP:LISTEN 2>/dev/null ` -- looks like accidental unusual double `2>/dev/null`? Also, we really don't want to lose the `-Pn` args to `lsof` I think: ``` -P inhibits the conversion of port numbers to port names for network files. Inhibiting the conversion may make lsof run a little faster. It is also useful when port name lookup is not working properly. -n inhibits the conversion of network numbers to host names for network files. Inhibiting conversion may make lsof run faster. It is also useful when host name lookup is not working properly. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org