Skip to content

Commit

Permalink
Enforces an exact match of replica processes (#5732)
Browse files Browse the repository at this point in the history
# Motivation

A script runs `pgrep -l replica` to check for replica processes, but it
can't receive false positives from a process called `replicatord`.

```sh
$ pgrep -l replica
781 replicatord
95113 replica
```

# Changes

- The script checks for exact matches with the keyword `replica`.

# Tests

I couldn't run the script that starts the snapshot without this change
because it was complaining about a process (`replicatord`) matching the
pattern. This change allowed me to run it without issues. I also tried
to start a second snapshot, and it correctly informed me that a replica
was already running.

# Todos

- [ ] Add entry to changelog (if necessary) - Not necessary
  • Loading branch information
yhabib authored Nov 6, 2024
1 parent 135d971 commit 86de7da
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/deploy-devenv
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ else
exit 1
fi

if ! pgrep replica; then
if ! pgrep -x replica; then
echo "A local replica must be running to deploy to." >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/dfx-snapshot-install
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ install_state() {

output_restore_backup_script() {
cat <<-EOF
if pgrep replica; then
if pgrep -x replica; then
echo "A replica is still running. State should be restored automatically when the replica is stopped." >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/dfx-snapshot-start
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ source "$(clap.build)"
# shellcheck disable=SC2009
SCRIPT_COUNT="$(ps -A -o command | grep -c "^bash .*$(basename "$0")")"

if pgrep replica || [ "$SCRIPT_COUNT" -gt 2 ]; then
if pgrep -x replica || [ "$SCRIPT_COUNT" -gt 2 ]; then
echo "ERROR: There is already a replica running. Please stop it first."
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/nns-dapp/release-sop
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ sha256() {
}

get_dfx_identity() {
if pgrep replica; then
if pgrep -x replica; then
(
echo
echo "A replica is running."
Expand Down
2 changes: 1 addition & 1 deletion scripts/nns-dapp/test-proposal-payload
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ clap.define short=i long=identity desc="Identity to use to create proposals" var
source "$(clap.build)"

# Check if a replica is running:
if ! pgrep replica; then
if ! pgrep -x replica; then
echo "A replica must be running to submit proposals to." >&2
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/nns-dapp/upgrade-downgrade-test
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if ! [ -f "$ARGS_FILE" ]; then
fi

# Check if a replica is running:
if pgrep replica; then
if pgrep -x replica; then
echo "A replica is already running. Shut it down first." >&2
exit 1
fi
Expand Down

0 comments on commit 86de7da

Please sign in to comment.