diff options
author | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2014-09-17 11:42:03 +0100 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2014-09-17 11:42:03 +0100 |
commit | 0f4f5d119c0deeee4806d33d688e735496a0e7ab (patch) | |
tree | e8027168300e135534d32ac7ce365a8d4a938a54 | |
parent | 0f11a6cbe1f4a70279c06ecdacaea942db36c209 (diff) | |
parent | 950017e5621bf5eac6ea13e9340194a6559b2bb1 (diff) | |
download | definitions-0f4f5d119c0deeee4806d33d688e735496a0e7ab.tar.gz |
Merge branch 'baserock/pedroalvarez/generic-mason3'
Reviewed-by: Richard Maw
Reviewed-by: Sam Thursfield
31 files changed, 417 insertions, 156 deletions
diff --git a/distbuild.configure b/distbuild.configure index 6c298967..79148106 100644 --- a/distbuild.configure +++ b/distbuild.configure @@ -22,6 +22,7 @@ # * DISTBUILD_WORKER: if 'yes', machine is set up as a worker. # * TROVE_ID: hostname and Trove prefix of the server to pull source # from and push built artifacts to. +# * TROVE_HOST: FQDN of the same server as in TROVE_ID # # The following variable is optional: # @@ -39,128 +40,93 @@ set -e +set -u -# If ARTIFACT_CACHE_SERVER isn't set, default to $TROVE_ID. -if [ "x$ARTIFACT_CACHE_SERVER" = x ] -then - ARTIFACT_CACHE_SERVER="$TROVE_HOST" +if [ -n "$DISTBUILD_GENERIC" ]; then + echo "Not configuring the distbuild node, it will be generic" + exit 0 fi -set -u - -# Create the mount point for extra disk space. -install -d -o 0 -g 0 -m 0755 "$1/srv/distbuild" - -# Configuration shared by all instances of Morph. For reasons of -# convenience, this sets the controller-initiator-address, so -# that when users invoke "morph", they don't need to manually -# specify it, or to manually add another configuration file to -# use. However, the setting may only be set for the distbuild -# initiator (which is what the user invokes), so in ALL other -# configuration files we unset it. - -cat <<EOF > "$1/etc/morph.conf" -[config] -log = /srv/distbuild/morph.log -log-max = 100M -cachedir = /srv/distbuild -tempdir = /srv/distbuild/tmp -trove-host = $TROVE_HOST -trove-id = $TROVE_ID -controller-initiator-address = $CONTROLLERHOST -tempdir-min-space = 4G -cachedir-min-space = 4G -build-ref-prefix = $TROVE_ID -artifact-cache-server = http://$ARTIFACT_CACHE_SERVER:8080/ -git-resolve-cache-server = http://$TROVE_HOST:8080/ -EOF +# Check that all the variables needed are present: -ln -s /srv/distbuild/morph.log "$1/var/log/morph.log" +error_vars=false +if [ "x$DISTBUILD_WORKER" = "x" ]; then + echo "ERROR: DISTBUILD_WORKER needs to be defined." + error_vars=true +fi -# Configuration for a distbuild controller. This configuration -# file gets used by the systemd unit that runs the controller. -# The existence of this configuration file triggers the systemd -# unit, so we only create it on nodes that are meant to act as -# the controller. +if [ "x$DISTBUILD_CONTROLLER" = "x" ]; then + echo "ERROR: DISTBUILD_CONTROLLER needs to be defined." + error_vars=true +fi -if [ "$DISTBUILD_CONTROLLER" = True ] -then - cat <<EOF > "$1/etc/morph-controller.conf" -[config] -log = /srv/distbuild/morph-controller.log -log-max = 100M -writeable-cache-server = http://$ARTIFACT_CACHE_SERVER:8081/ -worker = $WORKERS -controller-helper-address = 127.0.0.1 -EOF +if [ "x$TROVE_HOST" = "x" ]; then + echo "ERROR: TROVE_HOST needs to be defined." + error_vars=true +fi -ln -s /srv/distbuild/morph-controller.log "$1/var/log/morph-controller.log" +if [ "x$TROVE_ID" = "x" ]; then + echo "ERROR: TROVE_ID needs to be defined." + error_vars=true +fi - # Configuration for the controller's helper process. This - # gets used by the systemd unit that starts the helper. +if [ "$DISTBUILD_WORKER" = True ]; then + if ! ssh-keygen -lf "$WORKER_SSH_KEY" > /dev/null 2>&1; then + echo "ERROR: WORKER_SSH_KEY is not a vaild ssh key." + error_vars=true + fi -cat <<EOF > "$1/etc/morph-controller-helper.conf" -[config] -log = /srv/distbuild/morph-controller-helper.log -log-max = 100M -parent-port = 5656 -parent-address = 127.0.0.1 -EOF + if [ "x$CONTROLLERHOST" = "x" ]; then + echo "ERROR: CONTROLLERHOST needs to be defined." + error_vars=true + fi +fi -ln -s /srv/distbuild/morph-controller-helper.log "$1/var/log/morph-controller-helper.log" +if [ "$DISTBUILD_CONTROLLER" = True ]; then + if [ "x$WORKERS" = "x" ]; then + echo "ERROR: WORKERS needs to be defined." + error_vars=true + fi +fi +if "$error_vars"; then + exit 1 fi -# Configuration for a distbuild worker. This gets reference -# by the systemd unit that starts the worker. Again, the -# existence of morph-worker.conf triggers the systemd unit -# to starts the worker, so we only create it on systems -# that are meant to be a worker. +ROOT="$1" + +DISTBUILD_DATA="$ROOT/etc/distbuild" +mkdir -p "$DISTBUILD_DATA" + +# If it's a worker, install the worker ssh key. if [ "$DISTBUILD_WORKER" = True ] then - cat <<EOF > "$1/etc/morph-worker.conf" -[config] -log = /srv/distbuild/morph-worker.log -log-max = 100M -controller-initiator-address = -EOF - -ln -s /srv/distbuild/morph-worker.log "$1/var/log/morph-worker.log" + install -m 0644 "$WORKER_SSH_KEY" "$DISTBUILD_DATA/worker.key" +fi - # This will be used for a systemd generator which - # nfs mounts the ccache from the trove - echo "$TROVE_HOST" > "$1/etc/trove-host" - # Configuration for the controller's helper process. This - # gets used by the systemd unit that starts the helper. -cat <<EOF > "$1/etc/morph-worker-helper.conf" -[config] -log = /srv/distbuild/morph-worker-helper.log -log-max = 100M -parent-address = 127.0.0.1 -EOF +# Create the configuration file +python <<'EOF' >"$DISTBUILD_DATA/distbuild.conf" +import os, sys, yaml -ln -s /srv/distbuild/morph-worker-helper.log "$1/var/log/morph-worker-helper.log" +distbuild_configuration={ + 'TROVE_ID': os.environ['TROVE_ID'], + 'TROVE_HOST': os.environ['TROVE_HOST'], + 'DISTBUILD_WORKER': os.environ['DISTBUILD_WORKER'], + 'DISTBUILD_CONTROLLER': os.environ['DISTBUILD_CONTROLLER'], + 'WORKER_SSH_KEY': '/etc/distbuild/worker.key', +} - # Configuration for the Morph cache server daemon. We - # only run the cache server on workers. -cat <<EOF > "$1/etc/morph-cache-server.conf" -[config] -port = 8080 -artifact-dir = /srv/distbuild/artifacts -direct-mode = True -fcgi-server = False -EOF +optional_keys = ('ARTIFACT_CACHE_SERVER', 'CONTROLLERHOST', 'WORKERS', + 'TROVE_BACKUP_KEYS') -echo "Copy distbuild worker SSH key to system" -mkdir -p "$1/root/.ssh" -install -m 0600 "$WORKER_SSH_KEY" "$1/root/.ssh/id_rsa" -install -m 0644 "${WORKER_SSH_KEY}.pub" "$1/root/.ssh/id_rsa.pub" +for key in optional_keys: + if key in os.environ: + distbuild_configuration[key] = os.environ[key] -# Add trove's host key -ssh-keyscan -t dsa,ecdsa,rsa "$TROVE_HOST" >> "$1/root/.ssh/known_hosts" -fi +yaml.dump(distbuild_configuration, sys.stdout, default_flow_style=False) +EOF diff --git a/distbuild/manifest b/distbuild/manifest index eba7c9f1..35047028 100644 --- a/distbuild/manifest +++ b/distbuild/manifest @@ -4,6 +4,10 @@ 0100755 0 0 /lib/systemd/system-generators/ccache-nfs-mount-generator 0040755 0 0 /usr 0040755 0 0 /usr/lib +0040755 0 0 /usr/lib/distbuild-setup +0040755 0 0 /usr/lib/distbuild-setup/ansible +0100644 0 0 /usr/lib/distbuild-setup/ansible/hosts +0100644 0 0 /usr/lib/distbuild-setup/ansible/distbuild-setup.yml 0040755 0 0 /usr/lib/systemd 0040755 0 0 /usr/lib/systemd/system 0100755 0 0 /usr/lib/systemd/system/morph-cache-server.service @@ -11,9 +15,14 @@ 0100755 0 0 /usr/lib/systemd/system/morph-controller-helper.service 0100755 0 0 /usr/lib/systemd/system/morph-worker.service 0100755 0 0 /usr/lib/systemd/system/morph-worker-helper.service +0100755 0 0 /usr/lib/systemd/system/distbuild-setup.service 0040755 0 0 /usr/lib/systemd/system/multi-user.target.wants -0120755 0 0 /usr/lib/systemd/system/multi-user.target.wants/morph-cache-server.service -0120755 0 0 /usr/lib/systemd/system/multi-user.target.wants/morph-controller.service -0120755 0 0 /usr/lib/systemd/system/multi-user.target.wants/morph-controller-helper.service -0120755 0 0 /usr/lib/systemd/system/multi-user.target.wants/morph-worker.service -0120755 0 0 /usr/lib/systemd/system/multi-user.target.wants/morph-worker-helper.service +0120755 0 0 /usr/lib/systemd/system/multi-user.target.wants/distbuild-setup.service +0040755 0 0 /usr/share +0040755 0 0 /usr/share/distbuild-setup +0100644 0 0 /usr/share/distbuild-setup/morph.conf +0100644 0 0 /usr/share/distbuild-setup/morph-cache-server.conf +0100644 0 0 /usr/share/distbuild-setup/morph-controller.conf +0100644 0 0 /usr/share/distbuild-setup/morph-controller-helper.conf +0100644 0 0 /usr/share/distbuild-setup/morph-worker.conf +0100644 0 0 /usr/share/distbuild-setup/morph-worker-helper.conf diff --git a/distbuild/usr/lib/distbuild-setup/ansible/distbuild-setup.yml b/distbuild/usr/lib/distbuild-setup/ansible/distbuild-setup.yml new file mode 100644 index 00000000..e4f94f54 --- /dev/null +++ b/distbuild/usr/lib/distbuild-setup/ansible/distbuild-setup.yml @@ -0,0 +1,105 @@ +--- +- hosts: localhost + vars_files: + - "/etc/distbuild/distbuild.conf" + tasks: + + - set_fact: ARTIFACT_CACHE_SERVER={{ TROVE_HOST }} + when: ARTIFACT_CACHE_SERVER is not defined + + - name: Create mountpoint for extra disk space /srv/distbuild/ + file: path=/srv/distbuild state=directory owner=root group=root mode=0755 + + - name: Create the morph and morph-cache-server configuration files + template: src=/usr/share/distbuild-setup/{{ item }} dest=/etc/{{ item }} + with_items: + - morph.conf + - morph-cache-server.conf + + - name: Link the morph log file + file: src=/srv/distbuild/morph.log dest=/var/log/morph.log state=link force=yes + + - name: Create the controller configuration files + template: src=/usr/share/distbuild-setup/{{ item }} dest=/etc/{{ item }} + with_items: + - morph-controller.conf + - morph-controller-helper.conf + when: DISTBUILD_CONTROLLER + + - name: Link the controller log files + file: src=/srv/distbuild/{{ item }} dest=/var/log/{{ item }} state=link force=yes + with_items: + - morph-controller.log + - morph-controller-helper.log + when: DISTBUILD_CONTROLLER + + - name: Create the worker configuration files + template: src=/usr/share/distbuild-setup/{{ item }} dest=/etc/{{ item }} + with_items: + - morph-worker.conf + - morph-worker-helper.conf + when: DISTBUILD_WORKER + + - name: Link the controller log files + file: src=/srv/distbuild/{{ item }} dest=/var/log/{{ item }} state=link force=yes + with_items: + - morph-worker.log + - morph-worker-helper.log + when: DISTBUILD_WORKER + + - name: Create /root/.ssh directory + file: path=/root/.ssh state=directory owner=root group=root mode=0700 + + - name: Copy the worker ssh key + copy: src={{ WORKER_SSH_KEY }} dest=/root/.ssh/id_rsa owner=root group=root mode=0600 + + - name: Create ssh public key + shell: ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub creates=/root/.ssh/id_rsa.pub + + - name: Add trove's host key + shell: | + trove_key="$(ssh-keyscan -t dsa,ecdsa,rsa {{ TROVE_HOST|quote }})" + if [ -n "$trove_key" ]; then + echo "$trove_key" > /etc/ssh/ssh_known_hosts + fi + creates=/etc/ssh/ssh_known_hosts + + + - name: Enable the morph-cache-server service + service: name=morph-cache-server.service enabled=yes + register: morph_cache_server_service + - name: Restart the morph-cache-server service + service: name=morph-cache-server state=restarted + when: morph_cache_server_service|changed + + - name: Enable the morph-worker service + service: name=morph-worker.service enabled=yes + register: morph_worker_service + when: DISTBUILD_WORKER + - name: Restart the morph-worker service + service: name=morph-worker state=restarted + when: morph_worker_service|changed + + - name: Enable the morph-worker-helper service + service: name=morph-worker-helper.service enabled=yes + register: morph_worker_helper_service + when: DISTBUILD_WORKER + - name: Restart the morph-worker-helper service + service: name=morph-worker-helper state=restarted + when: morph_worker_helper_service|changed + + - name: Enable the morph-controller service + service: name=morph-controller.service enabled=yes + register: morph_controller_service + when: DISTBUILD_CONTROLLER + - name: Restart the morph-controller service + service: name=morph-controller state=restarted + when: morph_controller_service|changed + + - name: Enable the morph-controller-helper service + service: name=morph-controller-helper.service enabled=yes + register: morph_controller_helper_service + when: DISTBUILD_CONTROLLER + - name: Restart the morph-controller-helper service + service: name=morph-controller-helper state=restarted + when: morph_controller_helper_service|changed diff --git a/distbuild/usr/lib/distbuild-setup/ansible/hosts b/distbuild/usr/lib/distbuild-setup/ansible/hosts new file mode 100644 index 00000000..5b97818d --- /dev/null +++ b/distbuild/usr/lib/distbuild-setup/ansible/hosts @@ -0,0 +1 @@ +localhost ansible_connection=local diff --git a/distbuild/usr/lib/systemd/system/distbuild-setup.service b/distbuild/usr/lib/systemd/system/distbuild-setup.service new file mode 100644 index 00000000..ec5f5a2d --- /dev/null +++ b/distbuild/usr/lib/systemd/system/distbuild-setup.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run distbuild-setup Ansible scripts +Requires=network.target +After=network.target +Requires=opensshd.service +After=opensshd.service + +# If there's a shared /var subvolume, it must be mounted before this +# unit runs. +Requires=local-fs.target +After=local-fs.target + +ConditionPathExists=/etc/distbuild/distbuild.conf + +[Service] +ExecStart=/usr/bin/ansible-playbook -v -i /usr/lib/distbuild-setup/ansible/hosts /usr/lib/distbuild-setup/ansible/distbuild-setup.yml diff --git a/distbuild/usr/lib/systemd/system/morph-cache-server.service b/distbuild/usr/lib/systemd/system/morph-cache-server.service index 7ee5e167..f55f3b6d 100644 --- a/distbuild/usr/lib/systemd/system/morph-cache-server.service +++ b/distbuild/usr/lib/systemd/system/morph-cache-server.service @@ -1,3 +1,6 @@ +[Install] +WantedBy=multi-user.target + [Unit] Description=Morph cache server Requires=local-fs.target network.target diff --git a/distbuild/usr/lib/systemd/system/morph-controller-helper.service b/distbuild/usr/lib/systemd/system/morph-controller-helper.service index 9e5bd3c8..3f30cbcf 100644 --- a/distbuild/usr/lib/systemd/system/morph-controller-helper.service +++ b/distbuild/usr/lib/systemd/system/morph-controller-helper.service @@ -1,3 +1,6 @@ +[Install] +WantedBy=multi-user.target + [Unit] Description=Morph distributed build controller helper Requires=morph-controller.service diff --git a/distbuild/usr/lib/systemd/system/morph-controller.service b/distbuild/usr/lib/systemd/system/morph-controller.service index b3ba93b4..1556d232 100644 --- a/distbuild/usr/lib/systemd/system/morph-controller.service +++ b/distbuild/usr/lib/systemd/system/morph-controller.service @@ -1,3 +1,6 @@ +[Install] +WantedBy=multi-user.target + [Unit] Description=Morph distributed build controller Requires=local-fs.target network.target diff --git a/distbuild/usr/lib/systemd/system/morph-worker-helper.service b/distbuild/usr/lib/systemd/system/morph-worker-helper.service index 14c082ce..28400701 100644 --- a/distbuild/usr/lib/systemd/system/morph-worker-helper.service +++ b/distbuild/usr/lib/systemd/system/morph-worker-helper.service @@ -1,3 +1,6 @@ +[Install] +WantedBy=multi-user.target + [Unit] Description=Morph distributed build worker helper Requires=morph-worker.service diff --git a/distbuild/usr/lib/systemd/system/morph-worker.service b/distbuild/usr/lib/systemd/system/morph-worker.service index 26dcb9ad..90fea404 100644 --- a/distbuild/usr/lib/systemd/system/morph-worker.service +++ b/distbuild/usr/lib/systemd/system/morph-worker.service @@ -1,3 +1,6 @@ +[Install] +WantedBy=multi-user.target + [Unit] Description=Morph distributed build worker Requires=local-fs.target network.target diff --git a/distbuild/usr/lib/systemd/system/multi-user.target.wants/distbuild-setup.service b/distbuild/usr/lib/systemd/system/multi-user.target.wants/distbuild-setup.service new file mode 120000 index 00000000..8f06febd --- /dev/null +++ b/distbuild/usr/lib/systemd/system/multi-user.target.wants/distbuild-setup.service @@ -0,0 +1 @@ +../distbuild-setup.service
\ No newline at end of file diff --git a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-cache-server.service b/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-cache-server.service deleted file mode 120000 index e624a31d..00000000 --- a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-cache-server.service +++ /dev/null @@ -1 +0,0 @@ -../morph-cache-server.service
\ No newline at end of file diff --git a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller-helper.service b/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller-helper.service deleted file mode 120000 index 1554df76..00000000 --- a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller-helper.service +++ /dev/null @@ -1 +0,0 @@ -../morph-controller-helper.service
\ No newline at end of file diff --git a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller.service b/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller.service deleted file mode 120000 index 9d92814b..00000000 --- a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller.service +++ /dev/null @@ -1 +0,0 @@ -../morph-controller.service
\ No newline at end of file diff --git a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker-helper.service b/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker-helper.service deleted file mode 120000 index 298c582f..00000000 --- a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker-helper.service +++ /dev/null @@ -1 +0,0 @@ -../morph-worker-helper.service
\ No newline at end of file diff --git a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker.service b/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker.service deleted file mode 120000 index 3f8d58a8..00000000 --- a/distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker.service +++ /dev/null @@ -1 +0,0 @@ -../morph-worker.service
\ No newline at end of file diff --git a/distbuild/usr/share/distbuild-setup/morph-cache-server.conf b/distbuild/usr/share/distbuild-setup/morph-cache-server.conf new file mode 100644 index 00000000..b9020e7d --- /dev/null +++ b/distbuild/usr/share/distbuild-setup/morph-cache-server.conf @@ -0,0 +1,5 @@ +[config] +port = 8080 +artifact-dir = /srv/distbuild/artifacts +direct-mode = True +fcgi-server = False diff --git a/distbuild/usr/share/distbuild-setup/morph-controller-helper.conf b/distbuild/usr/share/distbuild-setup/morph-controller-helper.conf new file mode 100644 index 00000000..99d38739 --- /dev/null +++ b/distbuild/usr/share/distbuild-setup/morph-controller-helper.conf @@ -0,0 +1,5 @@ +[config] +log = /srv/distbuild/morph-controller-helper.log +log-max = 100M +parent-port = 5656 +parent-address = 127.0.0.1 diff --git a/distbuild/usr/share/distbuild-setup/morph-controller.conf b/distbuild/usr/share/distbuild-setup/morph-controller.conf new file mode 100644 index 00000000..c16c0343 --- /dev/null +++ b/distbuild/usr/share/distbuild-setup/morph-controller.conf @@ -0,0 +1,6 @@ +[config] +log = /srv/distbuild/morph-controller.log +log-max = 100M +writeable-cache-server = http://{{ ARTIFACT_CACHE_SERVER }}:8081/ +worker = {{ WORKERS }} +controller-helper-address = 127.0.0.1 diff --git a/distbuild/usr/share/distbuild-setup/morph-worker-helper.conf b/distbuild/usr/share/distbuild-setup/morph-worker-helper.conf new file mode 100644 index 00000000..29d4ef3f --- /dev/null +++ b/distbuild/usr/share/distbuild-setup/morph-worker-helper.conf @@ -0,0 +1,4 @@ +[config] +log = /srv/distbuild/morph-worker-helper.log +log-max = 100M +parent-address = 127.0.0.1 diff --git a/distbuild/usr/share/distbuild-setup/morph-worker.conf b/distbuild/usr/share/distbuild-setup/morph-worker.conf new file mode 100644 index 00000000..fb382bad --- /dev/null +++ b/distbuild/usr/share/distbuild-setup/morph-worker.conf @@ -0,0 +1,4 @@ +[config] +log = /srv/distbuild/morph-worker.log +log-max = 100M +controller-initiator-address = diff --git a/distbuild/usr/share/distbuild-setup/morph.conf b/distbuild/usr/share/distbuild-setup/morph.conf new file mode 100644 index 00000000..29de684c --- /dev/null +++ b/distbuild/usr/share/distbuild-setup/morph.conf @@ -0,0 +1,13 @@ +[config] +log = /srv/distbuild/morph.log +log-max = 100M +cachedir = /srv/distbuild +tempdir = /srv/distbuild/tmp +trove-host = {{ TROVE_HOST }} +trove-id = {{ TROVE_ID }} +controller-initiator-address = {{ CONTROLLERHOST }} +tempdir-min-space = 4G +cachedir-min-space = 4G +build-ref-prefix = {{ TROVE_ID }} +artifact-cache-server = http://{{ ARTIFACT_CACHE_SERVER }}:8080/ +git-resolve-cache-server = http://{{ TROVE_HOST }}:8080/ diff --git a/mason.configure b/mason.configure index 90d49709..4341d8c0 100644 --- a/mason.configure +++ b/mason.configure @@ -32,70 +32,96 @@ set -e ROOT="$1" -if [ "$ARTIFACT_CACHE_SERVER" = "" \ - -o "$MASON_CLUSTER_MORPHOLOGY" = "" \ - -o "$MASON_DEFINITIONS_REF" = "" \ - -o "$MASON_DISTBUILD_ARCH" = "" \ - -o "$MASON_TEST_HOST" = "" ]; then - echo Not configuring as Mason, some options not defined - exit 0 -fi - ########################################################################## -# Functions +# Copy Mason files into root filesystem ########################################################################## -shellescape() { - echo "'$(echo "$1" | sed -e "s/'/'\\''/g")'" -} +mkdir -p "$ROOT"/usr/lib/mason +cp mason/mason.sh "$ROOT"/usr/lib/mason/mason.sh +cp mason/mason-report.sh "$ROOT"/usr/lib/mason/mason-report.sh + +cp mason/mason.timer "$ROOT"/etc/systemd/system/mason.timer + +cp mason/mason.service "$ROOT"/etc/systemd/system/mason.service ########################################################################## -# Generate config variable shell snippet +# Set up httpd web server ########################################################################## -MASON_CONFIG="$ROOT"/root/mason.conf - -echo "Creating $MASON_CONFIG" -cat >>"$MASON_CONFIG" <<EOF -#################### START OF DEPLOY TIME CONFIGURATION ####################### +cp mason/httpd.service "$ROOT"/etc/systemd/system/httpd.service -ARTIFACT_CACHE_SERVER=$(shellescape "$ARTIFACT_CACHE_SERVER") -UPSTREAM_TROVE_ADDRESS=$(shellescape "$TROVE_HOST") -DEFINITIONS_REF=$(shellescape "$MASON_DEFINITIONS_REF") -DISTBUILD_ARCH=$(shellescape "$MASON_DISTBUILD_ARCH") -DISTBUILD_CONTROLLER_ADDRESS=$(shellescape "$CONTROLLERHOST") -TROVE_ID=$(shellescape "$TROVE_ID") -BUILD_CLUSTER_MORPHOLOGY=$(shellescape "$MASON_CLUSTER_MORPHOLOGY") -TEST_VM_HOST_SSH_URL=$(shellescape "$MASON_TEST_HOST") +mkdir -p "$ROOT"/srv/mason -##################### END OF DEPLOY TIME CONFIGURATION ######################## +cat >>"$ROOT"/etc/httpd.conf <<EOF +.log:text/plain EOF +mkdir -p "$ROOT"/var/mason ########################################################################## -# Copy Mason files into root filesystem +# Copy files needed for Ansible configuration ########################################################################## -cp mason/mason.sh "$ROOT"/root/mason.sh -cp mason/mason-report.sh "$ROOT"/root/mason-report.sh +mkdir -p "$ROOT/usr/share/mason-setup" +mkdir -p "$ROOT/usr/lib/mason-setup" -cp mason/mason.timer "$ROOT"/etc/systemd/system/mason.timer -ln -s ../mason.timer "$ROOT"/etc/systemd/system/multi-user.target.wants/mason.timer +cp mason/share/* "$ROOT/usr/share/mason-setup" +cp -r mason/ansible "$ROOT/usr/lib/mason-setup/" +cp mason/mason-setup.service "$ROOT"/etc/systemd/system/mason-setup.service + +ln -s ../mason-setup.service "$ROOT"/etc/systemd/system/multi-user.target.wants/mason-setup.service -cp mason/mason.service "$ROOT"/etc/systemd/system/mason.service -ln -s ../mason.service "$ROOT"/etc/systemd/system/multi-user.target.wants/mason.service ########################################################################## -# Set up httpd web server +# Check variables ########################################################################## -cp mason/httpd.service "$ROOT"/etc/systemd/system/httpd.service -ln -s ../httpd.service "$ROOT"/etc/systemd/system/multi-user.target.wants/httpd.service +if [ -n "$MASON_GENERIC" ]; then + echo Not configuring Mason, it will be generic + exit 0 +fi -mkdir -p "$ROOT"/srv/mason +if [ "$ARTIFACT_CACHE_SERVER" = "" \ + -o "$MASON_CLUSTER_MORPHOLOGY" = "" \ + -o "$MASON_DEFINITIONS_REF" = "" \ + -o "$MASON_DISTBUILD_ARCH" = "" \ + -o "$MASON_TEST_HOST" = "" ]; then + echo Not configuring as Mason, some options not defined + exit 1 +fi -cat >>"$ROOT"/etc/httpd.conf <<EOF -.log:text/plain +########################################################################## +# Generate config variable shell snippet +########################################################################## + +MASON_DATA="$ROOT/etc/mason" +mkdir -p "$MASON_DATA" + +python <<'EOF' >"$MASON_DATA/mason.conf" +import os, sys, yaml + +trove_configuration={ + 'ARTIFACT_CACHE_SERVIER': os.environ['ARTIFACT_CACHE_SERVER'], + 'MASON_CLUSTER_MORPHOLOGY': os.environ['MASON_CLUSTER_MORPHOLOGY'], + 'MASON_DEFINITIONS_REF': os.environ['MASON_DEFINITIONS_REF'], + 'MASON_DISTBUILD_ARCH': os.environ['MASON_DISTBUILD_ARCH'], + 'MASON_TEST_HOST': os.environ['MASON_TEST_HOST'], + 'TROVE_ADMIN_NAME': os.environ['TROVE_ADMIN_NAME'], + 'TROVE_ID': os.environ['TROVE_ID'], + 'TROVE_HOST': os.environ['TROVE_HOST'], + 'CONTROLLERHOST': os.environ['CONTROLLERHOST'], +} + +yaml.dump(trove_configuration, sys.stdout, default_flow_style=False) EOF + + +########################################################################## +# Enable services +########################################################################## + +ln -s ../mason.timer "$ROOT"/etc/systemd/system/multi-user.target.wants/mason.timer +ln -s ../mason.service "$ROOT"/etc/systemd/system/multi-user.target.wants/mason.service +ln -s ../httpd.service "$ROOT"/etc/systemd/system/multi-user.target.wants/httpd.service diff --git a/mason/ansible/hosts b/mason/ansible/hosts new file mode 100644 index 00000000..5b97818d --- /dev/null +++ b/mason/ansible/hosts @@ -0,0 +1 @@ +localhost ansible_connection=local diff --git a/mason/ansible/mason-setup.yml b/mason/ansible/mason-setup.yml new file mode 100644 index 00000000..70c77871 --- /dev/null +++ b/mason/ansible/mason-setup.yml @@ -0,0 +1,56 @@ +--- +- hosts: localhost + vars_files: + - "/etc/mason/mason.conf" + tasks: + + + - fail: msg='TROVE_ID is mandatory' + when: TROVE_ID is not defined + + - fail: msg='TROVE_HOST is mandatory' + when: TROVE_HOST is not defined + + - fail: msg='ARTIFACT_CACHE_SERVER is mandatory' + when: ARTIFACT_CACHE_SERVER is not defined + + - fail: msg='MASON_CLUSTER_MORPHOLOGY is mandatory' + when: MASON_CLUSTER_MORPHOLOGY is not defined + + - fail: msg='MASON_DEFINITIONS_REF is mandatory' + when: MASON_DEFINITIONS_REF is not defined + + - fail: msg='MASON_DISTBUILD_ARCH is mandatory' + when: MASON_DISTBUILD_ARCH is not defined + + - fail: msg='MASON_TEST_HOST is mandatory' + when: MASON_TEST_HOST is not defined + + - fail: msg='CONTROLLERHOST is mandatory' + when: CONTROLLERHOST is not defined + + - name: Create the Mason configuration file + template: src=/usr/share/mason-setup/{{ item }} dest=/etc/{{ item }} + with_items: + - mason.conf + + - name: Enable the mason service + service: name=mason.service enabled=yes + register: mason_service + - name: Restart the mason service + service: name=mason.service state=restarted + when: mason_service|changed + + - name: Enable the mason timer + service: name=mason.timer enabled=yes + register: mason_timer + - name: Restart the mason timer + service: name=mason.timer state=restarted + when: mason_timer|changed + + - name: Enable the httpd service + service: name=httpd.service enabled=yes + register: httpd_service + - name: Restart the httpd service + service: name=httpd state=restarted + when: httpd_service|changed diff --git a/mason/mason-report.sh b/mason/mason-report.sh index 23182cc9..9c20b65b 100755 --- a/mason/mason-report.sh +++ b/mason/mason-report.sh @@ -2,9 +2,9 @@ set -x -. /root/mason.conf +. /etc/mason.conf -REPORT_PATH=/root/report.html +REPORT_PATH=/var/mason/report.html SERVER_PATH=/srv/mason sed_escape() { @@ -210,7 +210,7 @@ update_report_time "$START_TIME" cp "$REPORT_PATH" "$SERVER_PATH/index.html" logfile="$(mktemp)" -/root/mason.sh 2>&1 | tee "$logfile" +/usr/lib/mason/mason.sh 2>&1 | tee "$logfile" case "${PIPESTATUS[0]}" in 0) RESULT=pass diff --git a/mason/mason-setup.service b/mason/mason-setup.service new file mode 100644 index 00000000..60403bde --- /dev/null +++ b/mason/mason-setup.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run mason-setup Ansible scripts +Requires=network.target +After=network.target +Requires=opensshd.service +After=opensshd.service + +# If there's a shared /var subvolume, it must be mounted before this +# unit runs. +Requires=local-fs.target +After=local-fs.target + +ConditionPathExists=/etc/mason/mason.conf + +[Service] +ExecStart=/usr/bin/ansible-playbook -v -i /usr/lib/mason-setup/ansible/hosts /usr/lib/mason-setup/ansible/mason-setup.yml diff --git a/mason/mason.service b/mason/mason.service index 16b5dc3f..ab2338c5 100644 --- a/mason/mason.service +++ b/mason/mason.service @@ -3,7 +3,7 @@ Description=Mason: Continuous Delivery Service [Service] User=root -ExecStart=/root/mason-report.sh +ExecStart=/usr/lib/mason/mason-report.sh [Install] WantedBy=multi-user.target diff --git a/mason/mason.sh b/mason/mason.sh index 13ea21db..32aab032 100755 --- a/mason/mason.sh +++ b/mason/mason.sh @@ -4,7 +4,7 @@ set -e set -x # Load our deployment config -. /root/mason.conf +. /etc/mason.conf if [ ! -e ws ]; then morph init ws diff --git a/mason/share/mason.conf b/mason/share/mason.conf new file mode 100644 index 00000000..b323896d --- /dev/null +++ b/mason/share/mason.conf @@ -0,0 +1,12 @@ +# This file is generarated by the mason-setup systemd unit. +# If you want to change the configuration, change the configuration +# in /etc/mason/mason.conf and restart the service. + +ARTIFACT_CACHE_SERVER={{ ARTIFACT_CACHE_SERVER|quote }} +UPSTREAM_TROVE_ADDRESS={{ TROVE_HOST|quote }} +DEFINITIONS_REF={{ MASON_DEFINITIONS_REF|quote }} +DISTBUILD_ARCH={{ MASON_DISTBUILD_ARCH|quote }} +DISTBUILD_CONTROLLER_ADDRESS={{ CONTROLLERHOST|quote }} +TROVE_ID={{ TROVE_ID|quote }} +BUILD_CLUSTER_MORPHOLOGY={{ MASON_CLUSTER_MORPHOLOGY|quote }} +TEST_VM_HOST_SSH_URL={{ MASON_TEST_HOST|quote }} diff --git a/systems/distbuild-system-x86_64.morph b/systems/distbuild-system-x86_64.morph index cd461d30..b248d9db 100644 --- a/systems/distbuild-system-x86_64.morph +++ b/systems/distbuild-system-x86_64.morph @@ -17,6 +17,10 @@ strata: morph: strata/nfs.morph - name: distbuild morph: strata/distbuild.morph +- name: ansible + morph: strata/ansible.morph +- name: cloudinit-support + morph: strata/cloudinit-support.morph configuration-extensions: - set-hostname - add-config-files @@ -26,3 +30,4 @@ configuration-extensions: - distbuild - fstab - mason +- cloud-init |