-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
62 lines (54 loc) · 1.74 KB
/
Copy pathmakefile
File metadata and controls
62 lines (54 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
APP := echos
OUTPUT_DIR := /opt/$(APP)
MAIN_PACKAGE := ./cmd/main.go
BINARY_NAME := $(APP)
SERVICE_FILE := $(APP).service
SERVICE_PATH := /etc/systemd/system/$(SERVICE_FILE)
STATIC_FILES := ./static
STATIC_FILES_PATH := /opt/$(APP)/$(INDEX_FILE)
.PHONY: all build install copy_config reload restart start status
install: copy_config build reload restart status
build:
@echo "$(APP): Building the binary..."
@sudo mkdir -p $(OUTPUT_DIR)
@sudo go build -ldflags="-s -w" -o $(OUTPUT_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
@if [ $$? -eq 0 ]; then \
echo "$(APP): Build successful. Binary located at $(OUTPUT_DIR)/$(BINARY_NAME)"; \
else \
echo "$(APP): Build failed. Check errors above."; \
exit 1; \
fi
copy_config:
@echo "$(APP): Copying files..."
@sudo cp $(SERVICE_FILE) $(SERVICE_PATH)
@if [ $$? -eq 0 ]; then \
echo "$(APP): $(SERVICE_FILE) successfully copied to $(SERVICE_PATH)"; \
else \
echo "$(APP): Failed to copy $(SERVICE_FILE). Check permissions or path."; \
exit 1; \
fi
@sudo cp -r $(STATIC_FILES) $(STATIC_FILES_PATH)
@if [ $$? -eq 0 ]; then \
echo "$(APP): $(STATIC_FILES) successfully copied to $(STATIC_FILES_PATH)"; \
else \
echo "$(APP): Failed to copy $(STATIC_FILES). Check permissions or path."; \
exit 1; \
fi
reload:
@echo "$(APP): Reloading systemd daemon..."
@sudo systemctl daemon-reload
@echo "$(APP): Daemon reloaded"
restart:
@if systemctl is-active --quiet $(SERVICE_FILE); then \
echo "$(APP): Restarting the service..."; \
sudo systemctl restart $(SERVICE_FILE); \
echo "$(APP): Service restarted"; \
else \
$(MAKE) start; \
fi
start:
@echo "$(APP): Starting the service..."
@sudo systemctl start $(SERVICE_FILE)
@echo "$(APP): Service started"
status:
@sudo systemctl status $(SERVICE_FILE)