Skip to content

Commit 3726745

Browse files
committed
workbench: fixes for supervisor, mac compatible pgrep
1 parent 437f7e3 commit 3726745

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

nix/workbench/backend/nomad/cloud.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ deploy-genesis-nomadcloud() {
729729
then
730730
wb_nomad agents stop "${server_name}" "${client_name}" "exec"
731731
fi
732-
backend_nomad stop-nomad-job "${dir}"
732+
# Already "fatal" -> ignore errors!
733+
backend_nomad stop-nomad-job "${dir}" || true
733734
fatal "Failed to upload genesis"
734735
fi
735736

@@ -738,6 +739,9 @@ deploy-genesis-nomadcloud() {
738739
if ! backend_nomad deploy-genesis-wget "${dir}" "${uri}"
739740
then
740741
# File kept for debugging!
742+
msg "$(red "FATAL: deploy-genesis-wget \"${dir}\" \"${uri}\"")"
743+
# Already "fatal" -> ignore errors!
744+
backend_nomad stop-nomad-job "${dir}" || true
741745
fatal "Deploy of genesis \"${uri}\" failed"
742746
else
743747
msg "$(green "Genesis \"${uri}\" deployed successfully")"
@@ -746,12 +750,13 @@ deploy-genesis-nomadcloud() {
746750
aws s3 rm \
747751
s3://"${s3_bucket_name}"/"${genesis_file_name}" \
748752
--region "${s3_region}" \
749-
|| true
753+
|| true # Ignore errors when doing clean ups!
750754
# Reminder to remove old files.
751755
msg "Still available files at $(yellow "\"s3://${s3_bucket_name}\""):"
752756
aws s3 ls \
753757
s3://"${s3_bucket_name}"/ \
754-
--region "${s3_region}"
758+
--region "${s3_region}" \
759+
|| true # Ignore errors when doing clean ups!
755760
fi
756761
}
757762

nix/workbench/backend/supervisor.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ case "$op" in
2525
grep ':9001 ' |
2626
wc -l)" = "0" ||
2727
echo 'supervisord'
28+
# `pgrep` piped to `wc -l` instead "--count" to make it Mac comptible
29+
# Also only shorthand options: like `-x` instead of `--exact`
2830
for exe in 'cardano-node' 'tx-generator' 'cardano-tracer'
29-
do test $(pgrep --exact --count $exe) = 0 || echo $exe
31+
do test $(pgrep -x $exe | wc -l) = 0 || echo $exe
3032
done
3133
;;
3234

@@ -176,7 +178,7 @@ EOF
176178

177179
# Avoid buffer related problems with stdout and stderr disabling buffering
178180
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED
179-
if ! PYTHONUNBUFFERED=TRUE supervisord --config "$dir"/supervisor/supervisord.conf $@
181+
if ! PYTHONUNBUFFERED=TRUE supervisord --config "$dir"/supervisor/supervisord.conf $@ >"$dir"/supervisor/stderr 2>"$dir"/supervisor/stderr
180182
then progress "supervisor" "$(red fatal: failed to start) $(white supervisord)"
181183
echo "$(red supervisord.conf) --------------------------------" >&2
182184
cat "$dir"/supervisor/supervisord.conf
@@ -325,6 +327,8 @@ EOF
325327
local usage="USAGE: wb backend $op RUN-DIR"
326328
local dir=${1:?$usage}; shift
327329

330+
# This flag/file makes `scenario_watcher` exit
331+
touch ${dir}/flag/cluster-stopping
328332
if test -f ${dir}/supervisor/supervisord.pid -a \
329333
-f ${dir}/supervisor/child.pids
330334
then kill $(<${dir}/supervisor/supervisord.pid) $(<${dir}/supervisor/child.pids) 2>/dev/null
@@ -386,3 +390,22 @@ EOF
386390

387391
* ) usage_supervisor;; esac
388392
}
393+
394+
###############################################################################
395+
# Debugging ###################################################################
396+
###############################################################################
397+
398+
if test -n "${SUPERVISOR_DEBUG:-}"
399+
then
400+
exec 5> "$(dirname "$(readlink -f "$0")")"/supervisor.sh.debug
401+
BASH_XTRACEFD="5"
402+
PS4='$LINENO: '
403+
set -x
404+
fi
405+
406+
debugMsg() {
407+
if test -n "${SUPERVISOR_DEBUG:-}"
408+
then
409+
>&2 echo -e "\n\n\t\t----------$1\n"
410+
fi
411+
}

nix/workbench/nomad.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,9 @@ EOL
657657
local usage="USAGE: wb nomad ${op} ${subop} SERVER-NAME"
658658
local name=${1:?$usage}; shift
659659
local config_file=$(wb_nomad server config-file-path "${name}")
660-
pgrep --delimiter ' ' --full "nomad.*${config_file}.*"
660+
# Make it Mac compatible by only using shorthand options:
661+
# `-d` instead of `--delimiter` and `-f` instead of `--full`
662+
pgrep -d ' ' -f "nomad.*${config_file}.*"
661663
# Clean up is only done by the `stop` subcommand!
662664
# No `rm "${pid_file}"` if not running.
663665
;;
@@ -668,7 +670,9 @@ EOL
668670
local pid_file=$(wb_nomad server pid-filepath "${name}")
669671
local config_file=$(wb_nomad server config-file-path "${name}")
670672
# It's running if we haven't PROPERLY stopped it or PIDs exist!
671-
test -f "${pid_file}" || test $(pgrep --count --full "nomad.*${config_file}.*") -gt 0
673+
# `pgrep` piped to `wc -l` instead "--count" to make it Mac comptible
674+
# Also only shorthand options: like `-f` instead of `--full`
675+
test -f "${pid_file}" || test $(pgrep -f "nomad.*${config_file}.*" | wc -l) -gt 0
672676
;;
673677
####### server -> start )#######################################################
674678
start )
@@ -879,7 +883,9 @@ EOL
879883
local usage="USAGE: wb nomad ${op} ${subop} CLIENT-NAME"
880884
local name=${1:?$usage}; shift
881885
local config_file=$(wb_nomad client config-file-path "${name}")
882-
pgrep --delimiter ' ' --full "nomad.*${config_file}.*"
886+
# Make it Mac compatible by only using shorthand options:
887+
# `-d` instead of `--delimiter` and `-f` instead of `--full`
888+
pgrep -d ' ' -f "nomad.*${config_file}.*"
883889
# Clean up is only done by the `stop` subcommand!
884890
# No `rm "${pid_file}"` if not running.
885891
;;
@@ -890,7 +896,9 @@ EOL
890896
local pid_file=$(wb_nomad client pid-filepath "${name}")
891897
local config_file=$(wb_nomad client config-file-path "${name}")
892898
# It's running if we haven't PROPERLY stopped it or PIDs exist!
893-
test -f "${pid_file}" || test $(pgrep --count --full "nomad.*${config_file}.*") -gt 0
899+
# `pgrep` piped to `wc -l` instead "--count" to make it Mac comptible
900+
# Also only shorthand options: like `-f` instead of `--full`
901+
test -f "${pid_file}" || test $(pgrep -f "nomad.*${config_file}.*" | wc -l) -gt 0
894902
;;
895903
####### client -> start )#######################################################
896904
# Agent is started with `-network-interface lo` if not without a proper
@@ -1317,7 +1325,9 @@ EOF
13171325
pids-array )
13181326
local usage="USAGE: wb nomad ${op} ${subop}"
13191327
local state_dir=$(wb_nomad webfs state-dir-path)
1320-
pgrep --delimiter ' ' --full "webfsd.*${state_dir}"/webfsd.log
1328+
# Make it Mac compatible by only using shorthand options:
1329+
# `-d` instead of `--delimiter` and `-f` instead of `--full`
1330+
pgrep -d ' ' -f "webfsd.*${state_dir}"/webfsd.log
13211331
# Clean up is only done by the `stop` subcommand!
13221332
# No `rm "${pid_file}"` if not running.
13231333
;;
@@ -1326,7 +1336,9 @@ EOF
13261336
local pid_file=$(wb_nomad webfs pid-filepath)
13271337
local state_dir=$(wb_nomad webfs state-dir-path)
13281338
# It's running if we haven't PROPERLY stopped it or PIDs exist!
1329-
test -f "${pid_file}" && test $(pgrep --count --full "webfsd.*${state_dir}"/webfsd.log) -gt 0
1339+
# `pgrep` piped to `wc -l` instead "--count" to make it Mac comptible
1340+
# Also only shorthand options: like `-f` instead of `--full`
1341+
test -f "${pid_file}" && test $(pgrep -f "webfsd.*${state_dir}"/webfsd.log | wc -l) -gt 0
13301342
;;
13311343
start )
13321344
local usage="USAGE: wb nomad ${op} ${subop}"

0 commit comments

Comments
 (0)