mirror of
https://github.com/YunoHost-Apps/duniter_ynh.git
synced 2024-09-03 18:26:35 +02:00
[enh] Add ynh_find_port helper
This commit is contained in:
parent
2ddb2cc18e
commit
03feb876a2
2 changed files with 18 additions and 4 deletions
|
@ -56,3 +56,20 @@ fi
|
||||||
# Remove Duniter package
|
# Remove Duniter package
|
||||||
sudo dpkg -r duniter
|
sudo dpkg -r duniter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Find a free port and return it
|
||||||
|
#
|
||||||
|
# example: port=$(ynh_find_port 8080)
|
||||||
|
#
|
||||||
|
# usage: ynh_find_port begin_port
|
||||||
|
# | arg: begin_port - port to start to search
|
||||||
|
ynh_find_port () {
|
||||||
|
port=$1
|
||||||
|
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
|
||||||
|
while netcat -z 127.0.0.1 $port # Check if the port is free
|
||||||
|
do
|
||||||
|
port=$((port+1)) # Else, pass to next port
|
||||||
|
done
|
||||||
|
echo $port
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,7 @@ sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|| ynh_die "Path not available: ${domain}${path}"
|
||||||
|
|
||||||
# Check port availability
|
# Check port availability
|
||||||
sudo yunohost app checkport $port
|
port=$(ynh_find_port $port)
|
||||||
if [[ ! $? -eq 0 ]]; then
|
|
||||||
ynh_die "Port not available: ${port}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check node availability
|
# Check node availability
|
||||||
if curl --output /dev/null --silent --head --fail "$sync_node:$sync_port/node/summary"; then
|
if curl --output /dev/null --silent --head --fail "$sync_node:$sync_port/node/summary"; then
|
||||||
|
|
Loading…
Add table
Reference in a new issue