Browse Source

Finish the buildagent playbook.

Turn sudo on, which makes all those sudo_users actually work.

Add tasks to idempotently start the agent if it's not running
master
Chris Smith 10 years ago
parent
commit
3d32969470
2 changed files with 18 additions and 0 deletions
  1. 5
    0
      playbooks/dmdirc-buildagent.yml
  2. 13
    0
      playbooks/includes/launch-app

+ 5
- 0
playbooks/dmdirc-buildagent.yml View File

@@ -2,12 +2,14 @@
2 2
 # Sets up accounts for DMDirc build agents
3 3
 
4 4
 - hosts: dmdirc-buildagents
5
+  sudo: yes
5 6
   user: root
6 7
 
7 8
   vars:
8 9
     home_dir: /home/{{ teamcity_user }}/
9 10
     agent_sh: "{{ home_dir }}/bin/agent.sh"
10 11
     conf: "{{ home_dir }}/conf/buildAgent.properties"
12
+    pid: "{{ home_dir }}/logs/buildAgent.pid"
11 13
     temp_key: /etc/ansible/data/auto/keys/teamcity-{{ ansible_hostname }}
12 14
     htaccess: /home/dmdirc/www/private/.htaccess
13 15
     header: "# {{ inventory_hostname }}"
@@ -72,3 +74,6 @@
72 74
     sudo_user: dmdirc
73 75
     lineinfile: dest={{ htaccess }} line="Allow from {{ item }}" insertafter="{{ header }}"
74 76
     with_items: ansible_all_ipv4_addresses
77
+
78
+  - include: includes/launch-app pid_file="{{ pid }}" start_command="{{ agent_sh }} start"
79
+    sudo_user: "{{ teamcity_user }}"

+ 13
- 0
playbooks/includes/launch-app View File

@@ -0,0 +1,13 @@
1
+---
2
+# Launches an app if its PID file doesn't exist or is stale
3
+
4
+- name: check if process is running
5
+  shell: ps p `cat {{ pid_file }}` executable=/bin/bash
6
+  ignore_errors: true
7
+  failed_when: false
8
+  changed_when: false
9
+  register: pid_result
10
+
11
+- name: start process
12
+  command: "{{ start_command }}"
13
+  when: pid_result|failed

Loading…
Cancel
Save