diff --git a/ansible/roles/cronjobs/tasks/main.yml b/ansible/roles/cronjobs/tasks/main.yml index d11ccd1..61205d1 100644 --- a/ansible/roles/cronjobs/tasks/main.yml +++ b/ansible/roles/cronjobs/tasks/main.yml @@ -35,10 +35,13 @@ hour: 0 minute: 10 +# Also reloads gunicorn if CSS updated, to update the cache-busting strings - name: Add cronjob for generating site-icons CSS file cron: name: generate_site_icons_css - job: "{{ bin_dir }}/python -c \"from scripts.generate_site_icons_css import generate_css; generate_css()\"" + job: > + {{ bin_dir }}/python -c "from scripts.generate_site_icons_css import generate_css; generated = generate_css(); exit(0 if generated else 1)" + && sudo systemctl reload gunicorn.service user: "{{ app_username }}" minute: "*/5" diff --git a/ansible/roles/gunicorn/files/gunicorn_reloader.path b/ansible/roles/gunicorn/files/gunicorn_reloader.path deleted file mode 100644 index 3fb2132..0000000 --- a/ansible/roles/gunicorn/files/gunicorn_reloader.path +++ /dev/null @@ -1,5 +0,0 @@ -[Path] -PathChanged=/opt/tildes/static/css/site-icons.css - -[Install] -WantedBy=multi-user.target diff --git a/ansible/roles/gunicorn/files/gunicorn_reloader.service b/ansible/roles/gunicorn/files/gunicorn_reloader.service deleted file mode 100644 index 21f609c..0000000 --- a/ansible/roles/gunicorn/files/gunicorn_reloader.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=gunicorn reloader -After=network.target - -[Service] -Type=oneshot -ExecStart=/bin/systemctl reload gunicorn.service - -[Install] -WantedBy=multi-user.target diff --git a/ansible/roles/gunicorn/tasks/main.yml b/ansible/roles/gunicorn/tasks/main.yml index cc3f268..0378da4 100644 --- a/ansible/roles/gunicorn/tasks/main.yml +++ b/ansible/roles/gunicorn/tasks/main.yml @@ -29,35 +29,8 @@ state: started enabled: true -# Set up the gunicorn_reloader service, which reloads gunicorn whenever certain files -# are changed (such as static files, to update the cache-busting strings) -- name: Create gunicorn_reloader service file - copy: - src: gunicorn_reloader.service - dest: /etc/systemd/system/gunicorn_reloader.service - owner: root - group: root - mode: 0644 - -- name: Create gunicorn_reloader path-monitoring file - copy: - src: gunicorn_reloader.path - dest: /etc/systemd/system/gunicorn_reloader.path - owner: root - group: root - mode: 0644 - -- name: Start and enable gunicorn_reloader path-monitoring service, with fallback - block: - - name: Start and enable gunicorn_reloader path-monitoring service - systemd_service: - name: gunicorn_reloader.path - state: started - enabled: true - rescue: - # Likely Docker; systemctl3.py doesn't support .path, so enable .service here - - name: Start and enable gunicorn.service (if .path service fails) - systemd_service: - name: gunicorn.service - state: started - enabled: true +- name: Start and enable gunicorn service + systemd_service: + name: gunicorn.service + state: started + enabled: true diff --git a/tildes/scripts/generate_site_icons_css.py b/tildes/scripts/generate_site_icons_css.py index e26d99a..45d5292 100644 --- a/tildes/scripts/generate_site_icons_css.py +++ b/tildes/scripts/generate_site_icons_css.py @@ -34,10 +34,13 @@ def _is_output_file_outdated() -> bool: return False -def generate_css() -> None: - """Generate the CSS file for site icons and replace the old one.""" +def generate_css() -> bool: + """Generate the CSS file for site icons and replace the old one. + + Return True if generated, otherwise return False if skipped. + """ if not _is_output_file_outdated(): - return + return False with NamedTemporaryFile(mode="w") as temp_file: for filename in os.listdir(ICON_FOLDER): @@ -54,3 +57,5 @@ def generate_css() -> None: # set file permissions to 644 (rw-r--r--) os.chmod(OUTPUT_FILE, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) + + return True