-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
149 lines (133 loc) · 3.5 KB
/
makefile
File metadata and controls
149 lines (133 loc) · 3.5 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
## for Ubuntu 16.04
# apt-get install make
# setup vars
DOMAIN = arknodejs.com
COLORS:=$(shell tput colors 2> /dev/null)
ifeq ($(COLORS), 256)
C_RESET=\033[0;39;49m
C_GREEN=\033[38;5;118m
C_BLUE=\033[38;5;81m
C_RED=\033[38;5;161m
C_PURPLE=\033[38;5;135m
C_ORANGE=\033[38;5;208m
C_YELLOW=\033[38;5;227m
C_GREY=\033[38;5;245m
C_WHITE=\033[38;5;15m
else ifeq ($(COLORS), 16)
C_RESET=\033[0;39;49m
C_GREEN=\033[0;32m
C_BLUE=\033[0;34m
C_RED=\033[0;31m
C_PURPLE=\033[0;35m
C_ORANGE=\033[1;31m
C_YELLOW=\033[0;33m
C_GREY=\033[1;30m
C_WHITE=\033[1;37m
endif
all: prep service clean install service-start start
prep: prep-nginx prep-certbot prep-mongo prep-nodejs prep-pm2
NGINX := $(shell nginx 2>/dev/null)
prep-nginx:
ifndef NGINX
@echo "$(C_BLUE)nginx installing...$(C_RESET)"
@apt-get update
@apt-get install nginx
endif
@echo "$(C_GREEN)nginx installed$(C_RESET)"
@cp -b /var/www/arknodejs/config/arknodejs.com /etc/nginx/sites-available/
@ln -s /etc/nginx/sites-available/arknodejs.com /etc/nginx/sites-enabled/arknodejs.com
@echo "$(C_GREEN)nginx configured$(C_RESET)"
CERTBOT := $(shell certbot 2>/dev/null)
prep-certbot:
ifndef CERTBOT
@echo "$(C_BLUE)certbot installing...$(C_RESET)"
@apt-get install software-properties-common
@add-apt-repository ppa:certbot/certbot
@apt-get update && apt-get install certbot
endif
@echo "$(C_GREEN)certbot installed$(C_RESET)"
@certbot certonly --standalone -d $(DOMAIN)
@echo "$(C_GREEN)certbot certificate generated$(C_RESET)"
MONGO := $(shell mongod 2>/dev/null)
prep-mongo:
ifndef MONGO
@echo "$(C_BLUE)mongodb installing...$(C_RESET)"
@apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
@echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
@apt-get update && apt-get install -y mongodb-org
@echo "$(C_GREEN)mongodb installed$(C_RESET)"
endif
NODEJS := $(shell node -v)
prep-nodejs:
ifndef NODEJS
@echo "$(C_BLUE)nodejs installing...$(C_RESET)"
@curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
@apt-get install -y nodejs
endif
@echo "$(C_GREEN)nodejs installed$(C_RESET)"
PM2 := $(shell pm2 2>/dev/null)
prep-pm2:
ifndef PM2
@echo "$(C_GREEN)pm2 installing...$(C_RESET)"
@npm i -g pm2
endif
@echo "$(C_GREEN)pm2 installed$(C_RESET)"
service-start:
@service mongod start
@nginx
service-end:
@service mongod stop
@nginx -s stop
test:
@echo "<-- nginx test -->"
@systemctl status nginx
@nginx -t
@echo "<-- nginx tend -->"
clean:
@rm -rf admin/node_modules
@rm -rf back/node_modules
@rm -rf front/node_modules
@echo "node_modules clean complete"
install:
@cd back && npm i --only=production
@cd ..
@cd front && npm i --only=production
@cd ..
@echo "npm install production complete"
start: start-front start-back
start-back:
@echo "start back"
@cd back && pm2 start pm2.json --env production
start-front:
@echo "start front"
@cd front && pm2 start pm2.json --env production
@cd ..
dev: dev-back dev-front
dev-back:
@echo "start back"
@cd back && pm2 start pm2.json
@cd ..
dev-front:
@echo "start front"
@cd front && pm2 start pm2.json
@cd ..
end:
@pm2 stop back front
kill:
@pm2 kill
restart:
@pm2 restart back front
version:
@nginx -v
@echo "node" && node -v
@echo "npm" && npm -v
# tput color code:
# 0 black
# 1 red
# 2 green
# 3 yellow
# 4 blue
# 5 magenta
# 6 cyan
# 7 white
# $(tput setab 7) [set background color]