Skip to content

Commit

Permalink
fix: systemd service now references script
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Jan 1, 2025
1 parent 3a0e29d commit 429682b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 65 deletions.
10 changes: 9 additions & 1 deletion ansible/roles/pretix/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,18 @@
# basically means nginx gives a 503 page, defined here.
- name: "prepare maintenance mode files"
block:
- name: "place maintenance page" # TODO: move this to the pretix repo
- name: "place maintenance page"
ansible.builtin.template:
owner: "pretix"
group: "pretix"
src: "pretix_maintenance.html.j2"
dest: "/var/www/pretix/pretix-maintenance.html"

- name: "install maintenance script to be run my systemd services"
ansible.builtin.template:
src: "pretix-maintenance.sh.j2"
dest: "/usr/local/bin/pretix-maintenance.sh"

- name: "prepare maintenance mode services"
ansible.builtin.template:
src: "systemd/{{ item }}.j2"
Expand All @@ -154,6 +159,9 @@
notify:
- "systemctl daemon-reload"

- name: "ensure daemon is reloaded"
ansible.builtin.meta: "flush_handlers"

- name: "ensure maintenance mode timer is enabled"
ansible.builtin.service:
name: "pretix-maintenance.timer"
Expand Down
4 changes: 2 additions & 2 deletions ansible/roles/pretix/templates/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ server {
# Security header file not included because frames

location / {
if (-f /var/www/pretix/MAINTENANCE_MODE) { # TODO abstract to variable
error_page 503 /503.html;
if (-f /var/www/pretix/MAINTENANCE_MODE) {
error_page 503 /var/www/pretix/pretix-maintenance.html;
return 503;
}

Expand Down
24 changes: 24 additions & 0 deletions ansible/roles/pretix/templates/pretix-maintenance.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

##
## This script checks the current UTC time, and based on that time
## enables or disables the pretix maintenance mode.
##
## USAGE: pretix_maintenance.sh
##

# Unofficial Bash strict mode
set -eEfuo pipefail
IFS=$'\n\t'

MARKER_PATH='/var/www/pretix/MAINTENANCE_MODE'

HOUR=$(date -u +%H) # UTC hour
DAY=$(date -u +%a) # UTC day

if [[ "$DAY" == "su" && $HOUR -gt 21 || "$DAY" == "mo" && $HOUR -lt 5 ]]
then touch "$MARKER_PATH"; # Enable maintenance mode
else rm "$MARKER_PATH"; # Disable maintenance mode
fi

systemctl reload nginx # Apply changes
59 changes: 0 additions & 59 deletions ansible/roles/pretix/templates/pretix.conf.j2

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ OnFailure=failure-notificator@%n.service
[Service]
# If, compared to UTC, we are between sunday 22:00 and monday 05:00, we want
# maintenance mode and otherwise not.
ExecStart=if [[ `date -u +%a` == "su" && `date -u +%H` > 21 || `date -u +%a` ==
"mo" && `date -u +%H` < 5` ]] then touch '/var/www/pretix/MAINTENANCE_MODE';
else rm '/var/www/pretix/MAINTENANCE_MODE'; fi && systemctl reload nginx
ExecStart=/usr/local/bin/pretix-maintenance.sh

0 comments on commit 429682b

Please sign in to comment.