diff --git a/CHANGES.txt b/CHANGES.txt index 9826f2fa76..277087985a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.30 + * Implement the logic in bin/stop-server (CASSANDRA-18838) * Upgrade snappy-java to 1.1.10.4 (CASSANDRA-18878) * Add cqlshrc.sample and credentials.sample into Debian package (CASSANDRA-18818) * Refactor validation logic in StorageService.rebuild (CASSANDRA-18803) diff --git a/bin/stop-server b/bin/stop-server index 45049d8052..573b512c56 100755 --- a/bin/stop-server +++ b/bin/stop-server @@ -1,3 +1,5 @@ +#!/bin/sh + # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -14,18 +16,59 @@ # See the License for the specific language governing permissions and # limitations under the License. +show_help() +{ + echo "Usage: $0 [-p ] | [-l] | [-e] | [-h]" + echo " -p 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" +kill_processes() +{ + pids=$(pgrep -u "$(whoami)" -f "${1}") + if [ -n "$pids" ]; then + echo "$pids" | xargs kill -9 + fi +} -# if you are using the cassandra start script with -p, this -# is the best way to stop: +if [ $# -eq 0 ]; then + show_help + exit 1 +fi -# kill `cat ` +case "$1" in + -p) + if [ -z "$2" ]; then + echo "missing pidfile argument after -p" + exit 1 + fi + if [ ! -f "$2" ]; then + echo "pidfile $2 does not exist" + 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: + kill_processes cassandra + ;; + -e) + kill_processes org.apache.cassandra.service.CassandraDaemon + ;; + -h) + show_help + exit 0 + ;; + *) + show_help + exit 1 + ;; +esac - -# otherwise, 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 +exit 0 diff --git a/redhat/cassandra.spec b/redhat/cassandra.spec index 0b38bdd615..37c21cdd0b 100644 --- a/redhat/cassandra.spec +++ b/redhat/cassandra.spec @@ -104,6 +104,7 @@ rm -f bin/*.bat rm -f bin/*.orig rm -f bin/*.ps1 rm -f bin/cassandra.in.sh +rm -f bin/stop-server rm -f lib/sigar-bin/*winnt* # strip segfaults on dll.. rm -f tools/bin/*.bat rm -f tools/bin/cassandra.in.sh @@ -154,7 +155,6 @@ exit 0 %attr(755,root,root) %{_bindir}/sstableupgrade %attr(755,root,root) %{_bindir}/sstableutil %attr(755,root,root) %{_bindir}/sstableverify -%attr(755,root,root) %{_bindir}/stop-server %attr(755,root,root) %{_sbindir}/cassandra %attr(755,root,root) /%{_sysconfdir}/rc.d/init.d/%{username} %{_sysconfdir}/default/%{username}