OpenMediaVault-Plugin-Developers / installScript

script that installs omv-extras and openmediavault if not installed already.
1.1k stars 207 forks source link

Errors and not booting when installed with invalid hostname #49

Closed flintstone1409 closed 3 years ago

flintstone1409 commented 3 years ago

For my local devices I use hostnames like device.intern.my.domain (they point to local IPs). I normally just set this whole name as hostname using raspi-config, which wasn't a problem until now. But when I use this install script, it errors but still tries to reboot, but the Pi doesn't boot anymore (doesn't even give some output via HDMI).

Thats the error-part of the console output (I replaced the hostname with <my hostname>):

----------
          ID: configure_netplan_ethernet_eth0
    Function: file.managed
        Name: /etc/netplan/20-openmediavault-eth0.yaml
      Result: False
     Comment: Unable to manage file: Jinja error: hostname: The value '<my hostname>' is not a valid hostname.
              Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 498, in render_jinja_tmpl
                  output = template.render(**decoded_context)
                File "/usr/lib/python3/dist-packages/jinja2/asyncsupport.py", line 76, in render
                  return original_render(self, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1008, in render
                  return self.environment.handle_exception(exc_info, True)
                File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
                  reraise(exc_type, exc_value, tb)
                File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
                  raise value.with_traceback(tb)
                File "<template>", line 1, in top-level template code
                File "/var/cache/salt/minion/extmods/modules/omv_conf.py", line 39, in get
                  objs = db.get(id_, identifier)
                File "/usr/lib/python3/dist-packages/openmediavault/config/database.py", line 85, in get
                  query.execute()
                File "/usr/lib/python3/dist-packages/openmediavault/config/database.py", line 726, in execute
                  self._response = self._elements_to_object(elements)
                File "/usr/lib/python3/dist-packages/openmediavault/config/database.py", line 487, in _elements_to_object
                  result.validate()
                File "/usr/lib/python3/dist-packages/openmediavault/config/object.py", line 236, in validate
                  self.model.validate(self.get_dict())
                File "/usr/lib/python3/dist-packages/openmediavault/config/datamodel.py", line 202, in validate
                  self.schema.validate(data)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 175, in validate
                  self._validate_type(value, schema, name)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 229, in _validate_type
                  raise last_exception
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 200, in _validate_type
                  self._validate_object(value, schema, name)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 305, in _validate_object
                  self._check_properties(value, schema, name)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 519, in _check_properties
                  self._validate_type(value[propk], propv, path)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 229, in _validate_type
                  raise last_exception
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 209, in _validate_type
                  self._validate_string(value, schema, name)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 283, in _validate_string
                  self._check_format(value, schema, name)
                File "/usr/lib/python3/dist-packages/openmediavault/datamodel/schema.py", line 35, in _check_format
                  super()._check_format(value, schema, name)
                File "/usr/lib/python3/dist-packages/openmediavault/json/schema.py", line 419, in _check_format
                  name, "The value '%s' is not a valid hostname." % value
              openmediavault.json.schema.SchemaValidationException: hostname: The value '<my hostname>' is not a valid hostname.

              ; line 1

              ---
              {%- set dns_config = salt['omv_conf.get']('conf.system.network.dns') -%}    <======================
              {%- set mac_address = salt['grains.get']('hwaddr_interfaces:' + interface.devicename) -%}
              network:
                ethernets:
                  {{ interface.devicename }}:
                    match:
              [...]
              ---
     Started: 18:20:08.580347
    Duration: 92.127 ms
     Changes:
----------
          ID: apply_netplan_config
    Function: cmd.run
        Name: netplan apply
      Result: True
     Comment: Command "netplan apply" run
     Started: 18:20:08.672825
    Duration: 368.964 ms
     Changes:
              ----------
              pid:
                  32267
              retcode:
                  0
              stderr:
              stdout:

Summary for <my hostname>
------------
Succeeded: 7 (changed=6)
Failed:    1
------------
Total states run:     8
Total run time:   4.828 s
Network setup.  Rebooting...

I know I should not use such hostnames, but as it isn't a problem with other software the script should at least test for such a hostname before it destroys something which results in that the system doesn't boot anymore.

ryecoaaron commented 3 years ago

The script doesn’t have an issue with the hostname either. OMV itself does. I guess I could add a check but if you know it causes problems with OMV, don’t do it because adding a check still won’t fix the real issue. And netplan failing, should not cause the pi to not boot. I guess I could change the script to not reboot on netplan failure.

flintstone1409 commented 3 years ago

but if you know it causes problems with OMV, don’t do it

I know (now) that this causes issues, but other users don't ;)

I guess I could change the script to not reboot on netplan failure.

The best way to prevent the issues would probably be to do a check before running any of the netplan stuff, and just outputting an error telling the user to change the hostname (and then exiting the script). By just not rebooting the user might run into issues when rebooting after some time, not even knowing whats wrong.

ryecoaaron commented 3 years ago

Thousands of users have run the script and I’ve never heard of this issue. In fact, the only hostname issue I have seen with OMV since the beginning 12+ years ago is when someone sets the hostname longer than 15 characters and samba doesn’t work.

Obviously if the script skipped the reboot, there would be output. OMV is already telling you the hostname is bad. I will add something to the script but it will not check for everything that could possibly be wrong. Why not file an issue with OMV to allow your really long hostname?

ryecoaaron commented 3 years ago

raspi-config must be putting the fqdn in /etc/hostname. With the current script changings, if hostname -s reports a name with a dot in it, then you doing something wrong. If there is no dot in the output, then the script should do the right thing. It will add the domain name to the omv dns database config if hostname -d reports a domain name. https://github.com/OpenMediaVault-Plugin-Developers/installScript/commit/2c5d89fe69891658f885528a9942b3f426d87ac4

The script won't reboot if salt fails to apply the new network settings. But that doesn't mean the network connection will be in a working state. So, I don't know how useful this change is. https://github.com/OpenMediaVault-Plugin-Developers/installScript/commit/4aceceb5d4d040556d13051cd5cffef9f90c3f66

I will mention that is the guide was followed and then you changed the hostname from the web interface, you wouldn't have had these issues. https://forum.openmediavault.org/index.php?thread/28789-installing-omv5-on-raspberry-pi-s-armbian-sbc-s-i386-32-bit-platforms/