Skip to content

Commit

Permalink
Move cleanup to a script so it doesn't kill itself (solana-labs#7603)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge authored Dec 23, 2019
1 parent 120c8f2 commit 6f7d0c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
37 changes: 12 additions & 25 deletions net/net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,16 @@ startCommon() {
"
fi
[[ -z "$externalNodeSshKey" ]] || ssh-copy-id -f -i "$externalNodeSshKey" "${sshOptions[@]}" "solana@$ipAddress"
syncScripts "$ipAddress"
}

syncScripts() {
echo "rsyncing scripts... to $ipAddress"
declare ipAddress=$1
rsync -vPrc -e "ssh ${sshOptions[*]}" \
--exclude 'net/log*' \
"$SOLANA_ROOT"/{fetch-perf-libs.sh,scripts,net,multinode-demo} \
"$ipAddress":~/solana/
"$ipAddress":~/solana/ > /dev/null
}

startBootstrapLeader() {
Expand Down Expand Up @@ -870,33 +876,14 @@ stopNode() {

echo "--- Stopping node: $ipAddress"
echo "stop log: $logFile"
syncScripts "$ipAddress"
(
# Since cleanup.sh does a pkill, we cannot pass the command directly,
# otherwise the process which is doing the killing will be killed because
# the script itself will match the pkill pattern
set -x
# shellcheck disable=SC2029 # It's desired that PS4 be expanded on the client side
ssh "${sshOptions[@]}" "$ipAddress" "
PS4=\"$PS4\"
set -x
! tmux list-sessions || tmux kill-session
declare sudo=
if sudo true; then
sudo=\"sudo -n\"
fi
for pid in solana/*.pid; do
pgid=\$(ps opgid= \$(cat \$pid) | tr -d '[:space:]')
if [[ -n \$pgid ]]; then
\$sudo kill -- -\$pgid
fi
done
if [[ -f solana/netem.cfg ]]; then
solana/scripts/netem.sh delete < solana/netem.cfg
rm -f solana/netem.cfg
fi
solana/scripts/net-shaper.sh force_cleanup
for pattern in solana- remote- iftop validator client node; do
pkill -9 -f \$pattern
done
"
ssh "${sshOptions[@]}" "$ipAddress" "PS4=\"$PS4\" ./solana/net/remote/cleanup.sh"
) >> "$logFile" 2>&1 &

declare pid=$!
Expand Down
25 changes: 25 additions & 0 deletions net/remote/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -x
! tmux list-sessions || tmux kill-session
declare sudo=
if sudo true; then
sudo="sudo -n"
fi

echo "pwd: $(pwd)"
for pid in solana/*.pid; do
pgid=$(ps opgid= "$(cat "$pid")" | tr -d '[:space:]')
if [[ -n $pgid ]]; then
$sudo kill -- -"$pgid"
fi
done
if [[ -f solana/netem.cfg ]]; then
solana/scripts/netem.sh delete < solana/netem.cfg
rm -f solana/netem.cfg
fi
solana/scripts/net-shaper.sh force_cleanup
for pattern in validator.sh boostrap-leader.sh solana- remote- iftop validator client node; do
echo "killing $pattern"
pkill -f $pattern
done

0 comments on commit 6f7d0c6

Please sign in to comment.