You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "smiklosovic (via GitHub)" <gi...@apache.org> on 2023/10/11 12:00:42 UTC

Re: [PR] CASSANDRA-18838: make stop-server shell out of the box [cassandra]

smiklosovic commented on code in PR #2680:
URL: https://github.com/apache/cassandra/pull/2680#discussion_r1354855529


##########
bin/stop-server:
##########
@@ -14,18 +16,55 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+show_help() {
+    echo "Usage: $0 [-p <pidfile>] | [-l] | [-e] | [-h]"
+    echo "  -p <pidfile>    Stop the process using the specified pidfile"
+    echo "  -l              Stop the process with the name like 'cassandra'"
+    echo "  -e              Stop the process with the name equal 'CassandraDaemon'"
+    echo "  -h              Show the help message"
+}
 
-echo "please read the stop-server script before use"
-
-# if you are using the cassandra start script with -p, this
-# is the best way to stop:
-
-# kill `cat <pidfile>` 
+if [ $# -eq 0 ]; then
+    echo "please read the stop-server script before use. use -h for help and usage."
+    exit 1
+fi
 
+case "$1" in
+    -p)
+        if [ -z "$2" ]; then
+            echo "Missing pidfile argument after -p."
+            exit 1
+        fi
+        # if you are using the cassandra start script with -p, this
+        # is the best way to stop:
+        kill "$(cat "$2")"
+        ;;
+    -l)
+        # you can run something like this, but
+        # this is a shotgun approach and will kill other processes
+        # with cassandra in their name or arguments too:
+        user=$(whoami)
+        pgrep -u "$user" -f cassandra | xargs kill -9
+        ;;
+    -e)
+        pids=$(ps ax | grep -i 'org.apache.cassandra.service.CassandraDaemon' | grep java | grep -v grep | awk '{print $1}')

Review Comment:
   @maoling I think you can use `pgrep` here too



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org