diff --git a/.gitignore b/.gitignore index df92b10d4..e4a08c1a2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ report.xml outputs.json builds/ *.tfstate.backup +.vscode diff --git a/Makefile b/Makefile index c6ec8518a..5f5c26f5f 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,8 @@ default: test build # Remove build directories clean: rm -rf vendor build - + rm -f *.rpm *.deb + # Set up vendor directory using `go mod vendor` vendor: go.mod $(GO) mod vendor @@ -134,10 +135,9 @@ release-sans-ui: check-clean package: go build -o featurebase ./cmd/featurebase - nfpm package --packager deb --target featurebase_$(VERSION_ID).deb - nfpm package --packager rpm --target featurebase_$(VERSION_ID).rpm - - + GOARCH=$(GOARCH) VERSION=$(VERSION) nfpm package --packager deb --target featurebase.$(VERSION).$(GOARCH).deb + GOARCH=$(GOARCH) VERSION=$(VERSION) nfpm package --packager rpm --target featurebase.$(VERSION).$(GOARCH).rpm + # We allow setting a custom docker-compose "project". Multiple of the # same docker-compose environment can exist simultaneously as long as # they use different projects (the project name is prepended to diff --git a/install/featurebase.conf b/install/featurebase.conf index 6068046b0..72500405a 100644 --- a/install/featurebase.conf +++ b/install/featurebase.conf @@ -38,11 +38,8 @@ # # bind-grpc = "0.0.0.0:20101" - - # Directory to store Featurebase data files -data-dir = "/var/lib/molecula" - +data-dir = "/var/lib/featurebase" # ============================================================================== # CORS (Cross-Origin Resource Sharing) Allowed Origins diff --git a/install/featurebase.debian.service b/install/featurebase.debian.service index 162264106..7837afd0a 100644 --- a/install/featurebase.debian.service +++ b/install/featurebase.debian.service @@ -7,7 +7,7 @@ RestartSec=30 Restart=on-failure EnvironmentFile= User=molecula -ExecStart=/usr/local/bin/featurebase server -c /etc/featurebase.conf +ExecStart=/usr/bin/featurebase server -c /etc/featurebase/featurebase.conf [Install] WantedBy=multi-user.target diff --git a/install/featurebase.redhat.service b/install/featurebase.redhat.service index cf507d8b0..f9a2962f4 100644 --- a/install/featurebase.redhat.service +++ b/install/featurebase.redhat.service @@ -1,12 +1,18 @@ [Unit] -Description="Service for FeatureBase" +After=network.target +Description=Service for FeatureBase +Documentation=https://docs.molecula.cloud/ +DefaultDependencies=no +ConditionPathExists=/etc/featurebase/featurebase.conf [Service] -RestartSec=30 -Restart=on-failure +User=featurebase +Group=featurebase +WorkingDirectory=/var/lib/featurebase EnvironmentFile= -User=molecula -ExecStart=/usr/local/bin/featurebase server -c /etc/featurebase.conf +ExecStart=/usr/bin/featurebase server -c /etc/featurebase/featurebase.conf +Restart=on-failure +RestartSec=30 [Install] WantedBy=multi-user.target diff --git a/install/postinstall.sh b/install/postinstall.sh new file mode 100644 index 000000000..d50279ee9 --- /dev/null +++ b/install/postinstall.sh @@ -0,0 +1,2 @@ +systemctl enable featurebase +systemctl start featurebase diff --git a/install/preinstall.sh b/install/preinstall.sh new file mode 100755 index 000000000..1df481c3c --- /dev/null +++ b/install/preinstall.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +USERNAME=featurebase +GROUPNAME=featurebase +HOMEDIR=/var/lib/molecula + +getent group $GROUPNAME >/dev/null || groupadd -r $GROUPNAME +getent passwd $USERNAME >/dev/null || \ + useradd -r -g $GROUPNAME -d $HOMEDIR -s /sbin/nologin \ + -c "Featurebase Service Account" $USERNAME + +exit 0 diff --git a/install/preremove.sh b/install/preremove.sh new file mode 100755 index 000000000..0b9a0ea43 --- /dev/null +++ b/install/preremove.sh @@ -0,0 +1,2 @@ +systemctl stop featurebase +systemctl disable featurebase diff --git a/nfpm.yaml b/nfpm.yaml index 636f5e03c..d21291353 100644 --- a/nfpm.yaml +++ b/nfpm.yaml @@ -1,6 +1,5 @@ name: "featurebase" arch: "${GOARCH}" -platform: "${GOOS}" version: "${VERSION}" section: "default" priority: "extra" @@ -10,6 +9,39 @@ vendor: "Molecula" homepage: "https://molecula.com" contents: - src: ./featurebase - dst: /usr/local/bin/featurebase - - dst: /etc/featurebase.conf - type: ghost + dst: /usr/bin/featurebase + - src: ./install/featurebase.conf + dst: /etc/featurebase/featurebase.conf + type: config|noreplace + file_info: + owner: featurebase + group: featurebase + - src: ./install/featurebase.redhat.service + dst: /usr/lib/systemd/system/featurebase.service + packager: rpm + - src: ./install/featurebase.debian.service + dst: /lib/systemd/system/featurebase.service + packager: deb + - dst: /var/log/molecula # We use vendor name on log directory in case other molecula components need it. + type: dir + file_info: + mode: 0755 + owner: featurebase + group: featurebase + - dst: /var/lib/featurebase + type: dir + file_info: + mode: 0755 + owner: featurebase + group: featurebase + - dst: /etc/featurebase # Keeping the config writable by the featurebase user is necessary for the agent. + type: dir + file_info: + mode: 0755 + owner: featurebase + group: featurebase + +scripts: + preinstall: ./install/preinstall.sh + postinstall: ./install/postinstall.sh + preremove: ./install/preremove.sh