Skip to content

Commit

Permalink
Merge pull request #524 from Ankurk99/systemd
Browse files Browse the repository at this point in the history
package discovery-engine as a systemd service
  • Loading branch information
nyrahul committed Aug 16, 2022
2 parents 641bef0 + b516729 commit f1f300f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
64 changes: 54 additions & 10 deletions src/.goreleaser.yml
@@ -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
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
11 changes: 11 additions & 0 deletions src/packaging/knoxAutoPolicy.service
@@ -0,0 +1,11 @@
[Unit]
Description=knoxAutoPolicy

[Service]
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
@@ -0,0 +1,4 @@
set -e

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

0 comments on commit f1f300f

Please sign in to comment.