2021-08-17 17:15:40 +00:00
|
|
|
export GIT_ROOT := $(shell git rev-parse --show-toplevel)
|
|
|
|
# Useful for showing enode address
|
|
|
|
PUBLIC_IP ?= $(shell curl -s https://ipecho.net/plain)
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
RED := $(shell tput -Txterm setaf 1)
|
|
|
|
GRN := $(shell tput -Txterm setaf 2)
|
|
|
|
YLW := $(shell tput -Txterm setaf 3)
|
|
|
|
RST := $(shell tput -Txterm sgr0)
|
|
|
|
BLD := $(shell tput bold)
|
|
|
|
|
2019-12-22 14:51:15 +00:00
|
|
|
# by default we run the service as user
|
|
|
|
SCTL_OPTS := --user
|
|
|
|
JRNL_OPTS := --user-unit
|
|
|
|
SERVICE_DIR := $(HOME)/.config/systemd/user/
|
|
|
|
# with sudo it will run as a system service
|
|
|
|
ifeq ($(USER), root)
|
|
|
|
SCTL_OPTS :=
|
|
|
|
JRNL_OPTS := --unit
|
|
|
|
SERVICE_DIR := /etc/systemd/system/
|
|
|
|
endif
|
|
|
|
|
2019-11-28 23:56:34 +00:00
|
|
|
# Settings
|
2020-01-08 12:40:08 +00:00
|
|
|
export SERVICE_NAME ?= status-go-bootnode
|
2019-11-28 23:56:34 +00:00
|
|
|
export SERVICE_PATH ?= $(SERVICE_DIR)/$(SERVICE_NAME).service
|
2020-01-08 12:40:08 +00:00
|
|
|
export DATA_PATH ?= /var/tmp/$(SERVICE_NAME)
|
2019-11-28 23:56:34 +00:00
|
|
|
export KEY_PATH ?= $(DATA_PATH)/nodekey
|
|
|
|
export ADDR_PATH ?= $(DATA_PATH)/nodeaddr
|
2020-01-08 12:40:08 +00:00
|
|
|
export LOG_LEVEL ?= 3
|
2020-02-03 19:02:23 +00:00
|
|
|
export LISTEN_PORT ?= 30301
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
# Info
|
2021-08-24 13:13:10 +00:00
|
|
|
STATUS = $(shell systemctl $(SCTL_OPTS) is-active $(SERVICE_NAME))
|
|
|
|
NODE_ADDR = $(shell cat $(ADDR_PATH))
|
|
|
|
ENODE_ADDR = enode://$(NODE_ADDR)@$(PUBLIC_IP):$(LISTEN_PORT)
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
define INFO_MSG
|
2021-08-17 17:15:40 +00:00
|
|
|
* $(GRN)Your bootnode is listening on:$(RST) $(BLD)$(PUBLIC_IP):$(LISTEN_PORT)$(RST)
|
2021-08-24 13:13:10 +00:00
|
|
|
* $(GRN)Your enode address is:$(RST)
|
|
|
|
$(ENODE_ADDR)
|
2021-08-17 17:15:40 +00:00
|
|
|
|
|
|
|
$(YLW)Make sure that IP and TCP port are available from the internet!$(RST)
|
2019-11-28 23:56:34 +00:00
|
|
|
endef
|
|
|
|
export INFO_MSG
|
|
|
|
|
2019-12-09 23:06:44 +00:00
|
|
|
all: checks build genkey save-address service enable restart info
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
clean: stop disable rm-service forget
|
|
|
|
|
|
|
|
checks:
|
|
|
|
# this setup wont work without an os with systemd
|
|
|
|
ifeq (, $(shell which systemctl))
|
|
|
|
$(error $(RED)Your system does not have systemd$(RST))
|
|
|
|
endif
|
|
|
|
# if the service is already up just show some info
|
|
|
|
ifeq (active, $(STATUS))
|
|
|
|
$(info $(INFO_MSG))
|
|
|
|
$(error $(YLW)Service already started$(RST))
|
|
|
|
endif
|
|
|
|
|
|
|
|
genkey: $(DATA_PATH)
|
|
|
|
@$(GIT_ROOT)/build/bin/bootnode -genkey=$(KEY_PATH)
|
|
|
|
|
|
|
|
address: save-address
|
|
|
|
echo "$(NODE_ADDR)"
|
|
|
|
|
|
|
|
save-address:
|
|
|
|
@$(GIT_ROOT)/build/bin/bootnode -nodekey=$(KEY_PATH) -writeaddress > $(ADDR_PATH)
|
|
|
|
|
|
|
|
status:
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) status --no-pager $(SERVICE_NAME)
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
logs:
|
2019-12-22 14:51:15 +00:00
|
|
|
journalctl $(JRNL_OPTS) statusd
|
2019-11-28 23:56:34 +00:00
|
|
|
|
2021-08-17 17:15:40 +00:00
|
|
|
info:
|
|
|
|
@echo "$$INFO_MSG"
|
|
|
|
|
|
|
|
enode:
|
|
|
|
@echo "$(ENODE)"
|
|
|
|
|
2019-11-28 23:56:34 +00:00
|
|
|
enable:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(GRN)Enabling '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) enable $(SERVICE_NAME)
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
disable:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(YLW)Disabling '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) disable "${SERVICE_NAME}"
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
start:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(GRN)Starting '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) start $(SERVICE_NAME)
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
restart:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(YLW)Restarting '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) restart $(SERVICE_NAME)
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
stop:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(YLW)Stopping '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) stop "${SERVICE_NAME}"
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
forget:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(YLW)Stopping '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) daemon-reload
|
|
|
|
systemctl $(SCTL_OPTS) reset-failed
|
2019-11-28 23:56:34 +00:00
|
|
|
|
|
|
|
$(GIT_ROOT)/build/bin/bootnode:
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(GRN)Building bootnode binary...$(RST)"
|
2019-11-28 23:56:34 +00:00
|
|
|
@cd "$(GIT_ROOT)" && make bootnode
|
|
|
|
|
|
|
|
build: $(GIT_ROOT)/build/bin/bootnode
|
|
|
|
.PHONY: build
|
|
|
|
|
|
|
|
$(SERVICE_DIR):
|
2019-12-09 23:06:44 +00:00
|
|
|
echo $(SERVICE_DIR)
|
2019-11-28 23:56:34 +00:00
|
|
|
@mkdir -p $(SERVICE_DIR)
|
|
|
|
|
|
|
|
service: $(SERVICE_DIR)
|
2021-08-17 17:15:40 +00:00
|
|
|
@echo " * $(GRN)Generating '$(SERVICE_NAME)' service...$(RST)"
|
2019-11-28 23:56:34 +00:00
|
|
|
@envsubst < ./service.template > $(SERVICE_PATH)
|
|
|
|
|
|
|
|
$(DATA_PATH):
|
|
|
|
@mkdir -p $(DATA_PATH)
|
|
|
|
|
|
|
|
rm-service:
|
|
|
|
rm -f $(SERVICE_PATH)
|