From 4adb31c7596f8047df03da8086025dfd36c694d8 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Thu, 2 Jun 2022 14:26:30 +0800 Subject: [PATCH] ci: deb packaging with ekuiper --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++ package/create_neuron_deb.py | 8 +++++-- package/deb/neuron/postinst | 10 +++++++- package/deb/neuron/prerm | 4 +++- package/ekuiper.sh | 44 ++++++++++++++++++++++++++++++++++ package/mkdeb.py | 7 ++++-- package/neuron.ekuiper.service | 18 ++++++++++++++ package/neuron.service | 1 + 8 files changed, 114 insertions(+), 6 deletions(-) create mode 100755 package/ekuiper.sh create mode 100644 package/neuron.ekuiper.service diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e25fbed..5f13fa7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,28 @@ jobs: with: submodules: recursive + - name: fetch ekuiper + if: ${{ matrix.arch[5] != 'armhf' }} + uses: dsaltares/fetch-gh-release-asset@master + env: + EKUIPER_VERSION: 1.5.0 + with: + repo: "lf-edge/ekuiper" + version: "tags/${{ env.EKUIPER_VERSION }}" + file: "kuiper-${{ env.EKUIPER_VERSION }}-linux-${{ matrix.arch[5] }}.tar.gz" + target: "ekuiper.tar.gz" + + - name: fetch ekuiper arm + if: ${{ matrix.arch[5] == 'armhf' }} + uses: dsaltares/fetch-gh-release-asset@master + env: + EKUIPER_VERSION: 1.5.0 + with: + repo: "lf-edge/ekuiper" + version: "tags/${{ env.EKUIPER_VERSION }}" + file: "kuiper-${{ env.EKUIPER_VERSION }}-linux-arm.tar.gz" + target: "ekuiper.tar.gz" + - name: install run: sudo apt-get update && sudo apt-get install -y ${{ matrix.arch[2] }} ${{ matrix.arch[3] }} pkg-config alien @@ -52,6 +74,7 @@ jobs: cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/${{ matrix.arch[0] }}.cmake \ -DCMAKE_BUILD_TYPE=Release -DDISABLE_UT=ON make -j4 + - name: get version id: get_version run: echo "::set-output name=version::$(cat version)" @@ -60,6 +83,10 @@ jobs: env: ARCH: ${{ matrix.arch[5] }} run: | + pwd + find . -iname "*kuiper*" + mkdir -p build/ekuiper + tar xvf ekuiper.tar.gz --strip-components=1 -C build/ekuiper ./package.sh -p ${ARCH} -n neuron-${{ steps.get_version.outputs.version }} cd package python3 create_neuron_deb.py ${{ steps.get_version.outputs.version }} ${{ matrix.arch[5] }} @@ -75,6 +102,7 @@ jobs: *.tar.gz *.deb *.rpm + !ekuiper.tar.gz - name: Create neuron sdk package run: | diff --git a/package/create_neuron_deb.py b/package/create_neuron_deb.py index 38208eff..535eb908 100755 --- a/package/create_neuron_deb.py +++ b/package/create_neuron_deb.py @@ -5,7 +5,7 @@ import sys rules = [] rules.append(mkdeb.FileMap("deb/neuron/conffiles", - "/DEBIAN/", "r", "conffiles")) + "/DEBIAN/", "r", "conffiles")) rules.append(mkdeb.FileMap("deb/neuron/postinst", "/DEBIAN/", "r", "postinst")) rules.append(mkdeb.FileMap("deb/neuron/preinst", "/DEBIAN/", "r", "preinst")) rules.append(mkdeb.FileMap("deb/neuron/prerm", "/DEBIAN/", "r", "prerm")) @@ -25,7 +25,7 @@ rules.append(mkdeb.FileMap("../neuron.key", "/opt/neuron/config/")) rules.append(mkdeb.FileMap("../neuron.pem", "/opt/neuron/config/")) rules.append(mkdeb.FileMap("../default_plugins.json", - "/opt/neuron/persistence/", "r", "plugins.json")) + "/opt/neuron/persistence/", "r", "plugins.json")) rules.append(mkdeb.FileMap("../build/libneuron-base.so", "/usr/local/lib/")) @@ -43,6 +43,10 @@ rules.append(mkdeb.FileMap( rules.append(mkdeb.FileMap( "../plugins/modbus/modbus-tcp.json", "/opt/neuron/plugins/schema/")) +rules.append(mkdeb.FileMap("../build/ekuiper", "/opt/neuron/")) +rules.append(mkdeb.FileMap("ekuiper.sh", "/opt/neuron/ekuiper/", "x")) +rules.append(mkdeb.FileMap("neuron.ekuiper.service", "/lib/systemd/system/")) + mkdeb.create_deb_file(rules) mkdeb.create_control("neuron", sys.argv[1], sys.argv[2], "neuron", "") diff --git a/package/deb/neuron/postinst b/package/deb/neuron/postinst index 4d028960..1279fadf 100755 --- a/package/deb/neuron/postinst +++ b/package/deb/neuron/postinst @@ -4,4 +4,12 @@ echo "postinst" ldconfig systemctl daemon-reload systemctl enable neuron -systemctl start neuron \ No newline at end of file +systemctl start neuron +systemctl enable neuron.ekuiper +systemctl start neuron.ekuiper + +# create ekuiper stream for neuron +sleep 1 +curl -X POST --location http://127.0.0.1:9081/streams \ + -H 'Content-Type: application/json' \ + -d '{"sql":"CREATE STREAM neuronStream() WITH (TYPE=\"neuron\",FORMAT=\"json\",SHARED=\"true\");"}' diff --git a/package/deb/neuron/prerm b/package/deb/neuron/prerm index ffdbe51d..9e583393 100755 --- a/package/deb/neuron/prerm +++ b/package/deb/neuron/prerm @@ -1,5 +1,7 @@ #!/bin/bash echo "prerm" +systemctl disable neuron.ekuiper +systemctl stop neuron.ekuiper systemctl disable neuron -systemctl stop neuron \ No newline at end of file +systemctl stop neuron diff --git a/package/ekuiper.sh b/package/ekuiper.sh new file mode 100755 index 00000000..0c8a0d10 --- /dev/null +++ b/package/ekuiper.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# +# NEURON IIoT System for Industry 4.0 +# Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +set -e -u + +case $1 in + start) + nohup /opt/neuron/ekuiper/bin/kuiperd >> /opt/neuron/ekuiper/log/nohup.out & + ;; + stop) + pid=$(ps -ef |grep kuiperd |grep -v "grep" | awk '{print $2}') + while $(kill "$pid" 2>/dev/null); do + sleep 1 + done + ;; + ping) + if [ "$(curl -sl -w %{http_code} 127.0.0.1:9081 -o /dev/null)" = "200" ]; then + echo pong + else + echo "Ping kuiper failed" + exit 1 + fi + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|ping|restart|force-reload|status}" >&2 + exit 3 + ;; +esac diff --git a/package/mkdeb.py b/package/mkdeb.py index f6cbe939..2d03defe 100755 --- a/package/mkdeb.py +++ b/package/mkdeb.py @@ -78,14 +78,17 @@ def create_deb_file(rules): src = r.src dstpath = fix_dri + r.dst dst = dstpath + r.filename - if not os.path.isfile(src): + if not os.path.exists(src): print("%s not exist!" % src) continue if not os.path.exists(dstpath): os.makedirs(dstpath) - shutil.copyfile(src, dst) + if os.path.isfile(src): + shutil.copyfile(src, dst) + else: + shutil.copytree(src, dst, dirs_exist_ok=True) if r.mode == "x": os.chmod(dst, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXGRP | stat.S_IWGRP | stat.S_IRGRP) diff --git a/package/neuron.ekuiper.service b/package/neuron.ekuiper.service new file mode 100644 index 00000000..a0929291 --- /dev/null +++ b/package/neuron.ekuiper.service @@ -0,0 +1,18 @@ +[Unit] +Description=ekuiper daemon +After=neuron.service +Requires=neuron.service +PartOf=neuron.service + +[Service] +Group=root +Type=forking +Environment=HOME=/opt/neuron/ekuiper +WorkingDirectory=/opt/neuron/ekuiper +ExecStart=/bin/sh /opt/neuron/ekuiper/ekuiper.sh start +LimitNOFILE=1048576 +ExecStop=/bin/sh /opt/neuron/ekuiper/ekuiper.sh stop + +[Install] +WantedBy=multi-user.target +WantedBy=neuron.service diff --git a/package/neuron.service b/package/neuron.service index d86cb528..e8060fe7 100644 --- a/package/neuron.service +++ b/package/neuron.service @@ -1,6 +1,7 @@ [Unit] Description=Neuron daemon After=network.target +Wants=neuron.ekuiper.service [Service] Type=simple