Skip to content

Commit

Permalink
package discovery-engine as a systemd service
Browse files Browse the repository at this point in the history
Signed-off-by: Ankur Kothiwal <ankur.kothiwal@accuknox.com>
  • Loading branch information
Ankurk99 committed Aug 16, 2022
1 parent 6cd61f8 commit 4baabee
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
64 changes: 54 additions & 10 deletions src/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,71 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
project_name: knoxAutoPolicy

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=1
- binary: "opt/knoxAutoPolicy/src/knoxAutoPolicy"
id: knoxAutoPolicy
goos:
- linux
#- windows
#- darwin
goarch:
- amd64

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- id: "knoxAutoPolicy"
builds:
- "knoxAutoPolicy"
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
files:
- src: ./conf/local-file.yaml
dst: /opt/knoxAutoPolicy
strip_parent: true
- src: ./packaging/knoxAutoPolicy.service
dst: /usr/lib/systemd/system
strip_parent: true

nfpms:
- id: "knoxAutoPolicy"
builds:
- "knoxAutoPolicy"
formats:
- deb
- rpm
replaces:
- knoxAutoPolicy
maintainer: "Ankur Kothiwal <ankur.kothiwal@accuknox.com>"
description: |
Auto policy discovery engine
file_name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
bindir: /
contents:
- dst: /opt/knoxAutoPolicy
type: dir
- src: ./conf/local-file.yaml
dst: /opt/knoxAutoPolicy/conf/local-file.yaml
type: config
- src: ./packaging/knoxAutoPolicy.service
dst: /usr/lib/systemd/system/knoxAutoPolicy.service
type: config
- src: /opt/knoxAutoPolicy/src/knoxAutoPolicy
dst: /usr/local/bin/knoxAutoPolicy
type: symlink
scripts:
postinstall: packaging/post-install.sh
overrides:
deb:
dependencies:
- make
rpm:
dependencies:
- make

checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
10 changes: 10 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ clean:
.PHONY: image
image:
cd $(CURDIR)/build; $(MAKE)

.PHONY: local-release
local-release: build
ifeq (, $(shell which goreleaser))
@{ \
set -e ;\
go install github.com/goreleaser/goreleaser@latest ;\
}
endif
cd $(CURDIR); VERSION=$(shell git describe --tags --always --dirty) goreleaser release --rm-dist --skip-publish --skip-sign --skip-validate --snapshot
12 changes: 12 additions & 0 deletions src/packaging/discovery-engine.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=knoxAutoPolicy

[Service]
User=root
KillMode=process
EnvironmentFile=/opt/knoxAutoPolicy/local-file.yaml
WorkingDirectory=/opt/knoxAutoPolicy/
ExecStart=/opt/knoxAutoPolicy/src/knoxAutoPolicy

[Install]
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions src/packaging/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e

/bin/systemctl daemon-reload
/bin/systemctl start knoxAutoPolicy.service

0 comments on commit 4baabee

Please sign in to comment.