2019-11-28 22:52:38 +00:00
|
|
|
export GIT_ROOT = $(shell git rev-parse --show-toplevel)
|
|
|
|
|
|
|
|
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 22:52:38 +00:00
|
|
|
# Settings
|
|
|
|
export SERVICE_NAME ?= statusd
|
|
|
|
export SERVICE_DIR ?= $(HOME)/.config/systemd/user/
|
|
|
|
export SERVICE_PATH ?= $(SERVICE_DIR)/$(SERVICE_NAME).service
|
|
|
|
export LOG_LEVEL ?= INFO
|
|
|
|
export LISTEN_PORT ?= 30303
|
|
|
|
export DATA_PATH ?= /var/tmp/status-go-mail
|
|
|
|
# Necessary to make mailserver available publicly
|
|
|
|
export PUBLIC_IP ?= $(shell curl -s https://ipecho.net/plain)
|
|
|
|
|
|
|
|
# Info
|
2019-12-22 14:51:15 +00:00
|
|
|
STATUS = $(shell systemctl $(SCTL_OPTS) is-active $(SERVICE_NAME))
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
define INFO_MSG
|
|
|
|
* $(GRN)Your mailserver is listening on:$(RST) $(BLD)$(PUBLIC_IP):$(LISTEN_PORT)$(RST)
|
|
|
|
* $(YLW)Make sure that IP and TCP port are available from the internet!$(RST)
|
|
|
|
$(GRN)Your enode address is:$(RST)
|
|
|
|
$(shell $(GIT_ROOT)/_assets/scripts/get_enode.sh 2>/dev/null)
|
|
|
|
endef
|
|
|
|
export INFO_MSG
|
|
|
|
|
|
|
|
all: checks build config service enable restart info
|
|
|
|
|
|
|
|
clean: stop disable rm-service forget
|
|
|
|
|
|
|
|
checks:
|
2019-12-20 13:09:39 +00:00
|
|
|
ifeq (, $(shell which jq))
|
|
|
|
$(error $(RED)No 'jq' in your $$PATH. please install it$(RST))
|
|
|
|
endif
|
2019-11-28 22:52:38 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
info:
|
|
|
|
@echo "$$INFO_MSG"
|
|
|
|
|
|
|
|
enode:
|
|
|
|
@$(GIT_ROOT)/_assets/scripts/get_enode.sh
|
|
|
|
|
|
|
|
status:
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) status --no-pager $(SERVICE_NAME)
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
logs:
|
2019-12-22 14:51:15 +00:00
|
|
|
journalctl $(JRNL_OPTS) statusd
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
enable:
|
|
|
|
@echo "* $(BLD)Enabling '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) enable $(SERVICE_NAME)
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
disable:
|
|
|
|
@echo "* $(BLD)Disabling '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) disable "${SERVICE_NAME}"
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
start:
|
|
|
|
@echo "* $(BLD)Starting '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) start $(SERVICE_NAME)
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
restart:
|
|
|
|
@echo "* $(BLD)Restarting '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) restart $(SERVICE_NAME)
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
stop:
|
|
|
|
@echo "* $(BLD)Stopping '$(SERVICE_NAME)' service...$(RST)"
|
2019-12-22 14:51:15 +00:00
|
|
|
systemctl $(SCTL_OPTS) stop "${SERVICE_NAME}"
|
2019-11-28 22:52:38 +00:00
|
|
|
|
|
|
|
forget:
|
|
|
|
@echo "* $(BLD)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 22:52:38 +00:00
|
|
|
|
|
|
|
$(GIT_ROOT)/build/bin/statusd:
|
|
|
|
@echo "* $(BLD)Building mailserver binary...$(RST)"
|
|
|
|
@cd "$(GIT_ROOT)" && make statusgo
|
|
|
|
|
|
|
|
build: $(GIT_ROOT)/build/bin/statusd
|
|
|
|
.PHONY: build
|
|
|
|
|
|
|
|
$(SERVICE_DIR):
|
|
|
|
@mkdir -p $(SERVICE_DIR)
|
|
|
|
|
|
|
|
service: $(SERVICE_DIR)
|
|
|
|
@echo "* $(BLD)Generating '$(SERVICE_NAME)' service...$(RST)"
|
|
|
|
@envsubst < ./service.template > $(SERVICE_PATH)
|
|
|
|
|
|
|
|
rm-service:
|
|
|
|
rm -f $(SERVICE_PATH)
|
|
|
|
|
|
|
|
config:
|
|
|
|
@echo "* $(BLD)Generating '$(SERVICE_NAME)' config...$(RST)"
|
|
|
|
@$(GIT_ROOT)/_assets/scripts/gen_config.sh
|