-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
126 lines (102 loc) · 3.59 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
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
# prefix ping deploy
#
# Goal here is not so much to execute a process
# but to document a coherent approach on various systems
# the two I care about are
# - redhat & derivatives for public servers
# - debian & derivatives for desktop development
#
# web-client <-> nginx <-> socket <-> uwsgi <-> flask-script
#
# (http) (web-service) (service(internal-service))
# if there are a number of uwsgi services they may be under the
# umbrella of an "emperor" uwsgi that marshalles "vassel" services
# !!! CHANGE ME
# the base name of the app in the filesystem
APP := prefixping
# !!! CHANGE ME
# this is the non root owner of the app
# app should not be owned by nginx or uwsgi either
OWNER := tomc
# if not root (RECOMENDED)
# then just outputs the steps decorated with `sudo`
ifneq ($(shell whoami), root)
# -n, --just-print, --dry-run, --recon
MAKEFLAGS += n
SUDO := sudo
else
# hope you know what you are doing
SUDO :=
endif
# different OS's have different conventions ...
UNAME := $(shell uname)
# Distros may be converging on systemd/systemcrtl
# but not on where the bits should live.
# Figure out distro we are on and adapt to local conventions
# WEBSRV is the owner of public facing webserver (nginx)
ifeq ($(UNAME), Linux)
DIST := $(shell grep "^ID=" /etc/os-release |cut -f2 -d '=' | tr -d '"')
ifeq ($(DIST), centos)
SERVICE := /usr/lib/systemd/system
WEBSRV := nginx
else ifeq ($(DIST), ubuntu)
SERVICE := /etc/systemd/system
WEBSRV := www-data
else ifeq ($(DIST), linuxmint)
# system dir may not exist
SERVICE := /etc/systemd/system
WEBSRV := www-data
#else ifeq ($(DIST), ???)
# SERVICE := /x/y/z
# WEBSRV := yomama
endif
endif
# expecting to be served from a user owned dirctory
# named after the app under /srv/
PWD := $(shell pwd)
NX := /etc/nginx
########################################################################
all : start
socket :
# communication between nginx and uwsgi
#### centos -- consider adding uwsgi user to nginx group for selinux
# usermod -a -G nginx uwsgi
#### make group for directory /run/$(APP) be be the webserver
$(SUDO) mkdir /run/$(APP)
$(SUDO) chown $(OWNER):$(WEBSRV) /run/$(APP)
### sticky too?
$(SUDO) chmod g+s /run/$(APP)
service: $(SERVICE)/$(APP).service
# systemd service in place
enabled: $(NX)/sites-enabled/$(APP)
# nginx configuration enabled
$(SERVICE)/$(APP).service : $(PWD)/$(APP).service
$(SUDO) unlink $(SERVICE)/$(APP).service
$(SUDO) ln -s $(PWD)/$(APP).service $(SERVICE)$(APP).service
$(NX)/sites-available : $(NX)/
$(SUDO) mkdir $(NX)/sites-available
$(SUDO) grep "include $(NX)/sites-enabled/\\*;" $(NX)/nginx.conf
$(NX)/sites-available/$(APP) : $(NX)/sites-available $(APP).nx_location
$(SUDO) unlink $(NX)/sites-available/$(APP)
$(SUDO) cp $(APP).nx_location $(NX)/sites-available/$(APP)
$(NX)/sites-enabled : $(NX)/sites-available
$(SUDO) mkdir $(NX)/sites-enabled
$(NX)/sites-enabled/$(APP) : $(NX)/sites-available/$(APP)
$(SUDO) unlink $(NX)/sites-enabled/$(APP)
$(SUDO) ln -s $(NX)/sites-available/$(APP) $(NX)/sites-enabled/$(APP)
inichk:
# check your "net user" is not commented out in the uwsgi ini filr
grep $(WEBSRV) ./$(APP).ini
start : socket service enabled inichk
$(SUDO) systemctl stop $(APP)
$(SUDO) systemctl start $(APP)
# $(SUDO) systemctl enable $(APP)
$(SUDO) nginx -t && $(SUDO) nginx -s reload
clean :
# These are ONLY to be done by hand
#$(SUDO) unlink $(NX)/sites-enabled/$(APP)
#$(SUDO) unlink $(NX)/sites-available/$(APP)
#$(SUDO) unlink $(SERVICE)/$(APP).service
#$(SUDO) unlink $(SERVICE)/$(APP).service
#$(SUDO) rm /run/$(APP)/uwsgi_nginx.socketS
#$(SUDO) systemctl stop $(APP)