Skip to content

Commit

Permalink
fix(build): fluidattacks#1002 args manage ports fix
Browse files Browse the repository at this point in the history
- sourcing `shellCommands` into `managePorts` builtin

Signed-off-by: Diego Quintero <diquintero@unal.edu.co>
  • Loading branch information
este6an13 committed Jul 13, 2023
1 parent 91ee9fe commit 3eb2ab2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Daniel Salazar <podany270895@gmail.com> Daniel Salazar <podany270895@gmail.com>
David Acevedo <dacevedoa12@gmail.com> David Acevedo <dacevedoa12@gmail.com>
David Arnold <david.arnold@iohk.io> David Arnold <david.arnold@iohk.io>
David Arnold <david.arnold@iohk.io> David Arnold <dgx.arnold@gmail.com>
Diego Quintero <diquintero@unal.edu.co> Diego Quintero <57577966+este6an13@users.noreply.github.com>
Diego Quintero <diquintero@unal.edu.co> Diego Quintero <diquintero@unal.edu.co>
Diego Restrepo <drestrepo@fluidattacks.com> Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com>
Diego Restrepo <drestrepo@fluidttacks.com> Diego Restrepo <drestrepo@fluidttacks.com>
Diego Restrepo <restrepomesadiego@gmail.com> Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com>
Expand Down
2 changes: 1 addition & 1 deletion src/args/make-template/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
then
abort ''
Ivalid placeholder: ${k}
Invalid placeholder: ${k}
Placeholders must match: ${argumentRegex}
For example: __argExample123__
Expand Down
4 changes: 4 additions & 0 deletions src/args/manage-ports/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
__nixpkgs__,
makeTemplate,
__shellCommands__,
...
}:
makeTemplate {
replace = {
__argShellCommands__ = __shellCommands__;
};
name = "manage-ports";
searchPaths = {
bin = [
Expand Down
12 changes: 7 additions & 5 deletions src/args/manage-ports/template.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# shellcheck shell=bash

source __argShellCommands__

function _kill_port {
local pids
local port="${1}"

pids="$(mktemp)" \
&& if ! lsof -t "-i:${port}" > "${pids}"; then
info "Nothing listening on port: ${port}" \
info "No process was found listening on port ${port}" \
&& return 0
fi \
&& while read -r pid; do
if kill -9 "${pid}"; then
if timeout 5 tail --pid="${pid}" -f /dev/null; then
info "Killed pid: ${pid}, listening on port: ${port}"
info "Process listening on port ${port} with PID ${pid} was successfully killed"
else
warn "kill timeout pid: ${pid}, listening on port: ${port}"
warn "Timeout while attempting to kill process with PID ${pid} listening on port ${port}"
fi
else
error "Unable to kill pid: ${pid}, listening on port: ${port}"
error "Unable to kill process with PID ${pid} listening on port ${port}"
fi
done < "${pids}"
}
Expand Down Expand Up @@ -50,7 +52,7 @@ function wait_for_tcp {
error "Timeout while waiting for ${host}:${port} to open" \
&& return 1
else
info "Waiting 1 second for ${host}:${port} to open, ${elapsed} seconds in total" \
info "Waiting 1 second for ${host}:${port} to open: ${elapsed} seconds in total" \
&& sleep 1 \
&& elapsed="$(("${elapsed}" + 1))" \
&& continue
Expand Down

0 comments on commit 3eb2ab2

Please sign in to comment.