~mpontillo/maas/dns-template-changes-1.7

544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
1
python := python2.7
1062.1.1 by Gavin Panella
Really really tell buildout to stay off the network.
2
3
# Network activity can be suppressed by setting offline=true (or any
4
# non-empty string) at the command-line.
5
ifeq ($(offline),)
634.3.13 by Gavin Panella
Don't automatically open the post-mortem debugger when buildout goes wrong.
6
buildout := bin/buildout
634.3.5 by Gavin Panella
Add --never-download to virtualenv's flags when using build-offline.
7
virtualenv := virtualenv
1062.1.1 by Gavin Panella
Really really tell buildout to stay off the network.
8
else
9
buildout := bin/buildout buildout:offline=true
10
virtualenv := virtualenv --never-download
11
endif
544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
12
1170.1.2 by Gavin Panella
Set bogus proxies to try and thwart more network activity.
13
# If offline has been selected, attempt to further block HTTP/HTTPS
14
# activity by setting bogus proxies in the environment.
15
ifneq ($(offline),)
16
export http_proxy := broken
17
export https_proxy := broken
18
endif
19
544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
20
# Python enum modules.
21
py_enums := $(wildcard src/*/enum.py)
22
# JavaScript enum module (not modules).
23
js_enums := src/maasserver/static/js/enums.js
9.1.5 by Gavin Panella
Clean up Makefile dependencies.
24
576.2.2 by Gavin Panella
New global dbrun.
25
# Prefix commands with this when they need access to the database.
26
# Remember to add a dependency on bin/database from the targets in
27
# which those commands appear.
28
dbrun := bin/database --preserve run --
29
510.4.63 by Gavin Panella
Default the database to maas, and use bin/database run when mutating the database.
30
# For things that care, postgresfixture for example, we always want to
31
# use the "maas" databases.
32
export PGDATABASE := maas
33
3074.1.15 by Gavin Panella
Always export MAAS_ROOT=./run in Makefile.
34
# For anything we start, we want to hint as to its root directory.
35
export MAAS_ROOT := $(CURDIR)/run
36
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
37
build: \
38
    bin/buildout \
510.4.20 by Gavin Panella
New buildout target for bin/database.
39
    bin/database \
1923.1.2 by Julian Edwards
maascli is now maas
40
    bin/maas-region-admin bin/test.maas \
41
    bin/maas bin/test.maascli \
987.1.1 by Gavin Panella
Introduce commandant into a new maascli package.
42
    bin/test.maastesting \
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
43
    bin/twistd.pserv bin/test.pserv \
2133.2.1 by Gavin Panella
Split configuration tests into a new script, test.config.
44
    bin/test.config \
1742.3.3 by Julian Edwards
turn into a buildout script, and remove unncessary options
45
    bin/maas-probe-dhcp \
532.1.1 by Jeroen Vermeulen
Script to generate JavaScript enums from our Python enums.
46
    bin/py bin/ipy \
544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
47
    $(js_enums)
47.4.12 by Gavin Panella
Don't always build docs.
48
49
all: build doc
9.1.5 by Gavin Panella
Clean up Makefile dependencies.
50
794.1.2 by Gavin Panella
Move install_dependencies towards to the top of the Makefile, make it display the full command line when executing, rename it install-dependencies to match a couple of existing targets, and mark it as phony.
51
# Install all packages required for MAAS development & operation on
52
# the system. This may prompt for a password.
53
install-dependencies:
952.1.1 by Robie Basak
Only install hard dependencies in make install-dependencies
54
	sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
1562.1.6 by Gavin Panella
Keep track of doc package dependencies separately.
55
	    --no-install-recommends install $(shell sort -u \
2157.1.1 by Raphael Badin
Add build dependencies.
56
	        $(addprefix required-packages/,base build dev doc))
2153.2.1 by Gavin Panella
Purge forbidden dependencies, like python-librabbitmq which causes segfaults.
57
	sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
58
	    purge $(shell sort -u required-packages/forbidden)
794.1.2 by Gavin Panella
Move install_dependencies towards to the top of the Makefile, make it display the full command line when executing, rename it install-dependencies to match a couple of existing targets, and mark it as phony.
59
1817.1.1 by Gavin Panella
virtualenv in Trusty does not install the pip executable when using --system-site-packages.
60
bin/python:
674.1.1 by Gavin Panella
Should use CURDIR instead of PWD in Makefile; the latter is inherited from the shell, the former is provided by make.
61
	$(virtualenv) --python=$(python) --system-site-packages $(CURDIR)
634.3.3 by Gavin Panella
Use virtualenv/pip to bootstrap zc.buildout, instead of buildout's buggy bootstrap.py.
62
1817.1.1 by Gavin Panella
virtualenv in Trusty does not install the pip executable when using --system-site-packages.
63
bin/buildout: bin/python bootstrap/zc.buildout-1.5.2.tar.gz
64
	bin/python -m pip --quiet install --ignore-installed \
634.3.12 by Gavin Panella
Force install zc.buildout from source, so that we can be sure to get the bin/buildout script.
65
	    --no-dependencies bootstrap/zc.buildout-1.5.2.tar.gz
634.3.6 by Gavin Panella
Remove the README.txt that buildout rudely installs.
66
	$(RM) -f README.txt  # zc.buildout installs an annoying README.txt.
44.1.1 by Gavin Panella
Ensure that bin/buildout is newer than its dependencies once it's been built.
67
	@touch --no-create $@  # Ensure it's newer than its dependencies.
9.1.5 by Gavin Panella
Clean up Makefile dependencies.
68
510.4.20 by Gavin Panella
New buildout target for bin/database.
69
bin/database: bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
70
	$(buildout) install database
510.4.20 by Gavin Panella
New buildout target for bin/database.
71
	@touch --no-create $@
72
3074.1.7 by Gavin Panella
Remove the region worker.
73
bin/maas-region-admin: \
1745.2.11 by Gavin Panella
Create separate scripts for celery on the region and on the cluster, so they can import different modules.
74
    bin/buildout buildout.cfg versions.cfg setup.py $(js_enums)
634.3.1 by Gavin Panella
Try to get everything able to build offline.
75
	$(buildout) install maas
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
76
	@touch --no-create $@
77
544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
78
bin/test.maas: bin/buildout buildout.cfg versions.cfg setup.py $(js_enums)
634.3.1 by Gavin Panella
Try to get everything able to build offline.
79
	$(buildout) install maas-test
125.1.1 by Gavin Panella
Switch away from djangorecipe, splitting the mass stuff into stuff required for production and stuff for testing.
80
	@touch --no-create $@
81
1923.1.2 by Julian Edwards
maascli is now maas
82
bin/maas: bin/buildout buildout.cfg versions.cfg setup.py
987.1.1 by Gavin Panella
Introduce commandant into a new maascli package.
83
	$(buildout) install maascli
84
	@touch --no-create $@
85
86
bin/test.maascli: bin/buildout buildout.cfg versions.cfg setup.py
87
	$(buildout) install maascli-test
88
	@touch --no-create $@
89
573.3.1 by Raphael Badin
Separate tests from maastesting.
90
bin/test.maastesting: bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
91
	$(buildout) install maastesting-test
573.3.1 by Raphael Badin
Separate tests from maastesting.
92
	@touch --no-create $@
93
3064.2.6 by Gavin Panella
Remove all Celery configuration and scripts for the cluster.
94
bin/maas-provision bin/twistd.pserv: \
1079.2.5 by Gavin Panella
Use bin/celeryd from the dev services script.
95
    bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
96
	$(buildout) install pserv
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
97
	@touch --no-create $@
38.2.1 by Gavin Panella
Break up the big bin/buildout rule.
98
620.1.3 by Gavin Panella
write_dhcp_config.TestScriptExecutable is not very useful; it just checks that buildout has run.
99
bin/test.pserv: bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
100
	$(buildout) install pserv-test
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
101
	@touch --no-create $@
51.1.1 by Gavin Panella
Get tests working for provisioningserver.
102
2133.2.1 by Gavin Panella
Split configuration tests into a new script, test.config.
103
bin/test.config: bin/buildout buildout.cfg versions.cfg setup.py
104
	$(buildout) install config-test
105
	@touch --no-create $@
106
1742.3.3 by Julian Edwards
turn into a buildout script, and remove unncessary options
107
bin/maas-probe-dhcp: bin/buildout buildout.cfg versions.cfg setup.py
108
	$(buildout) install maas-probe-dhcp
109
	@touch --no-create $@
110
509.1.1 by Raphael Badin
Add versions.cfg to makefile.
111
bin/flake8: bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
112
	$(buildout) install flake8
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
113
	@touch --no-create $@
38.2.1 by Gavin Panella
Break up the big bin/buildout rule.
114
1293.5.5 by Gavin Panella
Build the maas-cli.8 man page.
115
bin/sphinx bin/sphinx-build: bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
116
	$(buildout) install sphinx
66.1.1 by Gavin Panella
Create bin/twistd.pserv, and always update targets when calling buildout (because it doesn't).
117
	@touch --no-create $@
1 by Raphael Badin
Initial commit.
118
509.1.1 by Raphael Badin
Add versions.cfg to makefile.
119
bin/py bin/ipy: bin/buildout buildout.cfg versions.cfg setup.py
634.3.1 by Gavin Panella
Try to get everything able to build offline.
120
	$(buildout) install repl
125.1.2 by Gavin Panella
Touch both py and ipy when rebuilding them.
121
	@touch --no-create bin/py bin/ipy
47.4.5 by Gavin Panella
Rename test.pserv to pserv-test, add a repl part, and update versions.
122
664.2.1 by Jeroen Vermeulen
Make make target 'test' depend on 'build'. Can't keep duplicating every build artifact that the tests need in both targets.
123
test: build
758.2.2 by Raphael Badin
Fixes as per review.
124
	echo $(wildcard bin/test.*) | xargs -n1 env
1 by Raphael Badin
Initial commit.
125
2177.3.1 by jtv at canonical
Move Python linting into its own target, lint-py.
126
lint: lint-py lint-js lint-doc
1 by Raphael Badin
Initial commit.
127
511.1.3 by Gavin Panella
Use the available function for pocketlint too.
128
pocketlint = $(call available,pocketlint,python-pocket-lint)
129
2009.1.1 by jtv at canonical
Add lint check for trailing spaces in documentation. Make JS and documentation lint checks part of “make lint”.
130
# XXX jtv 2014-02-25: Clean up this lint, then make it part of "make lint".
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
131
lint-css: sources = src/maasserver/static/css
511.1.3 by Gavin Panella
Use the available function for pocketlint too.
132
lint-css:
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
133
	@find $(sources) -type f \
511.1.3 by Gavin Panella
Use the available function for pocketlint too.
134
	    -print0 | xargs -r0 $(pocketlint) --max-length=120
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
135
3147.1.1 by jtv at canonical
Run lint checks in parallel. Not ideal, but the checks were getting really annoyingly slow.
136
# Python lint checks are time-intensive, so we run them in parallel.  It may
137
# make things matters worse if the files need to be read from disk, though, so
138
# this may need more tuning.
139
# The -n50 -P4 setting roughly doubled speed on a high-end system with SSD and
140
# all the files in cache.
2177.3.1 by jtv at canonical
Move Python linting into its own target, lint-py.
141
lint-py: sources = $(wildcard *.py contrib/*.py) src templates twisted utilities etc
142
lint-py: bin/flake8
3147.1.1 by jtv at canonical
Run lint checks in parallel. Not ideal, but the checks were getting really annoyingly slow.
143
	@find $(sources) -name '*.py' ! -path '*/migrations/*' -print0 \
144
	    | xargs -r0 -n50 -P4 bin/flake8 --ignore=E123 --config=/dev/null
2777.1.1 by jtv at canonical
Fix a use of maaslog.exception; should be maaslog.error. Also, check for this as lint.
145
	@./utilities/check-maaslog-exception
2177.3.1 by jtv at canonical
Move Python linting into its own target, lint-py.
146
2009.1.1 by jtv at canonical
Add lint check for trailing spaces in documentation. Make JS and documentation lint checks part of “make lint”.
147
lint-doc:
148
	@./utilities/doc-lint
149
3147.1.1 by jtv at canonical
Run lint checks in parallel. Not ideal, but the checks were getting really annoyingly slow.
150
# JavaScript lint is checked in parallel for speed.  The -n20 -P4 seetting
151
# worked well on a multicore SSD machine with the files cached, roughly
152
# doubling the speed, but it may need tuning for slower systems or cold caches.
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
153
lint-js: sources = src/maasserver/static/js
511.1.3 by Gavin Panella
Use the available function for pocketlint too.
154
lint-js:
3147.1.1 by jtv at canonical
Run lint checks in parallel. Not ideal, but the checks were getting really annoyingly slow.
155
	@find $(sources) -type f -print0 '(' -name '*.html' -o -name '*.js' ')' | xargs -r0 -n20 -P4 $(pocketlint)
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
156
2177.3.2 by jtv at canonical
Add ‘format’ target to Makefile.
157
# Apply automated formatting to all Python files.
158
format: sources = $(wildcard *.py contrib/*.py) src templates twisted utilities etc
159
format:
160
	@find $(sources) -name '*.py' -print0 | xargs -r0 ./utilities/format-imports
161
620.1.2 by Gavin Panella
Fix dependencies in Makefile.
162
check: clean test
1 by Raphael Badin
Initial commit.
163
2744.1.6 by jtv at canonical
Extract API handlers: Nodes. (Actually, straighten out the last remaining bits and bobs and then rename api.py to nodes.py.)
164
docs/api.rst: bin/maas-region-admin src/maasserver/api/doc_handler.py syncdb
1923.1.3 by Julian Edwards
Makefile fixes
165
	bin/maas-region-admin generate_api_doc > $@
21.1.3 by Raphael Badin
Generate static doc.
166
1923.1.3 by Julian Edwards
Makefile fixes
167
sampledata: bin/maas-region-admin bin/database syncdb
168
	$(dbrun) bin/maas-region-admin loaddata src/maasserver/fixtures/dev_fixture.yaml
32.5.2 by Raphael Badin
Add doc.
169
32.1.2 by Gavin Panella
Use distribute with buildout; fix dependencies around docs; fix clean and distclean.
170
doc: bin/sphinx docs/api.rst
31.1.1 by Raphael Badin
Use sphinx's recipe.
171
	bin/sphinx
21.1.3 by Raphael Badin
Generate static doc.
172
2285.1.1 by Raphael Badin
The 'doc-with-versions' target should depend on docs/api.rst so that the API doc is part of the generated documentation.
173
doc-with-versions: bin/sphinx docs/api.rst
2231.1.2 by Raphael Badin
Add versions Javascript file.
174
	cd docs/_build; make SPHINXOPTS="-A add_version_switcher=true" html
175
1293.5.5 by Gavin Panella
Build the maas-cli.8 man page.
176
man: $(patsubst docs/man/%.rst,man/%,$(wildcard docs/man/*.rst))
177
178
man/%: docs/man/%.rst | bin/sphinx-build
179
	bin/sphinx-build -b man docs man $^
180
544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
181
enums: $(js_enums)
182
686.1.1 by Gavin Panella
Fix Makefile.
183
$(js_enums): bin/py src/maasserver/utils/jsenums.py $(py_enums)
184
	 bin/py -m src/maasserver/utils/jsenums $(py_enums) > $@
532.1.1 by Jeroen Vermeulen
Script to generate JavaScript enums from our Python enums.
185
532.1.3 by Jeroen Vermeulen
Generate JS versions of our python enums.
186
clean:
965.1.11 by Gavin Panella
Clean the acceptance tree when clean is called.
187
	$(MAKE) -C acceptance $@
532.1.3 by Jeroen Vermeulen
Generate JS versions of our python enums.
188
	find . -type f -name '*.py[co]' -print0 | xargs -r0 $(RM)
189
	find . -type f -name '*~' -print0 | xargs -r0 $(RM)
1352.2.5 by Gavin Panella
Clean more stuff in clean, rather than distclean.
190
	find . -type f -name dropin.cache -print0 | xargs -r0 $(RM)
532.1.3 by Jeroen Vermeulen
Generate JS versions of our python enums.
191
	$(RM) -r media/demo/* media/development
544.1.1 by Gavin Panella
Simplify convert-enums by working with files only, not trying to do module jiggery pokery.
192
	$(RM) $(js_enums)
546.2.6 by Raphael Badin
Ignore *.log.
193
	$(RM) *.log
674.1.5 by Gavin Panella
Use autosummary for enums too.
194
	$(RM) docs/api.rst
1352.2.5 by Gavin Panella
Clean more stuff in clean, rather than distclean.
195
	$(RM) -r docs/_autosummary docs/_build
1366.1.1 by Gavin Panella
Store generated man pages in the tree.
196
	$(RM) -r man/.doctrees
532.1.3 by Jeroen Vermeulen
Generate JS versions of our python enums.
197
499.1.1 by Gavin Panella
Rename stop to pause, shutdown to stop.
198
distclean: clean stop
634.3.3 by Gavin Panella
Use virtualenv/pip to bootstrap zc.buildout, instead of buildout's buggy bootstrap.py.
199
	$(RM) -r bin include lib local
9.1.2 by Gavin Panella
Update clean and distclean targets.
200
	$(RM) -r eggs develop-eggs
634.3.3 by Gavin Panella
Use virtualenv/pip to bootstrap zc.buildout, instead of buildout's buggy bootstrap.py.
201
	$(RM) -r build dist logs/* parts
9.1.2 by Gavin Panella
Update clean and distclean targets.
202
	$(RM) tags TAGS .installed.cfg
38.2.4 by Gavin Panella
Ignore ./dist and remove src/*.egg-info.
203
	$(RM) -r *.egg *.egg-info src/*.egg-info
149.6.50 by Gavin Panella
Remove the contents of run/ on distclean.
204
	$(RM) -r run/* services/*/supervise
47.4.1 by Gavin Panella
Rename the django recipe to maas.
205
1923.1.3 by Julian Edwards
Makefile fixes
206
harness: bin/maas-region-admin bin/database
207
	$(dbrun) bin/maas-region-admin shell --settings=maas.demo
47.4.1 by Gavin Panella
Rename the django recipe to maas.
208
510.4.20 by Gavin Panella
New buildout target for bin/database.
209
dbharness: bin/database
510.4.63 by Gavin Panella
Default the database to maas, and use bin/database run when mutating the database.
210
	bin/database --preserve shell
510.4.13 by Gavin Panella
New dbharness target.
211
1923.1.3 by Julian Edwards
Makefile fixes
212
syncdb: bin/maas-region-admin bin/database
213
	$(dbrun) bin/maas-region-admin syncdb --noinput
214
	$(dbrun) bin/maas-region-admin migrate maasserver --noinput
215
	$(dbrun) bin/maas-region-admin migrate metadataserver --noinput
273.1.6 by Raphael Badin
Add empy line.
216
2920.8.1 by jtv at canonical
Add schema caching. Makes tests start up faster.
217
# (Re)write the baseline schema.
218
schema/baseline.sql: bin/database
219
	$(dbrun) pg_dump -h $(PWD)/db/ -d maas --no-owner --no-privileges -f $@
220
221
# Synchronise the database, and update the baseline schema.
222
baseline-schema: syncdb schema/baseline.sql
223
149.6.30 by Gavin Panella
Reorganize Makefile.
224
define phony_targets
225
  build
226
  check
227
  clean
510.4.13 by Gavin Panella
New dbharness target.
228
  dbharness
149.6.30 by Gavin Panella
Reorganize Makefile.
229
  distclean
230
  doc
532.1.1 by Jeroen Vermeulen
Script to generate JavaScript enums from our Python enums.
231
  enums
2177.3.2 by jtv at canonical
Add ‘format’ target to Makefile.
232
  format
149.6.30 by Gavin Panella
Reorganize Makefile.
233
  harness
794.1.2 by Gavin Panella
Move install_dependencies towards to the top of the Makefile, make it display the full command line when executing, rename it install-dependencies to match a couple of existing targets, and mark it as phony.
234
  install-dependencies
149.6.30 by Gavin Panella
Reorganize Makefile.
235
  lint
236
  lint-css
2009.1.1 by jtv at canonical
Add lint check for trailing spaces in documentation. Make JS and documentation lint checks part of “make lint”.
237
  lint-doc
149.6.30 by Gavin Panella
Reorganize Makefile.
238
  lint-js
2177.3.1 by jtv at canonical
Move Python linting into its own target, lint-py.
239
  lint-py
1293.5.5 by Gavin Panella
Build the maas-cli.8 man page.
240
  man
1970.2.1 by Julian Edwards
experimental package building
241
  package
149.6.30 by Gavin Panella
Reorganize Makefile.
242
  sampledata
1970.2.4 by Julian Edwards
Really make package building work
243
  source_package
149.6.30 by Gavin Panella
Reorganize Makefile.
244
  syncdb
245
  test
246
endef
247
248
#
249
# Development services.
250
#
251
3074.1.7 by Gavin Panella
Remove the region worker.
252
service_names_region := database dns reloader web webapp
3064.2.6 by Gavin Panella
Remove all Celery configuration and scripts for the cluster.
253
service_names_cluster := pserv reloader
1044.2.1 by Gavin Panella
Get the run target to run everything.
254
service_names_all := $(service_names_region) $(service_names_cluster)
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
255
979.3.2 by Gavin Panella
Document the weird new Makefile stuff.
256
# The following template is intended to be used with `call`, and it
257
# accepts a single argument: a target name. The target name must
258
# correspond to a service action (see "Pseudo-magic targets" below).
259
# A region- and cluster-specific variant of the target will be
260
# created, in addition to the target itself. These can be used to
261
# apply the service action to the region services, the cluster
262
# services, or all services, at the same time.
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
263
define service_template
264
$(1)-region: $(patsubst %,services/%/@$(1),$(service_names_region))
265
$(1)-cluster: $(patsubst %,services/%/@$(1),$(service_names_cluster))
266
$(1): $(1)-region $(1)-cluster
267
phony_services_targets += $(1)-region $(1)-cluster $(1)
268
endef
269
979.3.2 by Gavin Panella
Document the weird new Makefile stuff.
270
# Expand out aggregate service targets using `service_template`.
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
271
$(eval $(call service_template,pause))
272
$(eval $(call service_template,restart))
273
$(eval $(call service_template,start))
274
$(eval $(call service_template,status))
275
$(eval $(call service_template,stop))
276
$(eval $(call service_template,supervise))
277
979.3.2 by Gavin Panella
Document the weird new Makefile stuff.
278
# The `run` targets do not fit into the mould of the others.
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
279
run-region:
3074.1.15 by Gavin Panella
Always export MAAS_ROOT=./run in Makefile.
280
	@services/run $(service_names_region)
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
281
run-cluster:
3074.1.15 by Gavin Panella
Always export MAAS_ROOT=./run in Makefile.
282
	@services/run $(service_names_cluster)
1044.2.1 by Gavin Panella
Get the run target to run everything.
283
run:
3074.1.15 by Gavin Panella
Always export MAAS_ROOT=./run in Makefile.
284
	@services/run $(service_names_all)
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
285
286
phony_services_targets += run-region run-cluster run
149.6.45 by Gavin Panella
Add new target, run+web, to run the web service in the foreground.
287
979.3.2 by Gavin Panella
Document the weird new Makefile stuff.
288
# This one's for the rapper, yo.
149.6.51 by Gavin Panella
Fix typo.
289
run+webapp:
3074.1.15 by Gavin Panella
Always export MAAS_ROOT=./run in Makefile.
290
	@services/run $(service_names_region) +webapp
979.3.1 by Gavin Panella
Add <action>-region and <action>-cluster targets.
291
292
phony_services_targets += run+webapp
149.6.30 by Gavin Panella
Reorganize Makefile.
293
511.1.2 by Gavin Panella
Also check for setlock.
294
# Convenient variables and functions for service control.
149.6.32 by Gavin Panella
Add +services/%/@run target.
295
511.1.2 by Gavin Panella
Also check for setlock.
296
setlock = $(call available,setlock,daemontools)
511.1.1 by Gavin Panella
Check availability of daemontools.
297
supervise = $(call available,supervise,daemontools)
298
svc = $(call available,svc,daemontools)
299
svok = $(call available,svok,daemontools)
300
svstat = $(call available,svstat,daemontools)
301
511.1.2 by Gavin Panella
Also check for setlock.
302
service_lock = $(setlock) -n /run/lock/maas.dev.$(firstword $(1))
303
304
# Pseudo-magic targets for controlling individual services.
149.6.39 by Gavin Panella
Lock when running or supervising.
305
499.1.1 by Gavin Panella
Rename stop to pause, shutdown to stop.
306
services/%/@run: services/%/@stop services/%/@deps
149.6.39 by Gavin Panella
Lock when running or supervising.
307
	@$(call service_lock, $*) services/$*/run
149.6.32 by Gavin Panella
Add +services/%/@run target.
308
149.6.5 by Gavin Panella
Reliable start/stop control for development daemons.
309
services/%/@start: services/%/@supervise
511.1.1 by Gavin Panella
Check availability of daemontools.
310
	@$(svc) -u $(@D)
149.6.5 by Gavin Panella
Reliable start/stop control for development daemons.
311
499.1.1 by Gavin Panella
Rename stop to pause, shutdown to stop.
312
services/%/@pause: services/%/@supervise
511.1.1 by Gavin Panella
Check availability of daemontools.
313
	@$(svc) -d $(@D)
149.6.5 by Gavin Panella
Reliable start/stop control for development daemons.
314
149.6.34 by Gavin Panella
More reorg.
315
services/%/@status:
511.1.1 by Gavin Panella
Check availability of daemontools.
316
	@$(svstat) $(@D)
149.6.34 by Gavin Panella
More reorg.
317
149.6.35 by Gavin Panella
Add restart target.
318
services/%/@restart: services/%/@supervise
511.1.1 by Gavin Panella
Check availability of daemontools.
319
	@$(svc) -du $(@D)
149.6.35 by Gavin Panella
Add restart target.
320
499.1.1 by Gavin Panella
Rename stop to pause, shutdown to stop.
321
services/%/@stop:
511.1.1 by Gavin Panella
Check availability of daemontools.
322
	@if $(svok) $(@D); then $(svc) -dx $(@D); fi
323
	@while $(svok) $(@D); do sleep 0.1; done
149.6.5 by Gavin Panella
Reliable start/stop control for development daemons.
324
149.6.34 by Gavin Panella
More reorg.
325
services/%/@supervise: services/%/@deps
326
	@mkdir -p logs/$*
327
	@touch $(@D)/down
511.1.1 by Gavin Panella
Check availability of daemontools.
328
	@if ! $(svok) $(@D); then \
674.1.1 by Gavin Panella
Should use CURDIR instead of PWD in Makefile; the latter is inherited from the shell, the former is provided by make.
329
	    logdir=$(CURDIR)/logs/$* \
511.1.1 by Gavin Panella
Check availability of daemontools.
330
	        $(call service_lock, $*) $(supervise) $(@D) & fi
331
	@while ! $(svok) $(@D); do sleep 0.1; done
149.6.5 by Gavin Panella
Reliable start/stop control for development daemons.
332
149.6.32 by Gavin Panella
Add +services/%/@run target.
333
# Dependencies for individual services.
334
720.2.11 by Raphael Badin
Fixes as per review.
335
services/dns/@deps: bin/py
720.2.1 by Raphael Badin
Add dns service.
336
510.4.20 by Gavin Panella
New buildout target for bin/database.
337
services/database/@deps: bin/database
510.4.5 by Gavin Panella
Start and stop the database as a service.
338
149.6.5 by Gavin Panella
Reliable start/stop control for development daemons.
339
services/pserv/@deps: bin/twistd.pserv
340
149.6.44 by Gavin Panella
The reloader doesn't depend on web and pserv.
341
services/reloader/@deps:
149.6.14 by Gavin Panella
Add the reloader service to Makefile.
342
149.6.47 by Gavin Panella
Control Apache via the service mechanism, calling it 'web'. Renamed the existing 'web' service to 'webapp'.
343
services/web/@deps:
344
1923.1.3 by Julian Edwards
Makefile fixes
345
services/webapp/@deps: bin/maas-region-admin
561.2.1 by Raphael Badin
Add celeryd to the list of available services.
346
149.6.30 by Gavin Panella
Reorganize Makefile.
347
#
1970.2.1 by Julian Edwards
experimental package building
348
# Package building
349
#
1970.2.2 by Julian Edwards
Gavin's Makefile foo put to use
350
# This ought to be as simple as using bzr builddeb --export-upstream but it
1970.2.1 by Julian Edwards
experimental package building
351
# has a bug and always considers apt-source tarballs before the specified
352
# branch.  So instead, export to a local tarball which is always found.
1970.2.4 by Julian Edwards
Really make package building work
353
# Make sure debhelper and dh-apport packages are installed before using this.
3266.1.1 by Julian Edwards
Set the right packaging branch
354
PACKAGING := $(CURDIR)/../packaging.utopic
355
PACKAGING_BRANCH := lp:~maas-maintainers/maas/packaging.utopic
1970.2.4 by Julian Edwards
Really make package building work
356
357
package_branch:
358
	@echo Downloading/refreshing packaging branch...
359
	@if [ ! -d $(PACKAGING) ]; then \
360
		bzr branch $(PACKAGING_BRANCH) $(PACKAGING); \
361
		else bzr pull -d $(PACKAGING); fi
1970.2.5 by Julian Edwards
review comments
362
363
# Make sure an orig tarball generated from the current branch is placed in the
364
# build area.
1970.2.4 by Julian Edwards
Really make package building work
365
package_export: VER = $(shell dpkg-parsechangelog -l$(PACKAGING)/debian/changelog | sed -rne 's,^Version: ([^-]+).*,\1,p')
366
package_export: TARBALL = maas_$(VER).orig.tar.gz
367
package_export: package_branch
368
	@$(RM) -f ../build-area/$(TARBALL)
369
	@mkdir -p ../build-area
370
	@bzr export --root=maas-$(VER).orig ../build-area/$(TARBALL) $(CURDIR)
1970.2.5 by Julian Edwards
review comments
371
1970.2.4 by Julian Edwards
Really make package building work
372
package: package_export
2340.2.1 by Julian Edwards
'make package' now puts the package files in ../build-area/ instead of the ../ directory.
373
	bzr bd --merge $(PACKAGING) --result-dir=../build-area -- -uc -us
374
	@echo Binary packages built, see ../build-area/ directory.
1970.2.5 by Julian Edwards
review comments
375
1970.2.4 by Julian Edwards
Really make package building work
376
source_package: package_export
2340.2.1 by Julian Edwards
'make package' now puts the package files in ../build-area/ instead of the ../ directory.
377
	bzr bd --merge $(PACKAGING) --result-dir=../build-area -- -S -uc -us
378
	@echo Source package built, see ../build-area/ directory.
1970.2.1 by Julian Edwards
experimental package building
379
380
#
149.6.30 by Gavin Panella
Reorganize Makefile.
381
# Phony stuff.
382
#
383
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
384
define phony
149.6.30 by Gavin Panella
Reorganize Makefile.
385
  $(phony_services_targets)
386
  $(phony_targets)
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
387
endef
388
149.6.30 by Gavin Panella
Reorganize Makefile.
389
phony := $(sort $(strip $(phony)))
390
473.2.5 by Gavin Panella
Add lint-js and lint-css targets to Makefile.
391
.PHONY: $(phony)
511.1.1 by Gavin Panella
Check availability of daemontools.
392
393
#
394
# Functions.
395
#
396
397
# Check if a command is found on PATH. Raise an error if not, citing
398
# the package to install. Return the command otherwise.
399
# Usage: $(call available,<command>,<package>)
400
define available
511.1.4 by Gavin Panella
Make the error message from 'available' more explicit.
401
  $(if $(shell which $(1)),$(1),$(error $(1) not found; \
402
    install it with 'sudo apt-get install $(2)'))
511.1.1 by Gavin Panella
Check availability of daemontools.
403
endef