From 0f50bd8af1e69a52ef6b93a0380fb9d67828c553 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 27 Aug 2014 16:49:40 +0000 Subject: Add Ansible and Cloud-init to the distbuild system Ansible is needed to use it as a configuration manager. Cloud-init is to make possible the deployment of disbuild nodes into OpenStack --- systems/distbuild-system-x86_64.morph | 5 +++++ 1 file changed, 5 insertions(+) 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 -- cgit v1.2.1 From fdae161d301c1d3e89e4bdafdf34a7e09ff0d663 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 28 Aug 2014 16:21:56 +0000 Subject: Configure distbuild with Ansible --- distbuild/manifest | 19 +++- .../distbuild-setup/ansible/distbuild-setup.yml | 105 +++++++++++++++++++++ distbuild/usr/lib/distbuild-setup/ansible/hosts | 1 + .../usr/lib/systemd/system/distbuild-setup.service | 16 ++++ .../lib/systemd/system/morph-cache-server.service | 3 + .../systemd/system/morph-controller-helper.service | 3 + .../lib/systemd/system/morph-controller.service | 3 + .../lib/systemd/system/morph-worker-helper.service | 3 + .../usr/lib/systemd/system/morph-worker.service | 3 + .../distbuild-setup.service | 1 + .../morph-cache-server.service | 1 - .../morph-controller-helper.service | 1 - .../morph-controller.service | 1 - .../morph-worker-helper.service | 1 - .../multi-user.target.wants/morph-worker.service | 1 - .../share/distbuild-setup/morph-cache-server.conf | 5 + .../distbuild-setup/morph-controller-helper.conf | 5 + .../share/distbuild-setup/morph-controller.conf | 6 ++ .../share/distbuild-setup/morph-worker-helper.conf | 4 + .../usr/share/distbuild-setup/morph-worker.conf | 4 + distbuild/usr/share/distbuild-setup/morph.conf | 13 +++ 21 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 distbuild/usr/lib/distbuild-setup/ansible/distbuild-setup.yml create mode 100644 distbuild/usr/lib/distbuild-setup/ansible/hosts create mode 100644 distbuild/usr/lib/systemd/system/distbuild-setup.service create mode 120000 distbuild/usr/lib/systemd/system/multi-user.target.wants/distbuild-setup.service delete mode 120000 distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-cache-server.service delete mode 120000 distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller-helper.service delete mode 120000 distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-controller.service delete mode 120000 distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker-helper.service delete mode 120000 distbuild/usr/lib/systemd/system/multi-user.target.wants/morph-worker.service create mode 100644 distbuild/usr/share/distbuild-setup/morph-cache-server.conf create mode 100644 distbuild/usr/share/distbuild-setup/morph-controller-helper.conf create mode 100644 distbuild/usr/share/distbuild-setup/morph-controller.conf create mode 100644 distbuild/usr/share/distbuild-setup/morph-worker-helper.conf create mode 100644 distbuild/usr/share/distbuild-setup/morph-worker.conf create mode 100644 distbuild/usr/share/distbuild-setup/morph.conf 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/ -- cgit v1.2.1 From e21c1c598b6ce29cae1ca186ac3224ab17e08c3c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 29 Aug 2014 12:14:26 +0000 Subject: Use the new distbuild.configure --- distbuild.configure | 163 ++++++++++++++++++++-------------------------------- 1 file changed, 62 insertions(+), 101 deletions(-) diff --git a/distbuild.configure b/distbuild.configure index 6c298967..f0de7a15 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,88 @@ set -e - -# If ARTIFACT_CACHE_SERVER isn't set, default to $TROVE_ID. -if [ "x$ARTIFACT_CACHE_SERVER" = x ] -then - ARTIFACT_CACHE_SERVER="$TROVE_HOST" -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 < "$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 < "$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 < "$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 < "$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 < "$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 < "$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 -- cgit v1.2.1 From a4a7a099c4e81ed3605521cb72ca8541471f0c67 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 11 Sep 2014 16:03:22 +0100 Subject: Allow the the deploment of generic distbuild nodes --- distbuild.configure | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/distbuild.configure b/distbuild.configure index f0de7a15..79148106 100644 --- a/distbuild.configure +++ b/distbuild.configure @@ -42,6 +42,11 @@ set -e set -u +if [ -n "$DISTBUILD_GENERIC" ]; then + echo "Not configuring the distbuild node, it will be generic" + exit 0 +fi + # Check that all the variables needed are present: -- cgit v1.2.1 From 04abe5fab7e2cc3a874f6d70ef92051096517e5f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Sep 2014 18:31:19 +0000 Subject: Allow the deployment of generic Mason instances --- mason.configure | 56 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/mason.configure b/mason.configure index 90d49709..9ad6f2c7 100644 --- a/mason.configure +++ b/mason.configure @@ -32,13 +32,47 @@ set -e ROOT="$1" + +########################################################################## +# Copy Mason files into root filesystem +########################################################################## + +cp mason/mason.sh "$ROOT"/root/mason.sh +cp mason/mason-report.sh "$ROOT"/root/mason-report.sh + +cp mason/mason.timer "$ROOT"/etc/systemd/system/mason.timer + +cp mason/mason.service "$ROOT"/etc/systemd/system/mason.service + +########################################################################## +# Set up httpd web server +########################################################################## + +cp mason/httpd.service "$ROOT"/etc/systemd/system/httpd.service + +mkdir -p "$ROOT"/srv/mason + +cat >>"$ROOT"/etc/httpd.conf <>"$ROOT"/etc/httpd.conf < Date: Mon, 1 Sep 2014 18:40:41 +0000 Subject: Move Mason out from /root - Move the configuration file to /etc/mason.conf - Move the scripts to /usr/lib/mason/ - Mason will store the report in /var/mason/report.html --- mason.configure | 9 ++++++--- mason/mason-report.sh | 6 +++--- mason/mason.service | 2 +- mason/mason.sh | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mason.configure b/mason.configure index 9ad6f2c7..23ee23c2 100644 --- a/mason.configure +++ b/mason.configure @@ -37,8 +37,10 @@ ROOT="$1" # Copy Mason files into root filesystem ########################################################################## -cp mason/mason.sh "$ROOT"/root/mason.sh -cp mason/mason-report.sh "$ROOT"/root/mason-report.sh + +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 @@ -56,6 +58,7 @@ cat >>"$ROOT"/etc/httpd.conf <>"$MASON_CONFIG" <&1 | tee "$logfile" +/usr/lib/mason/mason.sh 2>&1 | tee "$logfile" case "${PIPESTATUS[0]}" in 0) RESULT=pass 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 -- cgit v1.2.1 From 48a4b547d84f9469d0bda0ba9a151a8cd195ff5c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 9 Sep 2014 15:37:07 +0000 Subject: Configure Mason with Ansible --- mason/ansible/hosts | 1 + mason/ansible/mason-setup.yml | 56 +++++++++++++++++++++++++++++++++++++++++++ mason/mason-setup.service | 16 +++++++++++++ mason/share/mason.conf | 12 ++++++++++ 4 files changed, 85 insertions(+) create mode 100644 mason/ansible/hosts create mode 100644 mason/ansible/mason-setup.yml create mode 100644 mason/mason-setup.service create mode 100644 mason/share/mason.conf 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-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/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 }} -- cgit v1.2.1 From 950017e5621bf5eac6ea13e9340194a6559b2bb1 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 9 Sep 2014 15:37:40 +0000 Subject: Update mason.configure to use Ansible --- mason.configure | 57 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/mason.configure b/mason.configure index 23ee23c2..4341d8c0 100644 --- a/mason.configure +++ b/mason.configure @@ -60,6 +60,20 @@ EOF mkdir -p "$ROOT"/var/mason +########################################################################## +# Copy files needed for Ansible configuration +########################################################################## + +mkdir -p "$ROOT/usr/share/mason-setup" +mkdir -p "$ROOT/usr/lib/mason-setup" + +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 + + ########################################################################## # Check variables ########################################################################## @@ -78,36 +92,29 @@ if [ "$ARTIFACT_CACHE_SERVER" = "" \ exit 1 fi - -########################################################################## -# Functions -########################################################################## - -shellescape() { - echo "'$(echo "$1" | sed -e "s/'/'\\''/g")'" -} - - ########################################################################## # Generate config variable shell snippet ########################################################################## -MASON_CONFIG="$ROOT"/etc/mason.conf - -echo "Creating $MASON_CONFIG" -cat >>"$MASON_CONFIG" <"$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'], +} -##################### END OF DEPLOY TIME CONFIGURATION ######################## +yaml.dump(trove_configuration, sys.stdout, default_flow_style=False) EOF -- cgit v1.2.1