From 132b9651f2facbc8d18f41eec7b7e4810f8ac5ff Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Thu, 14 Nov 2024 18:23:31 +0100 Subject: [PATCH] speedtest: enable automatic updates of docker images --- roles/speedtest/handlers/main.yml | 9 ++++++--- roles/speedtest/tasks/main.yml | 12 ++++++++++++ .../speedtest/templates/speedtest-reload.service.j2 | 7 +++++++ roles/speedtest/templates/speedtest-reload.timer.j2 | 10 ++++++++++ roles/speedtest/templates/speedtest.service.j2 | 6 ++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 roles/speedtest/templates/speedtest-reload.service.j2 create mode 100644 roles/speedtest/templates/speedtest-reload.timer.j2 diff --git a/roles/speedtest/handlers/main.yml b/roles/speedtest/handlers/main.yml index 5f110d7..4ca4039 100644 --- a/roles/speedtest/handlers/main.yml +++ b/roles/speedtest/handlers/main.yml @@ -3,11 +3,14 @@ - name: Reload systemd systemd: daemon_reload=yes -- name: Restart nginx - service: name=nginx state=restarted - - name: Restart speedtest service: name=speedtest state=restarted +- name: Restart speedtest-reload + service: name=speedtest-reload state=restarted + +- name: Restart nginx + service: name=nginx state=restarted + - name: Run acertmgr command: /usr/bin/acertmgr diff --git a/roles/speedtest/tasks/main.yml b/roles/speedtest/tasks/main.yml index 891a4ae..9204da8 100644 --- a/roles/speedtest/tasks/main.yml +++ b/roles/speedtest/tasks/main.yml @@ -43,5 +43,17 @@ - Reload systemd - Restart speedtest +- name: Systemd unit for speedtest-reload + template: src=speedtest-reload.{{ item }}.j2 dest=/etc/systemd/system/speedtest-reload.{{ item }} + with_items: + - "service" + - "timer" + notify: + - Reload systemd + - Restart speedtest-reload + - name: Start the speedtest service service: name=speedtest state=started enabled=yes + +- name: Enable auto update timer + service: name=speedtest-reload.timer state=started enabled=yes diff --git a/roles/speedtest/templates/speedtest-reload.service.j2 b/roles/speedtest/templates/speedtest-reload.service.j2 new file mode 100644 index 0000000..1459802 --- /dev/null +++ b/roles/speedtest/templates/speedtest-reload.service.j2 @@ -0,0 +1,7 @@ +[Unit] +Description=Refresh speedtest images + +[Service] +Type=oneshot + +ExecStart=/bin/systemctl reload-or-restart speedtest.service diff --git a/roles/speedtest/templates/speedtest-reload.timer.j2 b/roles/speedtest/templates/speedtest-reload.timer.j2 new file mode 100644 index 0000000..ed8ddfe --- /dev/null +++ b/roles/speedtest/templates/speedtest-reload.timer.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Refresh speedtest images +Requires=speedtest.service +After=speedtest.service + +[Timer] +OnCalendar=*:0/15 + +[Install] +WantedBy=timers.target diff --git a/roles/speedtest/templates/speedtest.service.j2 b/roles/speedtest/templates/speedtest.service.j2 index 3898c10..9d8c6d9 100644 --- a/roles/speedtest/templates/speedtest.service.j2 +++ b/roles/speedtest/templates/speedtest.service.j2 @@ -17,6 +17,8 @@ WorkingDirectory=/opt/speedtest # Make sure no old containers are running ExecStartPre=/usr/bin/docker-compose down -v +# Update images +ExecStartPre=-/usr/bin/docker-compose pull --quiet # Compose up ExecStart=/usr/bin/docker-compose up @@ -24,5 +26,9 @@ ExecStart=/usr/bin/docker-compose up # Compose down, remove containers and volumes ExecStop=/usr/bin/docker-compose down -v +# Refresh on reload +ExecReload=-/usr/bin/docker-compose pull --quiet +ExecReload=/usr/bin/docker-compose up -d + [Install] WantedBy=multi-user.target