Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): #1002 args manage ports fix #1120

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <diquintero@unal.edu.co>
Diego Quintero <diquintero@unal.edu.co> este6an13 <57577966+este6an13@users.noreply.github.com>
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" \
este6an13 marked this conversation as resolved.
Show resolved Hide resolved
&& sleep 1 \
&& elapsed="$(("${elapsed}" + 1))" \
&& continue
Expand Down
Loading