Skip to content

Commit

Permalink
Merge pull request #27 from notoraptor/cw-556-update-cluster-status
Browse files Browse the repository at this point in the history
Set up a service to update clusters status
  • Loading branch information
soline-b authored Dec 3, 2024
2 parents 3bab287 + b59af59 commit c8ddd80
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
33 changes: 33 additions & 0 deletions tasks/setup_clusters_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# We can immediately install requirements from the file {{ clockwork_install_path }}/scripts/requirements.txt
# because it is expected that this task is called after setup_scrape, which copy the source code
- name: Install scripts requirements with pip
ansible.builtin.pip:
requirements: "{{ clockwork_install_path }}/scripts/requirements.txt"
virtualenv: "{{ clockwork_venv_path }}"

- name: Setup scripts for clusters status update
ansible.builtin.template:
src: templates/clockwork-clusters-status.service.j2
dest: /etc/systemd/system/clockwork-clusters-status.service
mode: 0600

- name: Setup system timer trigger
ansible.builtin.template:
src: templates/clockwork-clusters-status.timer.j2
dest: /etc/systemd/system/clockwork-clusters-status.timer
mode: 0600

- name: Ensure config dir is present
ansible.builtin.file:
path: /etc/clockwork
mode: 0700
state: directory
owner: "{{ clockwork_user }}"

- name: Enable timers for clusters status update
ansible.builtin.systemd:
daemon-reload: yes
enabled: true
state: started
name: clockwork-clusters-status.timer
7 changes: 6 additions & 1 deletion tasks/setup_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name: "{{ clockwork_user }}"
group: "{{ clockwork_group }}"
home: "{{ clockwork_user_home }}"

- name: Checkout source code
ansible.builtin.include_role:
name: mila.clockwork
Expand Down Expand Up @@ -113,6 +113,11 @@
dest: /etc/nginx/sites-enabled/clockwork
state: link

- name: Setup clusters status check service
ansible.builtin.include_role:
name: mila.clockwork
tasks_from: setup_clusters_status

- name: Start clockwork
ansible.builtin.systemd:
daemon-reload: yes
Expand Down
13 changes: 13 additions & 0 deletions templates/clockwork-clusters-status.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Clockwork clusters status updater
After=network.target

[Service]
Type=oneshot
User={{ clockwork_user }}
Group={{ clockwork_group }}
Environment=CLOCKWORK_CONFIG=/etc/clockwork/clockwork.toml
Environment=PYTHONPATH={{ clockwork_install_path }}

WorkingDirectory={{ clockwork_install_path }}
ExecStart={{ clockwork_venv_path }}/bin/python3 {{ clockwork_install_path }}/scripts/update_clusters_status.py
11 changes: 11 additions & 0 deletions templates/clockwork-clusters-status.timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Update clusters status in clockwork.
Requires=clockwork-clusters-status.service

[Timer]
Unit=clockwork-clusters-status.service
OnCalendar=*-*-* 00:00:00
AccuracySec=2min

[Install]
WantedBy=timers.target

0 comments on commit c8ddd80

Please sign in to comment.