From 95345b673ae9c3626108774836ee6d1c0cb2f361 Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Wed, 6 Nov 2019 16:09:07 +0300 Subject: [PATCH 1/3] added systemd unit file and target for make --- Makefile | 15 +++++++++++++++ neo-go.service | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 neo-go.service diff --git a/Makefile b/Makefile index f37bf24e4..b8d742442 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,21 @@ build: deps && export CGO_ENABLED=0 \ && go build -v -mod=vendor -ldflags $(BUILD_FLAGS) -o ${BINARY} ./cli/main.go +install: build + @echo "=> Preparing directories and configs" + @id neo-go || useradd -s /usr/sbin/nologin -d /var/lib/neo-go neo-go \ + && mkdir -p /var/lib/neo-go \ + && chown -R neo-go:neo-go /var/lib/neo-go + @echo "=> Installing systemd service" + @mkdir -p /etc/neo-go \ + && mkdir -p /etc/systemd/system/ \ + && cp ./neo-go.service /etc/systemd/system/ \ + && cp ./config/protocol.mainnet.yml /etc/neo-go \ + && systemctl enable neo-go.service \ + && mv ./bin/neo-go /usr/local/bin/neo-go \ + && chown neo-go:neo-go /usr/local/bin/neo-go + @echo "Done. Start Neo Go with 'systemctl start neo-go.service'" + image: @echo "=> Building image" @docker build -t cityofzion/neo-go:latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . diff --git a/neo-go.service b/neo-go.service new file mode 100644 index 000000000..2bb69c468 --- /dev/null +++ b/neo-go.service @@ -0,0 +1,18 @@ +[Unit] +Description=Neo Go node +Requires=network.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/neo-go node --mainnet --config-path=/etc/neo-go +User=neo-go +Group=neo-go +Restart=always +RestartSec=5 +StandardError=syslog +SyslogIdentifier=neo-go +PrivateTmp=true +WorkingDirectory=/var/lib/neo-go + +[Install] +WantedBy=multi-user.target From a00275bebddd14f8dbcf4bcb51248b95de355cfb Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Thu, 7 Nov 2019 14:57:02 +0300 Subject: [PATCH 2/3] fixes after review --- Makefile | 31 +++++++++++++++++++------------ neo-go.service | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b8d742442..041dd003a 100644 --- a/Makefile +++ b/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//')" @@ -20,19 +25,21 @@ build: deps && go build -v -mod=vendor -ldflags $(BUILD_FLAGS) -o ${BINARY} ./cli/main.go install: build - @echo "=> Preparing directories and configs" - @id neo-go || useradd -s /usr/sbin/nologin -d /var/lib/neo-go neo-go \ - && mkdir -p /var/lib/neo-go \ - && chown -R neo-go:neo-go /var/lib/neo-go @echo "=> Installing systemd service" - @mkdir -p /etc/neo-go \ - && mkdir -p /etc/systemd/system/ \ - && cp ./neo-go.service /etc/systemd/system/ \ - && cp ./config/protocol.mainnet.yml /etc/neo-go \ - && systemctl enable neo-go.service \ - && mv ./bin/neo-go /usr/local/bin/neo-go \ - && chown neo-go:neo-go /usr/local/bin/neo-go - @echo "Done. Start Neo Go with 'systemctl start neo-go.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" diff --git a/neo-go.service b/neo-go.service index 2bb69c468..88191555c 100644 --- a/neo-go.service +++ b/neo-go.service @@ -4,7 +4,7 @@ Requires=network.target [Service] Type=simple -ExecStart=/usr/local/bin/neo-go node --mainnet --config-path=/etc/neo-go +ExecStart=/usr/bin/neo-go node --mainnet --config-path=/etc/neo-go User=neo-go Group=neo-go Restart=always From 2afb1851d616e82d0debdf53dc4ecb67247444c7 Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Wed, 13 Nov 2019 15:05:13 +0300 Subject: [PATCH 3/3] service file templating --- Makefile | 5 ++++- neo-go.service => neo-go.service.template | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) rename neo-go.service => neo-go.service.template (69%) diff --git a/Makefile b/Makefile index 041dd003a..02eb1966a 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,10 @@ build: deps && export CGO_ENABLED=0 \ && go build -v -mod=vendor -ldflags $(BUILD_FLAGS) -o ${BINARY} ./cli/main.go -install: build +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) \ diff --git a/neo-go.service b/neo-go.service.template similarity index 69% rename from neo-go.service rename to neo-go.service.template index 88191555c..4d919e6a9 100644 --- a/neo-go.service +++ b/neo-go.service.template @@ -4,7 +4,7 @@ Requires=network.target [Service] Type=simple -ExecStart=/usr/bin/neo-go node --mainnet --config-path=/etc/neo-go +ExecStart=BINDIR/neo-go node --mainnet --config-path=SYSCONFIGDIR/neo-go User=neo-go Group=neo-go Restart=always @@ -12,7 +12,7 @@ RestartSec=5 StandardError=syslog SyslogIdentifier=neo-go PrivateTmp=true -WorkingDirectory=/var/lib/neo-go +WorkingDirectory=UNITWORKDIR [Install] WantedBy=multi-user.target