[ https://issues.apache.org/jira/browse/SOLR-16619?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17689758#comment-17689758 ]
Colvin Cowie commented on SOLR-16619: ------------------------------------- I could take a look more closely next week, I've just had a look at how ps is used currently. in main there's ~20 uses of ps, with several variations of arguments. It might be worth refactoring most of the existing usages to use a common function or two to DRY it out, because it's quite hard to understand what the intention of each one is and whether they all need different slightly arguments or not. Here's a summary of the uses I saw: # This one is used twice and counts the number of Solr PIDs running: ** {{numSolrs=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//')}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L770] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L817] # This one is used once within the above to get the PIDs rather than the count... ** {{PROCESSES=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | awk '\{print $2}' | sort -r)}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L820] # Used 3 times with jetty_port() to "extract the value of the -Djetty.port parameter from a running Solr process": ** {{for ID in $(ps auxww | grep java | grep start\.jar | awk '\{print $2}' | sort -r)}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L1169] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L1276] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L1579] # Used 4 times to determine the PID: ** {{SOLR_PID=$(ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' \{print $2}' | sort -r)}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L1935] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L1948] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L2339] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L2348] # Used in the jetty_port() function to extract the command line args that started it: ** {{SOLR_PROC=$(ps -o command='' -p "$SOLR_PID" | grep start\.jar | grep jetty\.port)}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L721] # Check whether the PID is still alive while shutting down ** {{while ps -o pid='' -p "$pid" &> /dev/null ; do}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L696] # Used twice (same command as above really): ** {{CHECK_PID=$(ps -o pid='' -p "$PID" | tr -d ' ')}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L711] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L1887] # Used 3 times when stopping, the stat is important here for checking for Zombie processes. ** {{STAT=$( (ps -o stat='' -p "$SOLR_PID" || :) | tr -d ' ')}} ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L866] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L887] ** [https://github.com/apache/solr/blob/f804af73397c6e4c1f14254af218714da751d047/solr/bin/solr#L904] If I've interpreted them all correctly: # Counts the number of Solr processes # Gets the PIDs of all Solr processes # Gets the PIDs of all Jetty processes # Gets the PID for an instance of jetty started with a specific port # Gets the command line arguments for a known PID if it's a jetty instance # Check PID is alive # Check PID is alive # Check if PID is alive and not a Zombie Then * 1 could be determined from 2 rather than repeating the ps * 2 and 3 are essentially doing the same things, so could have a single function * 6 and 7 and 8 could use a single function that returns the STAT for a PID if it's running. * 4 could be replaced with lsof, which is used to determine the PID from a port during stop commands (or they could use ps instead) ** (Also I have a [PR|https://github.com/apache/solr/pull/1328] to add support for ss and netstat as alternatives when lsof isn't available, but need to sort out mac support for some of the arguments...) * 5 exists to determine a port from a PID, so unless there's something special about the logic for that which needs to be preserved, it could also be done with lsof. > `solr status` and `solr create` do not work on IBM i > ---------------------------------------------------- > > Key: SOLR-16619 > URL: https://issues.apache.org/jira/browse/SOLR-16619 > Project: Solr > Issue Type: Bug > Affects Versions: 8.11.2, 9.1 > Environment: Pase on IBM i using Java 11 with OpenJDK > Reporter: Jesse Gorzinski > Priority: Minor > Time Spent: 0.5h > Remaining Estimate: 0h > > The `solr status` and `solr create` commands fail on the IBM i platform. > For example > ``` > Solr process 3391 from /solr/solr-8.11.2/bin/solr-8983.pid not found > ``` -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org