mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Disable predictable network interface names to avoid cases where devices
don't reboot properly because interface name changed...
This commit is contained in:
parent
8b08de665a
commit
2aeed38ea5
2 changed files with 23 additions and 3 deletions
|
@ -15,6 +15,7 @@ from yunohost.service import (_run_service_command,
|
||||||
manually_modified_files_compared_to_debian_default)
|
manually_modified_files_compared_to_debian_default)
|
||||||
from yunohost.utils.filesystem import free_space_in_directory
|
from yunohost.utils.filesystem import free_space_in_directory
|
||||||
from yunohost.utils.packages import get_installed_version
|
from yunohost.utils.packages import get_installed_version
|
||||||
|
from yunohost.utils.network import get_network_interfaces
|
||||||
|
|
||||||
logger = getActionLogger('yunohost.migration')
|
logger = getActionLogger('yunohost.migration')
|
||||||
|
|
||||||
|
@ -68,6 +69,8 @@ class MyMigration(Migration):
|
||||||
self.apt_dist_upgrade(conf_flags=["new", "miss", "def"])
|
self.apt_dist_upgrade(conf_flags=["new", "miss", "def"])
|
||||||
_run_service_command("restart", "fail2ban")
|
_run_service_command("restart", "fail2ban")
|
||||||
|
|
||||||
|
self.disable_predicable_interface_names()
|
||||||
|
|
||||||
# Clean the mess
|
# Clean the mess
|
||||||
os.system("apt autoremove --assume-yes")
|
os.system("apt autoremove --assume-yes")
|
||||||
os.system("apt clean --assume-yes")
|
os.system("apt clean --assume-yes")
|
||||||
|
@ -352,3 +355,20 @@ class MyMigration(Migration):
|
||||||
# command showing in the terminal, since 'info' channel is only
|
# command showing in the terminal, since 'info' channel is only
|
||||||
# enabled if the user explicitly add --verbose ...
|
# enabled if the user explicitly add --verbose ...
|
||||||
os.system(command)
|
os.system(command)
|
||||||
|
|
||||||
|
def disable_predicable_interface_names(self):
|
||||||
|
|
||||||
|
# Try to see if currently used interface names are predictable ones or not...
|
||||||
|
# If we ain't using "eth0" or "wlan0", assume we are using predictable interface
|
||||||
|
# names and therefore they shouldnt be disabled
|
||||||
|
network_interfaces = get_network_interfaces().keys()
|
||||||
|
if "eth0" not in network_interfaces and "wlan0" not in network_interfaces:
|
||||||
|
return
|
||||||
|
|
||||||
|
interfaces_config = read_file("/etc/network/interfaces")
|
||||||
|
if "eth0" not in interfaces_config and "wlan0" not in interfaces_config:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Disable predictive interface names
|
||||||
|
# c.f. https://unix.stackexchange.com/a/338730
|
||||||
|
os.system("ln -s /dev/null /etc/systemd/network/99-default.link")
|
||||||
|
|
|
@ -56,7 +56,7 @@ def get_network_interfaces():
|
||||||
# Parse relevant informations for each of them
|
# Parse relevant informations for each of them
|
||||||
devices = {name: _extract_inet(addrs) for name, addrs in devices_raw.items() if name != "lo"}
|
devices = {name: _extract_inet(addrs) for name, addrs in devices_raw.items() if name != "lo"}
|
||||||
|
|
||||||
return devices or "unknown"
|
return devices
|
||||||
|
|
||||||
|
|
||||||
def get_gateway():
|
def get_gateway():
|
||||||
|
@ -64,10 +64,10 @@ def get_gateway():
|
||||||
output = subprocess.check_output('ip route show'.split())
|
output = subprocess.check_output('ip route show'.split())
|
||||||
m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output)
|
m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output)
|
||||||
if not m:
|
if not m:
|
||||||
return "unknown"
|
return None
|
||||||
|
|
||||||
addr = _extract_inet(m.group(1), True)
|
addr = _extract_inet(m.group(1), True)
|
||||||
return addr.popitem()[1] if len(addr) == 1 else "unknown"
|
return addr.popitem()[1] if len(addr) == 1 else None
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
Loading…
Add table
Reference in a new issue