diff --git a/appliances/openvswitch-management.gns3a b/appliances/openvswitch-management.gns3a
index a31b36e..340ec46 100644
--- a/appliances/openvswitch-management.gns3a
+++ b/appliances/openvswitch-management.gns3a
@@ -16,6 +16,6 @@
"docker": {
"adapters": 16,
"image": "gns3/openvswitch:latest",
- "environment": "MANAGEMENT_INTERFACE=1"
+ "environment": "MANAGEMENT_INTERFACE=eth0"
}
}
diff --git a/docker/openvswitch/Dockerfile b/docker/openvswitch/Dockerfile
index 8ad3c1b..10aaee4 100644
--- a/docker/openvswitch/Dockerfile
+++ b/docker/openvswitch/Dockerfile
@@ -6,7 +6,7 @@ RUN apk add --no-cache openvswitch nano bash bash-completion
RUN sed -i s,/bin/ash,/bin/bash, /etc/passwd
# Enable bash completion
-RUN echo -e "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc
+RUN echo -e "source /etc/bash/bash_completion.sh" >> ~/.bashrc
# Enable openvswitch bash completion
RUN echo -e "source /usr/share/bash-completion/completions/ovs-vsctl-bashcomp.bash" >> ~/.bashrc
@@ -15,10 +15,8 @@ RUN echo -e "source /usr/share/bash-completion/completions/ovs-appctl-bashcomp.b
# Configure the prompt
RUN echo -e "PS1='\h:\w\$ '" >> ~/.bashrc
-RUN mkdir /var/run/openvswitch
+VOLUME [ "/root", "/etc/openvswitch" ]
-VOLUME /etc/openvswitch/
+ADD init.sh /etc/openvswitch/
-ADD boot.sh /bin/boot.sh
-
-CMD /bin/bash /bin/boot.sh
+CMD /etc/openvswitch/init.sh; bash
diff --git a/docker/openvswitch/README.md b/docker/openvswitch/README.md
new file mode 100644
index 0000000..13076dc
--- /dev/null
+++ b/docker/openvswitch/README.md
@@ -0,0 +1,18 @@
+# Docker Open vSwitch for GNS3
+
+This creates a container for using Open vSwitch in GNS3.
+
+This container supports ethernet interfaces and comes
+with bridges from br0 to br3.
+
+By default, all interfaces are connected to br0.
+
+If you set the `MANAGEMENT_INTERFACE` environment variable to
+an interface name, that interface will not be connected to br0.
+
+
+## Building the container
+
+```
+docker build -t gns3/openvswitch .
+```
diff --git a/docker/openvswitch/README.rst b/docker/openvswitch/README.rst
deleted file mode 100644
index 00b6716..0000000
--- a/docker/openvswitch/README.rst
+++ /dev/null
@@ -1,19 +0,0 @@
-Docker Open vSwitch for GNS3
-------------------------------
-
-This make a container for using Open vSwitch in GNS3 1.5 and later.
-
-This container support 16 ethernet interface and is shipped with
-bridge from br0 to br3.
-
-By default all interface are connected to the br0.
-
-If you set the environnement variable MANAGEMENT_INTERFACE to 1
-eth0 will not be attach to the container.
-
-Building the container
-#######################
-
-.. code:: bash
-
- docker build -t gns3/openvswitch .
diff --git a/docker/openvswitch/boot.sh b/docker/openvswitch/boot.sh
deleted file mode 100644
index b5ebd8a..0000000
--- a/docker/openvswitch/boot.sh
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2024 GNS3 Technologies Inc.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-
-if [[ ! -f "/etc/openvswitch/conf.db" ]]
-then
- ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
-
- ovsdb-server --detach --pidfile --remote=punix:/var/run/openvswitch/db.sock
- ovs-vswitchd --detach --pidfile
- ovs-vsctl --no-wait init
-
- x=0
- until [[ $x = "4" ]]; do
- ovs-vsctl add-br br$x
- ovs-vsctl set bridge br$x datapath_type=netdev
- x=$((x+1))
- done
-
- if [[ $MANAGEMENT_INTERFACE == 1 ]]
- then
- x=1
- else
- x=0
- fi
-
- until [[ $x = "16" ]]; do
- ovs-vsctl add-port br0 eth$x
- x=$((x+1))
- done
-else
- ovsdb-server --detach --pidfile --remote=punix:/var/run/openvswitch/db.sock
- ovs-vswitchd --detach --pidfile
-fi
-
-
-x=0
-until [[ $x = "4" ]]; do
- ip link set dev br$x up
- x=$((x+1))
-done
-
-/bin/bash
diff --git a/docker/openvswitch/init.sh b/docker/openvswitch/init.sh
new file mode 100755
index 0000000..d2abf47
--- /dev/null
+++ b/docker/openvswitch/init.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 GNS3 Technologies Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+firstrun=0
+[ -f "/etc/openvswitch/conf.db" ] || firstrun=1
+
+if [ $firstrun -ne 0 ]; then
+ # create database
+ ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
+fi
+
+# start openvswitch daemons
+mkdir -p /var/log/openvswitch /var/run/openvswitch
+ovsdb-server --detach --pidfile --remote=punix:/var/run/openvswitch/db.sock \
+ --log-file --verbose=off:syslog
+ovs-vswitchd --detach --pidfile --log-file --verbose=off:syslog
+
+if [ $firstrun -ne 0 ]; then
+ ovs-vsctl --no-wait init
+
+ # create br0..br3
+ for intf in br0 br1 br2 br3; do
+ ovs-vsctl add-br $intf
+ ovs-vsctl set bridge $intf datapath_type=netdev
+ done
+
+ # add all ethernet interfaces to br0, except MANAGEMENT_INTERFACE
+ [ "$MANAGEMENT_INTERFACE" = 1 ] && MANAGEMENT_INTERFACE=eth0
+ sed -n 's/^ *\(eth[0-9]*\): .*/\1/p' /proc/net/dev | sort -V | \
+ while read -r intf; do
+ [ "$intf" = "$MANAGEMENT_INTERFACE" ] || ovs-vsctl add-port br0 "$intf"
+ done
+fi
+
+# activate br0..br3
+for intf in br0 br1 br2 br3; do
+ ip link set dev $intf up
+done