Skip to content

Commit

Permalink
Implement the logic in bin/stop-server
Browse files Browse the repository at this point in the history
patch by Ling Mao; reviewed by Stefan Miklosovic and Brandon Williams for CASSANDRA-18838

Co-authored-by: Stefan Miklosovic <[email protected]>
  • Loading branch information
maoling and smiklosovic committed Oct 18, 2023
1 parent dc72341 commit f27c6c8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
65 changes: 54 additions & 11 deletions bin/stop-server
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,18 +16,59 @@
# 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>`
kill_processes()
{
pids=$(pgrep -u "$(whoami)" -f "${1}")
if [ -n "$pids" ]; then
echo "$pids" | xargs kill -9
fi
}

if [ $# -eq 0 ]; then
show_help
exit 1
fi

# 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:
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

# user=`whoami`
# pgrep -u $user -f cassandra | xargs kill -9
exit 0
2 changes: 1 addition & 1 deletion redhat/cassandra.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit f27c6c8

Please sign in to comment.