Skip to content

nodetool stopdaemon

Stops the Cassandra daemon process.


Synopsis

nodetool [connection_options] stopdaemon

Description

nodetool stopdaemon sends a shutdown signal to the Cassandra process, terminating the daemon. This is a hard stop that does not perform graceful draining—use drain first for a clean shutdown.

Not Graceful

stopdaemon does not flush memtables or complete pending operations. For graceful shutdown, always run drain before stopdaemon.


Behavior

When stopdaemon is executed:

  1. JMX shutdown signal is sent to Cassandra
  2. Cassandra process begins termination
  3. In-flight requests may be interrupted
  4. Unflushed memtable data remains in commit log
  5. Process exits

What does NOT happen: - Memtables are not flushed to SSTables - Pending operations are not completed - Gossip shutdown notification is not sent - Other nodes are not informed gracefully


Examples

Basic Usage

nodetool stopdaemon
# First drain (graceful)
nodetool drain

# Then stop
nodetool stopdaemon

Emergency Stop

When immediate shutdown is required:

nodetool stopdaemon

When to Use

After Drain

The recommended shutdown sequence:

# 1. Drain first (flushes data, stops accepting requests)
nodetool drain

# 2. Stop the daemon
nodetool stopdaemon

Emergency Situations

When immediate shutdown is critical:

# Stop immediately (not graceful)
nodetool stopdaemon

Use emergency stop when: - Node is causing cluster-wide issues - Runaway process consuming resources - Security incident requiring immediate isolation - drain is hanging or not responding

After drain Completes

Once drain finishes, stopdaemon simply terminates the process:

# Drain completes
nodetool drain
# INFO: DRAINED

# Safe to stop now
nodetool stopdaemon

Comparison: drain vs stopdaemon

Action drain stopdaemon
Flush memtables Yes No
Complete pending requests Yes No
Stop gossip Yes Immediate
Stop native transport Yes Immediate
Notify other nodes Yes No
Process exits No Yes
Data safety Safe Requires commit log replay

Graceful Shutdown Sequence

Step Command What Happens
1 drain Flush memtables, stop accepting requests, stop gossip
2 stopdaemon Exit process (data is safe)

Emergency Shutdown Sequence

Step Command What Happens
1 stopdaemon Immediate exit (commit log replay needed on restart)

Post-Stop Verification

Verify Process Stopped

# Check for Cassandra process
pgrep -f CassandraDaemon
# Should return nothing (no output)

# Alternative
ps aux | grep CassandraDaemon | grep -v grep
# Should return nothing

Verify Ports Released

# CQL port
netstat -tlnp | grep 9042
# Should return nothing

# JMX port
netstat -tlnp | grep 7199
# Should return nothing

# Inter-node port
netstat -tlnp | grep 7000
# Should return nothing

All-in-One Verification

#!/bin/bash
# verify_stopped.sh

echo "=== Cassandra Stop Verification ==="
echo ""

# Process check
pid=$(pgrep -f CassandraDaemon)
if [ -z "$pid" ]; then
    echo "Process: STOPPED"
else
    echo "Process: STILL RUNNING (PID: $pid)"
fi

# Port checks
for port in 9042 7199 7000 7001; do
    if netstat -tlnp 2>/dev/null | grep -q ":$port "; then
        echo "Port $port: IN USE"
    else
        echo "Port $port: FREE"
    fi
done

Alternatives to stopdaemon

# Stop via systemd (usually runs drain internally)
systemctl stop cassandra

Most distribution packages configure systemd to call drain before stopping.

init.d

service cassandra stop

kill Command (Last Resort)

# Find PID
pid=$(pgrep -f CassandraDaemon)

# Normal kill (SIGTERM)
kill $pid

# Force kill if unresponsive (SIGKILL)
kill -9 $pid

Force Kill

kill -9 should only be used when the process is completely unresponsive. It prevents any cleanup and may require longer commit log replay.

Comparison of Stop Methods

Method Graceful Runs Drain Recommended
nodetool drain && stopdaemon Yes Yes Yes
systemctl stop cassandra Usually Depends on unit file Yes
nodetool stopdaemon alone No No Emergency only
kill <pid> Partial No Last resort
kill -9 <pid> No No Extreme emergency

Workflow: Planned Maintenance Stop

#!/bin/bash
# graceful_stop.sh

echo "=== Graceful Cassandra Shutdown ==="
echo ""

# 1. Check current state
echo "1. Pre-stop status:"
echo "   Binary: $(nodetool statusbinary)"
echo "   Gossip: $(nodetool statusgossip)"

# 2. Drain
echo ""
echo "2. Draining node..."
nodetool drain
echo "   Drain complete"

# 3. Stop daemon
echo ""
echo "3. Stopping daemon..."
nodetool stopdaemon

# 4. Wait for process exit
echo ""
echo "4. Waiting for process to exit..."
for i in {1..30}; do
    if ! pgrep -f CassandraDaemon > /dev/null; then
        echo "   Process stopped"
        break
    fi
    sleep 1
done

# 5. Verify
echo ""
echo "5. Verification:"
if pgrep -f CassandraDaemon > /dev/null; then
    echo "   WARNING: Process still running!"
else
    echo "   Cassandra stopped successfully"
fi

Workflow: Emergency Stop

#!/bin/bash
# emergency_stop.sh

echo "=== EMERGENCY STOP ==="
echo "WARNING: This is not a graceful shutdown!"
echo ""

# Immediate stop
nodetool stopdaemon

# Wait briefly
sleep 5

# Check if stopped
if pgrep -f CassandraDaemon > /dev/null; then
    echo "Process still running, forcing kill..."
    pkill -9 -f CassandraDaemon
    sleep 2
fi

# Final check
if pgrep -f CassandraDaemon > /dev/null; then
    echo "ERROR: Cannot stop Cassandra!"
    exit 1
else
    echo "Cassandra stopped"
    echo "NOTE: Commit log replay will occur on restart"
fi

After Stop: Restart Considerations

If Stopped Without Drain

When Cassandra restarts after stopdaemon without drain:

  1. Commit log is replayed
  2. Unflushed memtable data is recovered
  3. Startup may take longer
  4. Data integrity is maintained (commit log is durable)
# Start after emergency stop
systemctl start cassandra

# Monitor startup (may be slower due to replay)
tail -f /var/log/cassandra/system.log | grep -i "replay\|starting\|listening"

If Stopped After Drain

Clean restart:

# Normal start
systemctl start cassandra

# Quick startup expected
tail -f /var/log/cassandra/system.log | grep -i "starting\|listening"

Troubleshooting

stopdaemon Doesn't Work

If JMX command fails:

# Check JMX connectivity
nodetool info
# If this fails, JMX is unreachable

# Use kill instead
pid=$(pgrep -f CassandraDaemon)
kill $pid

Process Hangs After stopdaemon

If process doesn't exit:

# Check process state
ps aux | grep CassandraDaemon

# Check what it's doing
strace -p $(pgrep -f CassandraDaemon) 2>&1 | head -20

# Force kill if necessary
kill -9 $(pgrep -f CassandraDaemon)

Cannot Connect to JMX

# If nodetool can't connect
nodetool stopdaemon
# Error: Failed to connect to '127.0.0.1:7199'

# Use systemctl or kill instead
systemctl stop cassandra
# or
kill $(pgrep -f CassandraDaemon)

Best Practices

Shutdown Guidelines

  1. Always drain first - Run nodetool drain before stopdaemon
  2. Use systemd in production - Prefer systemctl stop for managed shutdown
  3. Verify stopped - Confirm process exited and ports released
  4. Document emergency stops - Log when and why emergency stop was used
  5. Allow startup time - Expect longer restart after non-graceful stop
  6. Reserve for emergencies - Only use stopdaemon alone when drain is not viable

Command Relationship
drain Graceful prepare for shutdown
status Check cluster status before stop
info Node information
disablebinary Stop client connections
disablegossip Stop cluster communication