This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
38 lines (29 loc) · 1.46 KB
/
Makefile
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
# Variable for filename for store running procees id
PID_FILE = /tmp/swiss-deals-api.pid
# We can use such syntax to get main.go and other root Go files.
GO_FILES = $(wildcard *.go)
# Need swag to be installed: https://pkg.go.dev/github.com/swaggo/swag#readme-getting-started
SWAG=${HOME}/go/bin/swag
# Start task performs "go run main.go" command and writes it's process id to PID_FILE.
start:
${SWAG} init
go run $(GO_FILES) & echo $$! > $(PID_FILE)
# You can also use go build command for start task
# start:
# go build -o /bin/swiss-deals-api . && \
# /bin/swiss-deals-api & echo $$! > $(PID_FILE)
# Stop task will kill process by ID stored in PID_FILE (and all child processes by pstree).
stop:
-kill `pstree -p \`cat $(PID)\` | tr "\n" " " |sed "s/[^0-9]/ /g" |sed "s/\s\s*/ /g"`
# Before task will only prints message. Actually, it is not necessary. You can remove it, if you want.
before:
@echo "STOPED swiss-deals-api" && printf '%*s\n' "40" '' | tr ' ' -
# Restart task will execute stop, before and start tasks in strict order and prints message.
restart: stop before start
@echo "STARTED swiss-deals-api" && printf '%*s\n' "40" '' | tr ' ' -
# Serve task will run fswatch monitor and performs restart task if any source file changed. Before serving it will execute start task.
serve: start
fswatch -or --event=Updated /home/parla-go/src | \
xargs -n1 -I {} make restart
# .PHONY is used for reserving tasks words
.PHONY: start before stop restart serve