forked from TrueCloudLab/neoneo-go
Merge pull request #479 from nspcc-dev/feature/systemd-unit
added systemd unit file and target for make
This commit is contained in:
commit
d45a9f84f6
2 changed files with 43 additions and 0 deletions
25
Makefile
25
Makefile
|
@ -2,6 +2,11 @@ BRANCH = "master"
|
|||
REPONAME = "neo-go"
|
||||
NETMODE ?= "privnet"
|
||||
BINARY = "./bin/neo-go"
|
||||
DESTDIR = ""
|
||||
SYSCONFIGDIR = "/etc"
|
||||
BINDIR = "/usr/bin"
|
||||
SYSTEMDUNIT_DIR = "/lib/systemd/system"
|
||||
UNITWORKDIR = "/var/lib/neo-go"
|
||||
|
||||
REPO ?= "$(shell go list -m)"
|
||||
VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')"
|
||||
|
@ -19,6 +24,26 @@ build: deps
|
|||
&& export CGO_ENABLED=0 \
|
||||
&& go build -v -mod=vendor -ldflags $(BUILD_FLAGS) -o ${BINARY} ./cli/main.go
|
||||
|
||||
neo-go.service: neo-go.service.template
|
||||
@sed -r -e 's_BINDIR_$(BINDIR)_' -e 's_UNITWORKDIR_$(UNITWORKDIR)_' -e 's_SYSCONFIGDIR_$(SYSCONFIGDIR)_' $< >$@
|
||||
|
||||
install: build neo-go.service
|
||||
@echo "=> Installing systemd service"
|
||||
@mkdir -p $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
||||
&& mkdir -p $(SYSTEMDUNIT_DIR) \
|
||||
&& cp ./neo-go.service $(SYSTEMDUNIT_DIR) \
|
||||
&& cp ./config/protocol.mainnet.yml $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
||||
&& cp ./config/protocol.privnet.yml $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
||||
&& cp ./config/protocol.testnet.yml $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
||||
&& install -m 0755 -t $(BINDIR) $(BINARY) \
|
||||
|
||||
postinst: install
|
||||
@echo "=> Preparing directories and configs"
|
||||
@id neo-go || useradd -s /usr/sbin/nologin -d $(UNITWORKDIR) neo-go \
|
||||
&& mkdir -p $(UNITWORKDIR) \
|
||||
&& chown -R neo-go:neo-go $(UNITWORKDIR) $(BINDIR)/neo-go \
|
||||
&& systemctl enable neo-go.service
|
||||
|
||||
image:
|
||||
@echo "=> Building image"
|
||||
@docker build -t cityofzion/neo-go:latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
|
||||
|
|
18
neo-go.service.template
Normal file
18
neo-go.service.template
Normal file
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=Neo Go node
|
||||
Requires=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=BINDIR/neo-go node --mainnet --config-path=SYSCONFIGDIR/neo-go
|
||||
User=neo-go
|
||||
Group=neo-go
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardError=syslog
|
||||
SyslogIdentifier=neo-go
|
||||
PrivateTmp=true
|
||||
WorkingDirectory=UNITWORKDIR
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue