github.com/status-im/status-go@v1.1.0/_assets/systemd/mailserver/Makefile (about)

     1  export GIT_ROOT := $(shell git rev-parse --show-toplevel)
     2  # Useful for showing enode address
     3  PUBLIC_IP ?= $(shell curl -s https://ipecho.net/plain)
     4  
     5  RED := $(shell tput -Txterm setaf 1)
     6  GRN := $(shell tput -Txterm setaf 2)
     7  YLW := $(shell tput -Txterm setaf 3)
     8  RST := $(shell tput -Txterm sgr0)
     9  BLD := $(shell tput bold)
    10  
    11  # by default we run the service as user
    12  SCTL_OPTS   := --user
    13  JRNL_OPTS   := --user-unit
    14  SERVICE_DIR := $(HOME)/.config/systemd/user/
    15  # with sudo it will run as a system service
    16  ifeq ($(USER), root)
    17  SCTL_OPTS   := 
    18  JRNL_OPTS   := --unit
    19  SERVICE_DIR := /etc/systemd/system/
    20  endif
    21  
    22  # Settings
    23  export SERVICE_NAME ?= status-go-mailserver
    24  export SERVICE_DIR  ?= $(HOME)/.config/systemd/user/
    25  export SERVICE_PATH ?= $(SERVICE_DIR)/$(SERVICE_NAME).service
    26  export DATA_PATH    ?= /var/tmp/$(SERVICE_NAME)
    27  export LOG_LEVEL    ?= INFO
    28  export LISTEN_PORT  ?= 30303
    29  export METRICS_PORT ?= 9090
    30  export RPC_PORT     ?= 8545
    31  
    32  # Info
    33  STATUS = $(shell systemctl $(SCTL_OPTS) is-active $(SERVICE_NAME))
    34  
    35  define INFO_MSG
    36   * $(GRN)Your mailserver is listening on:$(RST) $(BLD)$(PUBLIC_IP):$(LISTEN_PORT)$(RST)
    37   * $(GRN)Your enode address is:$(RST)
    38  $(shell $(GIT_ROOT)/_assets/scripts/get_enode.sh 2>/dev/null)
    39  
    40  $(YLW)Make sure that IP and TCP port are available from the internet!$(RST)
    41  
    42  endef
    43  export INFO_MSG
    44  
    45  all: checks build config service enable restart info enode-qr
    46  
    47  clean: stop disable rm-service forget 
    48  
    49  checks:
    50  ifeq (, $(shell which jq))
    51  	$(error $(RED)No 'jq' in your $$PATH. please install it$(RST))
    52  endif
    53  # this setup wont work without an os with systemd
    54  ifeq (, $(shell which systemctl))
    55  	$(error $(RED)Your system does not have systemd$(RST))
    56  endif
    57  # if the service is already up just show some info
    58  ifeq (active, $(STATUS))
    59  	$(info $(INFO_MSG))
    60  	$(error $(YLW)Service already started$(RST))
    61  endif
    62  
    63  info:
    64  	@echo "$$INFO_MSG"
    65  
    66  enode:
    67  	@$(GIT_ROOT)/_assets/scripts/get_enode.sh
    68  
    69  enode-qr:
    70  	@$(GIT_ROOT)/_assets/scripts/get_enode.sh --qr
    71  
    72  status:
    73  	systemctl $(SCTL_OPTS) status --no-pager $(SERVICE_NAME)
    74  
    75  logs:
    76  	journalctl $(JRNL_OPTS) statusd
    77  
    78  enable:
    79  	@echo " * $(GRN)Enabling '$(SERVICE_NAME)' service...$(RST)"
    80  	systemctl $(SCTL_OPTS) enable $(SERVICE_NAME)
    81  
    82  disable:
    83  	@echo " * $(YLW)Disabling '$(SERVICE_NAME)' service...$(RST)"
    84  	systemctl $(SCTL_OPTS) disable "${SERVICE_NAME}"
    85  
    86  start:
    87  	@echo " * $(GRN)Starting '$(SERVICE_NAME)' service...$(RST)"
    88  	systemctl $(SCTL_OPTS) start $(SERVICE_NAME)
    89  
    90  restart:
    91  	@echo " * $(GRN)Restarting '$(SERVICE_NAME)' service...$(RST)"
    92  	systemctl $(SCTL_OPTS) restart $(SERVICE_NAME)
    93  
    94  stop:
    95  	@echo " * $(YLW)Stopping '$(SERVICE_NAME)' service...$(RST)"
    96  	systemctl $(SCTL_OPTS) stop "${SERVICE_NAME}"
    97  
    98  forget:
    99  	@echo " * $(YLW)Stopping '$(SERVICE_NAME)' service...$(RST)"
   100  	systemctl $(SCTL_OPTS) daemon-reload
   101  	systemctl $(SCTL_OPTS) reset-failed
   102  
   103  $(GIT_ROOT)/build/bin/statusd:
   104  	@echo " * $(GRN)Building mailserver binary...$(RST)"
   105  	@cd "$(GIT_ROOT)" && make statusgo
   106  
   107  build: $(GIT_ROOT)/build/bin/statusd
   108  .PHONY: build
   109  
   110  $(SERVICE_DIR):
   111  	@mkdir -p $(SERVICE_DIR)
   112  
   113  service: $(SERVICE_DIR)
   114  	@echo " * $(GRN)Generating '$(SERVICE_NAME)' service...$(RST)"
   115  	@envsubst < ./service.template > $(SERVICE_PATH)
   116  
   117  rm-service:
   118  	rm -f $(SERVICE_PATH)
   119  
   120  config:
   121  	@echo " * $(GRN)Generating '$(SERVICE_NAME)' config...$(RST)"
   122  	@$(GIT_ROOT)/_assets/scripts/gen_config.sh