Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pillar/cms.sls
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ backup:
# Sites are configured in each CMS' Pillar file.
apache:
public_access: True
site_logs: True

# Databases and users are configured in each CMS' Pillar file.
mysql:
Expand Down
6 changes: 6 additions & 0 deletions salt/apache/files/sites/_common.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
{#- https://github.com/icing/mod_md#tls-alpn-challenges #}
Protocols h2 http/1.1 acme-tls/1

{#- System-wide configuration files should be prefixed with numbers #}
{%- if pillar.apache.site_logs|default(False) and not name[0:1].isdigit() %}
Comment thread
RobHooper marked this conversation as resolved.
Outdated
ErrorLog {{ log_directory }}/error.log
CustomLog {{ log_directory }}/access.log vhost_combined
{%- endif %}

Include {{ includefile }}
{%- elif not servername %}

Expand Down
8 changes: 6 additions & 2 deletions salt/apache/init.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from 'lib.sls' import apache, set_firewall, unset_firewall %}
{% from 'lib.sls' import apache, logrotate, set_firewall, unset_firewall %}

{% if salt['pillar.get']('apache:public_access') %}
{{ set_firewall('PUBLIC_HTTP') }}
Expand Down Expand Up @@ -63,7 +63,7 @@ apache2-utils:

# Ensure this configuration is loaded first.
{{ apache('00-default', {'configuration': 'default', 'servername': ''}) }}
{{ apache('fqdn', {'configuration': 'default', 'servername': grains.fqdn}) }}
{{ apache('10-fqdn', {'configuration': 'default', 'servername': grains.fqdn}) }}

{% if salt['pillar.get']('apache:modules:mod_autoindex:enabled') %}
autoindex:
Expand Down Expand Up @@ -143,3 +143,7 @@ disable-conf-other-vhosts-access-log.conf:
- onchanges:
- file: /etc/systemd/system/apache2.service.d/customization.conf
{% endif %}

{% if pillar.apache.site_logs|default(False) %}
{{ logrotate("apache-site-logs") }}
Comment thread
RobHooper marked this conversation as resolved.
Outdated
{% endif %}
20 changes: 20 additions & 0 deletions salt/core/logrotate/files/apache-site-logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/var/log/apache2/*/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then
run-parts /etc/logrotate.d/httpd-prerotate
fi
endscript
postrotate
if pgrep -f ^/usr/sbin/apache2 > /dev/null; then
invoke-rc.d apache2 reload 2>&1 | logger -t apache2.logrotate
fi
endscript
Comment thread
RobHooper marked this conversation as resolved.
Outdated
}
10 changes: 3 additions & 7 deletions salt/core/logrotate/init.sls
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{% from 'lib.sls' import logrotate %}

# Some configurations use `postrotate /usr/lib/rsyslog/rsyslog-rotate`, so rsyslog is required.
include:
- core.rsyslog

{% for filename, entry in salt['pillar.get']('logrotate:conf', {})|items %}
/etc/logrotate.d/{{ filename }}:
file.managed:
- source: salt://core/logrotate/files/{{ entry.source }}
{% if 'context' in entry %}
- template: jinja
- context: {{ entry.context|yaml }}
{% endif %}
{{ logrotate(filename, entry) }}
{% endfor %}
21 changes: 21 additions & 0 deletions salt/lib.sls
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ unset {{ setting_name }} in {{ filename }}:
servername: {{ entry.servername }}
serveraliases: {{ entry.serveraliases|default([])|yaml }}
https: {{ entry.https|default(true) }}
log_directory: /var/log/apache2/{{ name }}
- require:
- file: /etc/apache2/sites-available/{{ name }}.conf.include
- watch_in:
Expand All @@ -190,6 +191,16 @@ add .htpasswd-{{ name }}-{{ username }}:
- require:
- pkg: apache2
{% endfor %}

{% if pillar.apache.site_logs|default(False) and not name[0:1].isdigit() %}
/var/log/apache2/{{ name }}:
file.directory:
- user: root
- group: adm
- dir_mode: 755
- require_in:
- file: /etc/apache2/sites-available/{{ name }}.conf
{% endif%}
{% endmacro %}

{#
Expand Down Expand Up @@ -242,3 +253,13 @@ add .htpasswd-{{ name }}-{{ username }}:
- watch_in:
- module: nginx-reload
{% endmacro %}

{% macro logrotate(name, entry={}) %}
/etc/logrotate.d/{{ name }}:
file.managed:
- source: salt://core/logrotate/files/{{ entry.source|default(name) }}
{% if 'context' in entry %}
- template: jinja
- context: {{ entry.context|yaml }}
{% endif %}
{% endmacro %}