From 2f4ae3fd7089141790fe83ef4d4052b588f76115 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Thu, 7 May 2020 13:11:43 +0200 Subject: [PATCH] make buildbot-worker setup work --- defaults/main.yaml | 3 ++ files/systemd/buildbot-worker@.service | 25 +++++++++++++++ handlers/main.yaml | 9 ++++++ tasks/main.yaml | 44 ++++++++++++++++++++++++-- vars/main.yaml | 3 ++ 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 files/systemd/buildbot-worker@.service diff --git a/defaults/main.yaml b/defaults/main.yaml index ed97d53..a0026a1 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1 +1,4 @@ --- +buildbot_worker_name: buildbot-worker +buildbot_worker_admin_info: "" +buildbot_worker_host_info: "" diff --git a/files/systemd/buildbot-worker@.service b/files/systemd/buildbot-worker@.service new file mode 100644 index 0000000..d460d87 --- /dev/null +++ b/files/systemd/buildbot-worker@.service @@ -0,0 +1,25 @@ +# This template file assumes the buildbot worker lives in a subdirectory od +# /var/lib/buildbot +# Usage: +# cd /var/lib/buildbot +# buildbot-worker create-worker [directory] [master hostname] [name] [password] +# systemctl enable --now buildbot-worker@[directory].service +[Unit] +Description=Buildbot Worker +After=network.target + +[Service] +User=%i +Group=%i +WorkingDirectory=/var/lib/buildbot-worker/%i +ExecStart=/usr/local/bin/buildbot-worker start --nodaemon worker +# if using EC2 Latent worker, you want to uncomment following line, and comment out the Restart line +# ExecStopPost=shutdown now +Restart=always +ProtectSystem=full +ProtectHome=yes +PrivateDevices=yes +PrivateTmp=yes + +[Install] +WantedBy=multi-user.target diff --git a/handlers/main.yaml b/handlers/main.yaml index ed97d53..ec04ea9 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -1 +1,10 @@ --- + +- name: systemd daemon reload + systemd: + daemon_reload: yes + +- name: restart buildbot-worker service + systemd: + state: restarted + name: buildbot-worker@{{buildbot_worker_name}}.service diff --git a/tasks/main.yaml b/tasks/main.yaml index 67b9f6d..5a2fcb6 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -6,6 +6,11 @@ - buildbot-worker executable: pip3 +- name: buildbot-worker var directory + file: + path: /var/lib/buildbot-worker + state: directory + - name: buildbot-worker group group: name: "{{ buildbot_worker_group }}" @@ -14,8 +19,9 @@ user: name: "{{ buildbot_worker_user }}" group: "{{ buildbot_worker_group }}" - home: "{{ ez_directory }}" + home: "{{ buildbot_worker_home_directory }}" shell: /usr/bin/fish + password_lock: true - name: buildbot-worker home directory file: @@ -23,4 +29,38 @@ owner: "{{ buildbot_worker_user }}" group: "{{ buildbot_worker_group }}" state: directory - mode: u=rwx,g=rwx,o= + mode: u=rwx,g=rx,o= + +# source of unit file from https://github.com/buildbot/buildbot-contrib/blob/master/worker/contrib/systemd/buildbot-worker%40.service +- name: buildbot-worker systemd service unit + copy: + src: systemd/buildbot-worker@.service + dest: /etc/systemd/system/buildbot-worker@.service + notify: + - systemd daemon reload + - restart buildbot-worker service + +- name: initiate buildbot-worker + command: buildbot-worker create-worker worker localhost:9989 "{{buildbot_worker_name}}" "{{buildbot_worker_password}}" + become: true + become_user: "{{buildbot_worker_user}}" + args: + chdir: "{{buildbot_worker_home_directory}}" + creates: /var/lib/buildbot-worker/{{buildbot_worker_name}}/worker + notify: restart buildbot-worker service + +- name: buildbot-worker host info + copy: + content: "{{buildbot_worker_host_info}}" + dest: /var/lib/buildbot-worker/{{buildbot_worker_name}}/worker/info/host + owner: "{{ buildbot_worker_user }}" + group: "{{ buildbot_worker_group }}" + notify: restart buildbot-worker service + +- name: buildbot-worker admin info + copy: + content: "{{buildbot_worker_admin_info}}" + dest: /var/lib/buildbot-worker/{{buildbot_worker_name}}/worker/info/admin + owner: "{{ buildbot_worker_user }}" + group: "{{ buildbot_worker_group }}" + notify: restart buildbot-worker service diff --git a/vars/main.yaml b/vars/main.yaml index ed97d53..1cdc2b5 100644 --- a/vars/main.yaml +++ b/vars/main.yaml @@ -1 +1,4 @@ --- +buildbot_worker_user: "{{ buildbot_worker_name }}" +buildbot_worker_group: "{{ buildbot_worker_name }}" +buildbot_worker_home_directory: "/var/lib/buildbot-worker/{{ buildbot_worker_name }}"