From 112cc4993293fe328780a25a5841328df25ab14e Mon Sep 17 00:00:00 2001 From: David Seira Date: Fri, 27 Sep 2019 14:05:54 +0200 Subject: [PATCH] Fixed varnish 6 systemd packaging changes --- README.md | 26 ++++++++++++++++++++++++++ varnish/ng/service.sls | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/README.md b/README.md index 50618ce..86a4f4f 100644 --- a/README.md +++ b/README.md @@ -190,3 +190,29 @@ WantedBy=multi-user.target ``` So you can edit and have the file managed by salt. + + +* Varnish versions from 6 (including it) have change the systemd unit service; are OS agnostic (see [packaging changes](https://varnish-cache.org/docs/trunk/whats-new/upgrading-6.0.html#packaging-changes)). + +For Debian Family OSes can use the previous trick (changing the unit service). + +For RedHat Family OSes there is a new variable `version` that setup an `override.conf` for the default varnish systemd service that allow to use the `varnish.params` file. For example, to install varnish 6 LTS: + +``` +varnish: + ng: + lookup: + repo: 'varnish60lts' + version: '6' + install_from_repo: True + enabled: True + config_source_path: salt://hostname/varnish.params.jinja + vcl: + files: + default: + path: /etc/varnish/default.vcl + source_path: salt://hostname/default.vcl.jinja +``` + +This change is compatible with other varnish versions (there is no error if not set). + diff --git a/varnish/ng/service.sls b/varnish/ng/service.sls index 2c9229e..356c560 100644 --- a/varnish/ng/service.sls +++ b/varnish/ng/service.sls @@ -3,6 +3,46 @@ {% from "varnish/ng/map.jinja" import varnish_settings with context %} +{% set initsystem = salt['grains.get']('init') %} +{% set version = varnish_settings.version | default('0') %} + +{% if initsystem == 'systemd' and version >= '6' %} + +{% if grains['os_family'] == 'RedHat' %} + +varnish.systemd_varnish_params: + file.managed: + - name: /etc/systemd/system/varnish.service.d/override.conf + - makedirs: True + - user: root + - group: root + - mode: '644' + - contents: | + [Service] + EnvironmentFile=/etc/varnish/varnish.params + ExecStart= + ExecStart=/usr/sbin/varnishd \ + -P /var/run/varnish.pid \ + -f ${VARNISH_VCL_CONF} \ + -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ + -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ + -S ${VARNISH_SECRET_FILE} \ + -s ${VARNISH_STORAGE} \ + $DAEMON_OPTS + module.run: + - name: service.systemctl_reload + - onchanges: + - file: /etc/systemd/system/varnish.service.d/override.conf + +{% endif %} + +varnish.varnish_secret: + cmd.run: + - name: uuidgen > /etc/varnish/secret + - unless: test -f /etc/varnish/secret + +{% endif %} + varnish.service: {% if ( 'enabled' in varnish_settings and varnish_settings.enabled ) or ('enabled' not in varnish_settings ) %} service.running: