From a5ffe5562741e258b879967361664f468c3f6213 Mon Sep 17 00:00:00 2001
From: totemofwolf <gk.wl@qq.com>
Date: Thu, 1 Apr 2021 18:59:54 +0800
Subject: [PATCH 1/4] feat: support manager-api systemd startup script

---
 Makefile                             |  1 +
 deps/manager-api.service             | 13 +++++++++++++
 dockerfiles/Dockerfile.dashboard.rpm |  7 +++++--
 3 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 deps/manager-api.service

diff --git a/Makefile b/Makefile
index 02f21450d..92fd2313d 100644
--- a/Makefile
+++ b/Makefile
@@ -69,6 +69,7 @@ package-dashboard-rpm:
 		--iteration $(iteration) \
 		--description 'Apache APISIX Dashboard is designed to make it as easy as possible for users to operate Apache APISIX through a frontend interface.'  \
 		--license "ASL 2.0" \
+		--after-install =(echo "systemctl daemon-reload && systemctl enable manager-api.service && chown -R nobody: /usr/local/apisix/dashboard/logs") \
 		-C ${PWD}/build/rpm/output/apisix/dashboard/ \
 		-p ${PWD}/output/ \
 		--url 'https://github.com/apache/apisix-dashboard'
diff --git a/deps/manager-api.service b/deps/manager-api.service
new file mode 100644
index 000000000..434497eaf
--- /dev/null
+++ b/deps/manager-api.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=APACHE APISIX Manager-api Service
+After=network.target
+
+[Service]
+Type=simple
+User=nobody
+Restart=on-failure
+RestartSec=5s
+ExecStart=/usr/bin/manager-api -p /usr/local/apisix/dashboard
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dockerfiles/Dockerfile.dashboard.rpm b/dockerfiles/Dockerfile.dashboard.rpm
index d49ce7d72..d12dc070f 100644
--- a/dockerfiles/Dockerfile.dashboard.rpm
+++ b/dockerfiles/Dockerfile.dashboard.rpm
@@ -20,8 +20,9 @@ ARG checkout_v
 ARG iteration
 ARG dashboard_repo
 RUN set -x \
-    && mkdir -p /tmp/build/output/apisix/dashboard/usr/bin/ \
-    && mkdir -p /tmp/build/output/apisix/dashboard/usr/local/apisix/dashboard/ \
+    && mkdir -pv /tmp/build/output/apisix/dashboard/usr/bin/ \
+    && mkdir -pv /tmp/build/output/apisix/dashboard/usr/local/apisix/dashboard/ \
+    && mkdir -pv /tmp/build/output/apisix/dashboard/usr/lib/systemd/system \
     # config golang
     && export GO111MODULE=on \
     && export GOROOT=/usr/local/go \
@@ -31,6 +32,8 @@ RUN set -x \
     && mkdir gopath \
     && go env -w GOPROXY=https://goproxy.cn,direct \
     && cd /tmp/ \
+    # add startup script
+    && curl --silent --location https://raw.githubusercontent.com/totemofwolf/apisix-build-tools/service/deps/manager-api.service | tee /tmp/build/output/apisix/dashboard/usr/lib/systemd/system/manager-api.service \
     # get source code and build
     && git clone ${dashboard_repo} \
     && cd apisix-dashboard \

From 7515413eb51d45dc6dd1028dc5546c744010048a Mon Sep 17 00:00:00 2001
From: totemofwolf <gk.wl@qq.com>
Date: Thu, 1 Apr 2021 19:45:10 +0800
Subject: [PATCH 2/4] fix: "/bin/sh: -c: line 7: syntax error near unexpected
 token `('" error

---
 Makefile              | 2 +-
 deps/after-install.sh | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
 create mode 100644 deps/after-install.sh

diff --git a/Makefile b/Makefile
index 92fd2313d..2f8fc0e1b 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ package-dashboard-rpm:
 		--iteration $(iteration) \
 		--description 'Apache APISIX Dashboard is designed to make it as easy as possible for users to operate Apache APISIX through a frontend interface.'  \
 		--license "ASL 2.0" \
-		--after-install =(echo "systemctl daemon-reload && systemctl enable manager-api.service && chown -R nobody: /usr/local/apisix/dashboard/logs") \
+		--after-install ${PWD}/deps/after-install.sh \
 		-C ${PWD}/build/rpm/output/apisix/dashboard/ \
 		-p ${PWD}/output/ \
 		--url 'https://github.com/apache/apisix-dashboard'
diff --git a/deps/after-install.sh b/deps/after-install.sh
new file mode 100644
index 000000000..52a375e05
--- /dev/null
+++ b/deps/after-install.sh
@@ -0,0 +1,3 @@
+systemctl daemon-reload \
+&& systemctl enable manager-api.service \
+&& chown -R nobody: /usr/local/apisix/dashboard/logs
\ No newline at end of file

From 57003112d9f29eeaa5ace13801dae409e91f44d4 Mon Sep 17 00:00:00 2001
From: totemofwolf <gk.wl@qq.com>
Date: Thu, 1 Apr 2021 20:29:11 +0800
Subject: [PATCH 3/4] add newline for after-install.sh

---
 deps/after-install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/deps/after-install.sh b/deps/after-install.sh
index 52a375e05..541ed37e4 100644
--- a/deps/after-install.sh
+++ b/deps/after-install.sh
@@ -1,3 +1,3 @@
 systemctl daemon-reload \
 && systemctl enable manager-api.service \
-&& chown -R nobody: /usr/local/apisix/dashboard/logs
\ No newline at end of file
+&& chown -R nobody: /usr/local/apisix/dashboard/logs

From 3a73894df5713f946063b896c37991a35684d319 Mon Sep 17 00:00:00 2001
From: nic-chen <johz@163.com>
Date: Tue, 20 Apr 2021 20:07:43 +0800
Subject: [PATCH 4/4] fix: use local service file

---
 deps/after-install.sh                                  | 2 +-
 deps/{manager-api.service => apisix-dashboard.service} | 2 +-
 dockerfiles/Dockerfile.dashboard.rpm                   | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
 rename deps/{manager-api.service => apisix-dashboard.service} (80%)

diff --git a/deps/after-install.sh b/deps/after-install.sh
index 541ed37e4..14febe73e 100644
--- a/deps/after-install.sh
+++ b/deps/after-install.sh
@@ -1,3 +1,3 @@
 systemctl daemon-reload \
-&& systemctl enable manager-api.service \
+&& systemctl enable apisix-dashboard.service \
 && chown -R nobody: /usr/local/apisix/dashboard/logs
diff --git a/deps/manager-api.service b/deps/apisix-dashboard.service
similarity index 80%
rename from deps/manager-api.service
rename to deps/apisix-dashboard.service
index 434497eaf..4c50105b7 100644
--- a/deps/manager-api.service
+++ b/deps/apisix-dashboard.service
@@ -1,5 +1,5 @@
 [Unit]
-Description=APACHE APISIX Manager-api Service
+Description=APACHE APISIX Dashboard Service
 After=network.target
 
 [Service]
diff --git a/dockerfiles/Dockerfile.dashboard.rpm b/dockerfiles/Dockerfile.dashboard.rpm
index d12dc070f..3a55d89ca 100644
--- a/dockerfiles/Dockerfile.dashboard.rpm
+++ b/dockerfiles/Dockerfile.dashboard.rpm
@@ -6,6 +6,8 @@ ARG dashboard_repo="https://github.com/apache/apisix-dashboard.git"
 
 FROM ${image_base}:${image_tag}
 
+COPY ./deps/apisix-dashboard.service /tmp/build/output/apisix/dashboard/usr/lib/systemd/system/apisix-dashboard.service
+
 RUN set -x \
     # install dependency
     && yum install -y wget curl git which gcc make \
@@ -32,8 +34,6 @@ RUN set -x \
     && mkdir gopath \
     && go env -w GOPROXY=https://goproxy.cn,direct \
     && cd /tmp/ \
-    # add startup script
-    && curl --silent --location https://raw.githubusercontent.com/totemofwolf/apisix-build-tools/service/deps/manager-api.service | tee /tmp/build/output/apisix/dashboard/usr/lib/systemd/system/manager-api.service \
     # get source code and build
     && git clone ${dashboard_repo} \
     && cd apisix-dashboard \