mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
ynh_port_available: also check ports used by other apps in settings.yml
This commit is contained in:
parent
4ae72cc3c8
commit
381f789fec
2 changed files with 29 additions and 2 deletions
|
@ -20,7 +20,7 @@ ynh_find_port () {
|
||||||
test -n "$port" || ynh_die --message="The argument of ynh_find_port must be a valid port."
|
test -n "$port" || ynh_die --message="The argument of ynh_find_port must be a valid port."
|
||||||
while ! ynh_port_available --port=$port
|
while ! ynh_port_available --port=$port
|
||||||
do
|
do
|
||||||
port=$((port+1)) # Else, pass to next port
|
port=$((port+1))
|
||||||
done
|
done
|
||||||
echo $port
|
echo $port
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,12 @@ ynh_port_available () {
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if ss --numeric --listening --tcp --udp | awk '{print$5}' | grep --quiet --extended-regexp ":$port$" # Check if the port is free
|
# Check if the port is free
|
||||||
|
if ss --numeric --listening --tcp --udp | awk '{print$5}' | grep --quiet --extended-regexp ":$port$"
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
# This is to cover (most) case where an app is using a port yet ain't currently using it for some reason (typically service ain't up)
|
||||||
|
elif grep -q "port: '$port'" /etc/yunohost/apps/*/settings.yml
|
||||||
then
|
then
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
|
|
22
tests/test_helpers.d/ynhtest_network.sh
Normal file
22
tests/test_helpers.d/ynhtest_network.sh
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
ynhtest_port_80_aint_available() {
|
||||||
|
! ynh_port_available 80
|
||||||
|
}
|
||||||
|
|
||||||
|
ynhtest_port_12345_is_available() {
|
||||||
|
ynh_port_available 12345
|
||||||
|
}
|
||||||
|
|
||||||
|
ynhtest_port_12345_is_booked_by_other_app() {
|
||||||
|
|
||||||
|
ynh_port_available 12345
|
||||||
|
ynh_port_available 12346
|
||||||
|
|
||||||
|
mkdir -p /etc/yunohost/apps/block_port/
|
||||||
|
echo "port: '12345'" > /etc/yunohost/apps/block_port/settings.yml
|
||||||
|
! ynh_port_available 12345
|
||||||
|
|
||||||
|
echo "other_port: '12346'" > /etc/yunohost/apps/block_port/settings.yml
|
||||||
|
! ynh_port_available 12346
|
||||||
|
|
||||||
|
rm -rf /etc/yunohost/apps/block_port
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue