Skip to content

Commit 89e3299

Browse files
committed
package discovery-engine as a systemd service
Signed-off-by: Ankur Kothiwal <ankur.kothiwal@accuknox.com>
1 parent 6cd61f8 commit 89e3299

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

src/.goreleaser.yml

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# This is an example .goreleaser.yml file with some sensible defaults.
2-
# Make sure to check the documentation at https://goreleaser.com
1+
project_name: discovery-engine
2+
33
before:
44
hooks:
55
# You may remove this if you don't use go modules.
66
- go mod tidy
77
# you may remove this if you don't need go generate
88
- go generate ./...
9+
910
builds:
11+
- binary: discovery-engine
12+
id: discovery-engine
1013
- env:
1114
- CGO_ENABLED=1
1215
goos:
@@ -15,13 +18,62 @@ builds:
1518
#- darwin
1619
goarch:
1720
- amd64
21+
1822
archives:
23+
- id: "discovery-engine"
24+
builds:
25+
- "discovery-engine"
26+
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
27+
files:
28+
- src: ./conf/local-file.yaml
29+
dst: /opt/discovery-engine/local-file.yaml
30+
strip_parent: true
31+
- src: ./packaging/discovery-engine.service
32+
dst: /usr/lib/systemd/system
33+
strip_parent: true
1934
- replacements:
2035
darwin: Darwin
2136
linux: Linux
2237
windows: Windows
2338
386: i386
2439
amd64: x86_64
40+
41+
nfpms:
42+
- id: "discovery-engine"
43+
builds:
44+
- "discovery-engine"
45+
formats:
46+
- deb
47+
- rpm
48+
replaces:
49+
- discovery-engine
50+
maintainer: "Ankur Kothiwal <ankur.kothiwal@accuknox.com>"
51+
description: |
52+
Auto policy discovery engine
53+
file_name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
54+
bindir: /
55+
contents:
56+
- dst: /opt/discovery-engine
57+
type: dir
58+
- src: ./conf/local-file.yaml
59+
dst: /opt/discovery-engine/local-file.yaml
60+
type: config
61+
- src: ./packaging/discovery-engine.service
62+
dst: /usr/lib/systemd/system/discovery-engine.service
63+
type: config
64+
- src: /opt/src/discovery-engine
65+
dst: /usr/local/bin/discovery-engine
66+
type: symlink
67+
scripts:
68+
postinstall: packaging/post-install.sh
69+
overrides:
70+
deb:
71+
dependencies:
72+
- make
73+
rpm:
74+
dependencies:
75+
- make
76+
2577
checksum:
2678
name_template: 'checksums.txt'
2779
snapshot:

src/Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,27 @@ clean:
3838
.PHONY: image
3939
image:
4040
cd $(CURDIR)/build; $(MAKE)
41+
42+
.PHONY: systemd-deb
43+
systemd-deb: build
44+
ifeq (, $(shell which nfpm))
45+
@{ \
46+
set -e ;\
47+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
48+
}
49+
endif
50+
cd $(CURDIR); VERSION=$(shell git describe --tags --always --dirty) nfpm pkg --packager deb
51+
52+
.PHONY: systemd-rpm
53+
systemd-rpm: build
54+
ifeq (, $(shell which nfpm))
55+
@{ \
56+
set -e ;\
57+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
58+
}
59+
endif
60+
cd $(CURDIR); VERSION=$(shell git describe --tags --always --dirty) nfpm pkg --packager rpm
61+
62+
.PHONY: systemd
63+
systemd: systemd-deb systemd-rpm
64+
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=discovery-engine
3+
4+
[Service]
5+
User=root
6+
KillMode=process
7+
Environment=/opt/discovery-engine/local-file.yaml
8+
WorkingDirectory=/opt/discovery-engine/
9+
ExecStart=/opt/discovery-engine/src/discovery-engine
10+
11+
[Install]
12+
WantedBy=multi-user.target

src/packaging/post-install.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set -e
2+
3+
/bin/systemctl daemon-reload
4+
/bin/systemctl start discovery-engine.service

0 commit comments

Comments
 (0)