mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #233 from YunoHost/ynh_find_port
Nouveau helper ynh_find_port
This commit is contained in:
commit
5d3e1c9212
1 changed files with 15 additions and 0 deletions
15
data/helpers.d/network
Normal file
15
data/helpers.d/network
Normal file
|
@ -0,0 +1,15 @@
|
|||
# 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
|
||||
}
|
Loading…
Add table
Reference in a new issue