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