-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from danl5/fix_issue27
Resolve the issue of failing to correctly elect a leader.
- Loading branch information
Showing
5 changed files
with
208 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
node_addrs=("127.0.0.1:9981" "127.0.0.1:9982" "127.0.0.1:9983") | ||
peers="127.0.0.1:9981,127.0.0.1:9982,127.0.0.1:9983" | ||
|
||
elect_binary="node" | ||
pid_file="./node_pids" | ||
|
||
start_nodes() { | ||
echo "Starting nodes..." | ||
for node_addr in "${node_addrs[@]}"; do | ||
echo "Starting node with address $node_addr" | ||
log_file="${node_addr//:/_}.log" | ||
./$elect_binary --nodeaddr=$node_addr --peers=$peers 2>&1 | tee "$log_file" & | ||
echo $! >> $pid_file | ||
done | ||
echo "All nodes started." | ||
} | ||
|
||
stop_nodes() { | ||
echo "Stopping nodes..." | ||
if [ -f $pid_file ]; then | ||
while read -r pid; do | ||
echo "Stopping process $pid" | ||
kill -9 $pid | ||
done < $pid_file | ||
rm $pid_file | ||
echo "All nodes stopped." | ||
else | ||
echo "No nodes are running." | ||
fi | ||
} | ||
|
||
show_help() { | ||
echo "Usage: $0 {start|stop}" | ||
} | ||
|
||
case "$1" in | ||
start) | ||
start_nodes | ||
;; | ||
stop) | ||
stop_nodes | ||
;; | ||
*) | ||
show_help | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.