The command I use to do what you want to do is:
nmcli c up CONNECTION_NAME
To find the connection name, run
nmcli c show
In my application, I spin off a python thread that is entirely devoted to waiting a set interval, checking for internet below and on failure, running the above (which if run with os.system waits on the command) then checking again to confirm it works and logging it for statistics.
My interval is every 20 seconds and my devices will “soft-reset” their network manager 20 to several hundred times a day. I suspect this has something to do with the adapter I am using.
def internet(host="18.104.22.168", port=53, timeout=3):
Host: 22.214.171.124 (google-public-dns-a.google.com)
Service: domain (DNS/TCP)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
except Exception as ex:
It seems to remind the network manager that it can and should connect to a connection it chooses to stop connecting to. Note that why it stops in the first place remains unknown to me.
Restarting the entire network manager service was never an option for me because it seems to forget that unmanaged devices exist after such a restart.
To access the nmcli in a container you have to follow the instruction in the networking documentation balena has.
Good luck and if you ever find out more about whats going on let me know.