openSUSE / wicked

Framework for network configuration
https://en.opensuse.org/Portal:Wicked
GNU General Public License v2.0
98 stars 49 forks source link

dbus-service interface="org.opensuse.Network.Scripts" not working #986

Open rnissl opened 9 months ago

rnissl commented 9 months ago

Documentation and implementation (extensions/dispatch) look promising, but for any reason, no one triggers these events mentioned in server.xml.

Am I missing any component which provides and serves dbus-service interface="org.opensuse.Network.Scripts"?

mtomaschewski commented 9 months ago

See man 5 ifcfg:

       PRE_UP_SCRIPT, POST_UP_SCRIPT, PRE_DOWN_SCRIPT and POST_DOWN_SCRIPT
              Here  you can hook a script (better: an executable) or systemd service name to per-
              form individual actions before/after the interface is set up  or  before/after  the
              interface is set down by specifying the script names in a space separated list.

              Wicked supports multiple schemes for the scripts.

                  - systemd:<service.name>" scheme:
                      Permits  a  service name or template which will be completed with interface
                      name as its argument, e.g.:

                           POST_UP_SCRIPT="systemd:my-eth-post-up.service"
                           POST_UP_SCRIPT="systemd:my-post-up@.service"

                      On pre-up and post-up actions the service is started, on pre-down and post-
                      down the service will be stopped.

                      The  service should make use of an device service unit binding BindsTo=sys-
                      subsystem-net-devices-%i.device so it gets stopped, when  the  device  sud-
                      denly disappears.  See also man systemd.unit(5).

                  - wicked:<script> scheme:
                      Permits  to specify a script or script directory either as an absolute path
                      or relative to the /etc/wicked/scripts directory, e.g.:

                           POST_UP_SCRIPT="wicked:post-up"
                           POST_UP_SCRIPT="wicked:post-up/script1"
                           POST_UP_SCRIPT="wicked:/path/to/my-script-or-dir"

                      The script is executed as "$script $action  $interface"  with  the  pre-up,
                      post-up, pre-down, post-down actions corresponding with the variable name.

                  - compat:suse:<script> scheme:
                      Permits  to specify a script or script directory either as an absolute path
                      or relative to the /etc/sysconfig/network/scripts directory, e.g.:

                           POST_UP_SCRIPT="compat:suse:post-up-script1"
                           POST_UP_SCRIPT="compat:suse:/path/to/my-script-or-dir"

                      The script is executed as "$script $interface $interface -o  $action"  with
                      the  pre-up,  post-up,  pre-down,  post-down actions corresponding with the
                      variable name.

              Note: The script scheme must be specified as a safeguard to not execute any old and
              not-compatible  sysconfig ifup scripts (which may depend on different files, inter-
              nal state, ...). Once the script has been adopted, prepend e.g. the  "compat:suse:"
              scheme to activate.

So when you add e.g. POST_UP_SCRIPT="systemd:my-post-up@.service" to ifcfg-dummy0, a wicked show-config dummy0 shows you the xml representation (usable in xml config /etc/wicked/ifconfig/*.xml):

  <scripts>
    <post-up>
      <script>systemd:my-post-up@.service</script>
    </post-up>
  </scripts>

As this is a systemd template service name containing an "@", the dispatcher will instantiate it / add the dummy0 interface name to it and start the my-post-up@dummy0.service as the post-up hook, that is in the last step/state when the leases are already applied, e.g. to trigger some interface setup depending service start.

mtomaschewski commented 9 months ago

Am I missing any component which provides and serves dbus-service interface="org.opensuse.Network.Scripts"?

It's triggered by the config, see scripts service scheme definition. The

<meta:mapping document-node="/scripts/post-up"  skip-unless-present="true" />

causes that wickedd-nanny serializes the content of the <scripts><post-up> xml node as script-config dict type and pass to the dispatcher commands implementing the org.opensuse.Network.Scripts service as specified in the server.xml config.

mtomaschewski commented 9 months ago

BTW: Easier to understand is the <dbus-service interface="org.opensuse.Network.Firewall">, see schema/firewall.xml. The /etc/wicked/extensions/firewall up command defined in server.xml will get the <firewall> node contents (zone here).

Note: there is no config node passed to any down actions as they don't act on config (which may be replaced by a new/different different config already, e.g. while wicked ifreload), but always on state of the interface or some "non-kernel" state created somewhere (/run/wicked/extension/<name>) during some up action triggered by the config.

boomer41 commented 9 months ago

Thanks for your info!

We added POST_UP_SCRIPTs to the respective interface configurations and it seems to work.