← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/dev-services into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/dev-services into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/dev-services/+merge/94184

Use daemontools to manage running development services. This lets us do:

make start
make status
make stop
make shutdown

The distinction between `stop` and `shutdown` is because supervise (from daemontools) is left running under `make stop`, but it stopped under `make shutdown`. The latter is a prerequisite of `distclean`.

A `run` target also exists, which starts the services then tails the log files.

-- 
https://code.launchpad.net/~allenap/maas/dev-services/+merge/94184
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/dev-services into lp:maas.
=== modified file '.bzrignore'
--- .bzrignore	2012-02-20 11:02:48 +0000
+++ .bzrignore	2012-02-22 14:41:31 +0000
@@ -16,6 +16,7 @@
 ./parts
 ./pserv.log
 ./pserv.pid
+./services/*/supervise
 ./TAGS
 ./tags
 ./twistd.log

=== modified file 'HACKING.txt'
--- HACKING.txt	2012-02-16 15:45:16 +0000
+++ HACKING.txt	2012-02-22 14:41:31 +0000
@@ -23,13 +23,16 @@
 
 Prerequisites
 =============
+
 You will need to manually install Postgres 9.1 (postgresql-9.1 and
-libpq-dev), RabbitMQ (rabbitmq-server), python-dev and make::
-
-    $ sudo apt-get install postgresql-9.1 libpq-dev rabbitmq-server python-dev make
-
-Also, you might want to install Bazaar (bzr) to grab the source code directly
-from Launchpad::
+libpq-dev), RabbitMQ (rabbitmq-server), python-dev, daemontools, and
+make::
+
+    $ sudo apt-get install postgresql-9.1 libpq-dev rabbitmq-server
+    $ sudo apt-get install python-dev daemontools make
+
+Also, you might want to install Bazaar (``bzr``) to grab the source
+code directly from Launchpad::
 
     $ sudo apt-get install bzr
 
@@ -49,6 +52,7 @@
 
     $ bzr branch lp:maas maas && cd maas
 
+
 Development MaaS server setup
 =============================
 

=== modified file 'Makefile'
--- Makefile	2012-02-15 17:13:37 +0000
+++ Makefile	2012-02-22 14:41:31 +0000
@@ -67,7 +67,7 @@
 	find . -type f -name '*.py[co]' -print0 | xargs -r0 $(RM)
 	find . -type f -name '*~' -print0 | xargs -r0 $(RM)
 
-distclean: clean pserv-stop
+distclean: clean shutdown
 	utilities/maasdb delete-cluster ./db/
 	$(RM) -r eggs develop-eggs
 	$(RM) -r bin build dist logs parts
@@ -75,17 +75,8 @@
 	$(RM) -r *.egg *.egg-info src/*.egg-info
 	$(RM) docs/api.rst
 	$(RM) -r docs/_build/
-
-pserv.pid: bin/twistd.pserv
-	bin/twistd.pserv --pidfile=$@ maas-pserv --config-file=etc/pserv.yaml
-
-pserv-start: pserv.pid
-
-pserv-stop:
-	{ test -e pserv.pid && cat pserv.pid; } | xargs --no-run-if-empty kill
-
-run: bin/maas dev-db pserv.pid
-	bin/maas runserver 8000 --settings=maas.demo
+	$(RM) -r services/*/supervise
+	$(RM) twisted/plugins/dropin.cache
 
 harness: bin/maas dev-db
 	bin/maas shell
@@ -93,7 +84,51 @@
 syncdb: bin/maas dev-db
 	bin/maas syncdb --noinput
 
+services := api pserv
+services := $(patsubst %,services/%/,$(services))
+
+# The services/*/@something targets below are phony - they will never
+# correspond to an existing file - but we want them to be evaluated
+# for building.
+
+start: $(addsuffix @start,$(services))
+
+stop: $(addsuffix @stop,$(services))
+
+run: start
+	@tail --follow=name logs/*/current
+
+status: $(addsuffix @status,$(services))
+
+shutdown: $(addsuffix @shutdown,$(services))
+
+services/%/@supervise: services/%/@deps logs/%
+	@if ! svok $(@D); then \
+	    logdir=$(PWD)/logs/$* supervise $(@D) & fi
+	@while ! svok $(@D); do sleep 0.1; done
+
+services/%/@start: services/%/@supervise
+	@svc -u $(@D)
+
+services/%/@stop: services/%/@supervise
+	@svc -d $(@D)
+
+services/%/@shutdown:
+	@if svok $(@D); then svc -dx $(@D); fi
+	@while svok $(@D); do sleep 0.1; done
+
+services/%/@status:
+	@svstat $(@D)
+
+services/pserv/@deps: bin/twistd.pserv
+
+services/api/@deps: bin/maas dev-db
+
+.PRECIOUS: logs/%
+logs/%:
+	@mkdir -p $@
+
 .PHONY: \
     build check clean dev-db distclean doc \
-    harness lint pserv-start pserv-stop run \
-    syncdb test sampledata
+    harness lint run shutdown syncdb test \
+    sampledata start stop status

=== added directory 'services'
=== added directory 'services/api'
=== added file 'services/api/down'
=== added file 'services/api/run'
--- services/api/run	1970-01-01 00:00:00 +0000
+++ services/api/run	2012-02-22 14:41:31 +0000
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+# Exit immediately if a command exits with a non-zero status.
+set -o errexit
+# Treat unset variables as an error when substituting.
+set -o nounset
+
+# Move to the project root.
+cd ../..
+
+# Start logging, if requested.
+[ -z "${logdir:-}" ] || exec &> >(
+    exec multilog s1048576 n10 "${logdir}")
+
+# Exec the MaaS API and Web UI Server.
+script="$(readlink -f bin/maas)"
+exec "${script}" runserver 8000 --settings=maas.demo --noreload

=== added directory 'services/pserv'
=== added file 'services/pserv/down'
=== added file 'services/pserv/run'
--- services/pserv/run	1970-01-01 00:00:00 +0000
+++ services/pserv/run	2012-02-22 14:41:31 +0000
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+# Exit immediately if a command exits with a non-zero status.
+set -o errexit
+# Treat unset variables as an error when substituting.
+set -o nounset
+
+# Move to the project root.
+cd ../..
+
+# Start logging, if requested.
+[ -z "${logdir:-}" ] || exec &> >(
+    exec multilog s1048576 n10 "${logdir}")
+
+# Exec the Provisioning Server.
+script="$(readlink -f bin/twistd.pserv)"
+config="$(readlink -f etc/pserv.yaml)"
+exec "${script}" --nodaemon maas-pserv --config-file "${config}"