Always use "ynh_find_port"?

All of my Python projects used a app server that will bind to

In my GitHub - YunoHost-Apps/pyinventory_ynh: YunoHost app package for: project it currently looks like this:

So only the “install” used a “free” port. All other remains to the same port.
Currently the “restore” script doesn’t contain anything about the port … So i assume the last used port in the backup remains, isn’t it?

now i have a clash: A other application used already port 8000… And i restored a backup of my PyInventory project. Restore was successfully, but the assigned domain was response from the “wrong” application: The already installed one…

Question: Maybe it’s a better idea to always use the port=$(ynh_find_port --port=8000) pattern to get a free port in all scripts (install/change_url/upgrade/restore) …
Because the finally used port is not important. The main thing is, that it’s exclusive used by the correct app. So better save than sorry and always find a free port?

Side answer, if you use packaging v2 the YunoHost core takes care of all that. :wink:
Simply declare that the app needs a port resource, you can even specify a preferred port, and the core will use the first available port.

cf. Packaging v2 | Yunohost Documentation and App resources | Yunohost Documentation

1 Like

Sounds good. I will take a look on v2