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 <[email protected]>
  • Loading branch information
este6an13 committed Jul 12, 2023
1 parent 91ee9fe commit a2f60a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Daniel Salazar <[email protected]> Daniel Salazar <[email protected]>
David Acevedo <[email protected]> David Acevedo <[email protected]>
David Arnold <[email protected]> David Arnold <[email protected]>
David Arnold <[email protected]> David Arnold <[email protected]>
Diego Quintero <[email protected]> Diego Quintero <[email protected]>
Diego Restrepo <[email protected]> Diego Restrepo Mesa <[email protected]>
Diego Restrepo <[email protected]> Diego Restrepo <[email protected]>
Diego Restrepo <[email protected]> Diego Restrepo Mesa <[email protected]>
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 a2f60a4

Please sign in to comment.