diff --git a/Makefile b/Makefile index d68ccae..853e3ff 100755 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SHELL := /bin/bash .ONESHELL: -.PHONY: linux linux-rpm darwin darwin-zip windows windows-zip test vendor +.PHONY: docker linux linux-rpm darwin darwin-zip windows windows-zip test vendor ## version LSB = $(shell lsb_release -i -s)$(shell lsb_release -r -s) @@ -38,15 +38,10 @@ bin: linux windows darwin ## build all platform binary ## docker run --network host --privileged \ ## -v /var/run:/var/run -v /etc/openlan/switch:/etc/openlan/switch \ ## openlan-switch:5.8.13 -docker: docker-switch docker-confd +docker: pkg + cp $(SD)/docker/openlan.docker $(BD) + cd $(BD) && docker build -t openlan:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan.docker . -docker-switch: pkg - cp $(SD)/docker/openlan-switch.docker $(BD) - cd $(BD) && docker build -t openlan-switch:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan-switch.docker . - -docker-confd: pkg - cp $(SD)/docker/openlan-confd.docker $(BD) - cd $(BD) && docker build -t openlan-confd:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan-confd.docker . clean: ## clean cache rm -rvf ./build diff --git a/dist/resource/openlan-confd.service b/dist/resource/openlan-confd.service index 0bbf3c9..1102477 100755 --- a/dist/resource/openlan-confd.service +++ b/dist/resource/openlan-confd.service @@ -9,8 +9,8 @@ PIDFile=/var/openlan/confd/confd.pid Restart=on-failure EnvironmentFile=-/etc/sysconfig/openlan/confd -ExecStart=/var/openlan/script/confd start --detach -ExecStop=/var/openlan/script/confd stop +ExecStart=/var/openlan/script/confd.sh start --detach +ExecStop=/var/openlan/script/confd.sh stop [Install] WantedBy=multi-user.target diff --git a/dist/script/confd b/dist/script/confd.sh similarity index 76% rename from dist/script/confd rename to dist/script/confd.sh index efb800d..1421c6d 100755 --- a/dist/script/confd +++ b/dist/script/confd.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex command=$1; shift options=$@; @@ -8,6 +8,8 @@ options=$@; dir=$(dirname $0) OVSDB_SERVER_BIN="/usr/bin/env ovsdb-server" +OVSDB_TOOL_BIN="/usr/bin/env ovsdb-tool" +[ "$OVSDB_DATABASE_SCH" == "" ] && OVSDB_DATABASE_SCH="/etc/openlan/switch/confd.schema.json" [ "$OVSDB_DATABASE" == "" ] && OVSDB_DATABASE="/etc/openlan/switch/confd.db" [ "$OVSDB_LOG_FILE" == "" ] && OVSDB_LOG_FILE="/var/openlan/confd/confd.log" [ "$OVSDB_SOCK" == "" ] && OVSDB_SOCK="/var/openlan/confd/confd.sock" @@ -18,14 +20,17 @@ function stop() { } function start() { + [ -e "$OVSDB_DATABASE" ] || { + $OVSDB_TOOL_BIN create $OVSDB_DATABASE $OVSDB_DATABASE_SCH + } set $OVSDB_SERVER_BIN $OVSDB_DATABASE - set "$@" -vconsole:emer -vsyslog:err -vfile:info + set "$@" -vconsole:info -vsyslog:off -vfile:off set "$@" --remote=punix:"$OVSDB_SOCK" set "$@" --log-file="$OVSDB_LOG_FILE" set "$@" --pidfile="$OVSDB_PID_FILE" [ "$OVSDB_OPTIONS" != "" ] && set "$@" $OVSDB_OPTIONS for opt in $options; do - set "$@" $opt + set "$@" $opt done OVS_RUNDIR="/var/openlan/confd" "$@" } diff --git a/dist/script/ovs-vswitchd.sh b/dist/script/ovs-vswitchd.sh new file mode 100755 index 0000000..64071c7 --- /dev/null +++ b/dist/script/ovs-vswitchd.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -ex + +/usr/sbin/ovs-vswitchd unix:/run/openvswitch/db.sock \ + -vconsole:info -vsyslog:off -vfile:off --mlockall \ + --pidfile diff --git a/dist/script/ovsdb-server.sh b/dist/script/ovsdb-server.sh new file mode 100755 index 0000000..49ac5f4 --- /dev/null +++ b/dist/script/ovsdb-server.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -ex + +if [ ! -f "/etc/openvswitch/conf.db" ]; then + ovsdb-tool create /etc/openvswitch/conf.db +elif ovsdb-tool needs-conversion /etc/openvswitch/conf.db | grep -s -w yes; then + ovsdb-tool convert /etc/openvswitch/conf.db +fi + +/usr/sbin/ovsdb-server /etc/openvswitch/conf.db \ + -vconsole:info -vsyslog:off -vfile:off \ + --remote=punix:/run/openvswitch/db.sock \ + --remote=db:Open_vSwitch,Open_vSwitch,manager_options \ + --pidfile diff --git a/dist/script/switch.sh b/dist/script/switch.sh new file mode 100755 index 0000000..1e13980 --- /dev/null +++ b/dist/script/switch.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -ex + +if [ ! -e "/etc/openlan/switch/switch.json" ]; then +cat >> /etc/openlan/switch/switch.json << EOF +{ + "cert": { + "directory": "/var/openlan/cert" + }, + "http": { + "public": "/var/openlan/public" + }, + "crypt": { + "secret": "cb2ff088a34d" + } +} +EOF +fi + +if [ ! -e "/etc/openlan/switch/network/example.json" ]; then +cat >> /etc/openlan/switch/network/example.json << EOF +{ + "name": "example", + "bridge": { + "address": "172.32.100.40/24" + } +} +EOF +fi + +/usr/bin/openlan-switch -conf:dir /etc/openlan/switch -log:level 20 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 48bc743..8ab97fc 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,16 +1,38 @@ version: "2.3" services: + ovsdb-server: + image: "openlan:latest" + entrypoint: ["/var/openlan/script/ovsdb-server.sh", "start"] + volumes: + - /opt/openlan/run/openvswitch:/run/openvswitch + - /opt/openlan/etc/openvswitch:/etc/openvswitch + ovs-vswitchd: + image: "openlan:latest" + privileged: true + entrypoint: ["/var/openlan/script/ovs-vswitchd.sh", "start"] + volumes: + - /opt/openlan/run/openvswitch:/run/openvswitch + depends_on: + - ovsdb-server confd: - image: "openlan-confd:latest" + image: "openlan:latest" + entrypoint: ["/var/openlan/script/confd.sh", "start"] volumes: - /opt/openlan/confd:/var/openlan/confd + - /opt/openlan/etc/openlan:/etc/openlan switch: - image: "openlan-switch:latest" + image: "openlan:latest" privileged: true + entrypoint: ["/var/openlan/script/switch.sh", "start"] ports: - 10000:10000 - 10002:10002 volumes: - /opt/openlan/confd:/var/openlan/confd + - /opt/openlan/run/openvswitch:/run/openvswitch + - /opt/openlan/etc/openvswitch:/etc/openvswitch + - /opt/openlan/etc/openlan:/etc/openlan depends_on: - confd + - ovsdb-server + - ovs-vswitchd diff --git a/docker/openlan-switch.docker b/docker/openlan-switch.docker deleted file mode 100755 index cd40a6a..0000000 --- a/docker/openlan-switch.docker +++ /dev/null @@ -1,23 +0,0 @@ -FROM centos:7 - -ARG BIN - -WORKDIR /root - -ADD ${BIN} /tmp - -RUN yum install -y epel-release centos-release-openstack-train \ - && yum install -y rdma-core libibverbs -RUN DOCKER=yes /tmp/${BIN} - -RUN rm -rf /tmp/* && rm -rf /var/cache/yum/* - -LABEL application="OpenLAN Switch Application" -LABEL maintainer="danieldin95@163.com" - -EXPOSE 10000/tcp -EXPOSE 10002/tcp -EXPOSE 10002/udp -EXPOSE 4500/udp - -CMD ["/usr/bin/openlan-switch", "-conf:dir", "/etc/openlan/switch", "-log:level", "20"] diff --git a/docker/openlan-confd.docker b/docker/openlan.docker similarity index 87% rename from docker/openlan-confd.docker rename to docker/openlan.docker index cadce1a..21e9440 100755 --- a/docker/openlan-confd.docker +++ b/docker/openlan.docker @@ -15,4 +15,4 @@ RUN rm -rf /tmp/* && rm -rf /var/cache/yum/* LABEL application="OpenLAN Switch Application" LABEL maintainer="danieldin95@163.com" -CMD ["/var/openlan/script/confd", "start"] +CMD ["/var/openlan/script/switch.sh", "start"] diff --git a/pkg/network/iptables.go b/pkg/network/iptables.go index 5b6b7d2..e1cfe7c 100755 --- a/pkg/network/iptables.go +++ b/pkg/network/iptables.go @@ -246,6 +246,6 @@ func IptInit() { } __iptablesInit__ = true if err := iptables.FirewalldInit(); err != nil { - libol.Info("IptInit %s", err) + libol.Debug("IptInit %s", err) } }