From fef87e76791fca17b389dae630007478d6a96902 Mon Sep 17 00:00:00 2001 From: Antsiferov Grigory Date: Fri, 29 Jan 2021 13:35:59 +0300 Subject: [PATCH] Rename gentoo-mirrors to gentoo-mirror, add logrotate config --- .../cache.sls | 0 .../files/gentoo-mirror-cache.nginx.conf.tpl | 0 .../files/gentoo-mirror-proxy-params.conf | 0 .../files/gentoo-mirror.logrotate | 6 ++ .../files/gentoo_mirror.nginx.conf.tpl | 0 .../files/gentoo_mirror.rsync.conf.tpl | 0 .../files/rsync-base.sh | 4 +- .../files/rsync-conf.tpl | 0 .../git-portage.sls | 0 .../rsync-distfiles.sls | 77 +++++++++++-------- sls/nginx/tls/gentoo-mirror.sls | 35 +++++++++ 11 files changed, 90 insertions(+), 32 deletions(-) rename sls/{gentoo-mirrors => gentoo-mirror}/cache.sls (100%) rename sls/{gentoo-mirrors => gentoo-mirror}/files/gentoo-mirror-cache.nginx.conf.tpl (100%) rename sls/{gentoo-mirrors => gentoo-mirror}/files/gentoo-mirror-proxy-params.conf (100%) create mode 100644 sls/gentoo-mirror/files/gentoo-mirror.logrotate rename sls/{gentoo-mirrors => gentoo-mirror}/files/gentoo_mirror.nginx.conf.tpl (100%) rename sls/{gentoo-mirrors => gentoo-mirror}/files/gentoo_mirror.rsync.conf.tpl (100%) rename sls/{gentoo-mirrors => gentoo-mirror}/files/rsync-base.sh (92%) rename sls/{gentoo-mirrors => gentoo-mirror}/files/rsync-conf.tpl (100%) rename sls/{gentoo-mirrors => gentoo-mirror}/git-portage.sls (100%) rename sls/{gentoo-mirrors => gentoo-mirror}/rsync-distfiles.sls (68%) create mode 100644 sls/nginx/tls/gentoo-mirror.sls diff --git a/sls/gentoo-mirrors/cache.sls b/sls/gentoo-mirror/cache.sls similarity index 100% rename from sls/gentoo-mirrors/cache.sls rename to sls/gentoo-mirror/cache.sls diff --git a/sls/gentoo-mirrors/files/gentoo-mirror-cache.nginx.conf.tpl b/sls/gentoo-mirror/files/gentoo-mirror-cache.nginx.conf.tpl similarity index 100% rename from sls/gentoo-mirrors/files/gentoo-mirror-cache.nginx.conf.tpl rename to sls/gentoo-mirror/files/gentoo-mirror-cache.nginx.conf.tpl diff --git a/sls/gentoo-mirrors/files/gentoo-mirror-proxy-params.conf b/sls/gentoo-mirror/files/gentoo-mirror-proxy-params.conf similarity index 100% rename from sls/gentoo-mirrors/files/gentoo-mirror-proxy-params.conf rename to sls/gentoo-mirror/files/gentoo-mirror-proxy-params.conf diff --git a/sls/gentoo-mirror/files/gentoo-mirror.logrotate b/sls/gentoo-mirror/files/gentoo-mirror.logrotate new file mode 100644 index 0000000..f86b39c --- /dev/null +++ b/sls/gentoo-mirror/files/gentoo-mirror.logrotate @@ -0,0 +1,6 @@ +# Managed by Salt + +/var/log/rsync-gentoo-.log { + missingok + delaycompress +} diff --git a/sls/gentoo-mirrors/files/gentoo_mirror.nginx.conf.tpl b/sls/gentoo-mirror/files/gentoo_mirror.nginx.conf.tpl similarity index 100% rename from sls/gentoo-mirrors/files/gentoo_mirror.nginx.conf.tpl rename to sls/gentoo-mirror/files/gentoo_mirror.nginx.conf.tpl diff --git a/sls/gentoo-mirrors/files/gentoo_mirror.rsync.conf.tpl b/sls/gentoo-mirror/files/gentoo_mirror.rsync.conf.tpl similarity index 100% rename from sls/gentoo-mirrors/files/gentoo_mirror.rsync.conf.tpl rename to sls/gentoo-mirror/files/gentoo_mirror.rsync.conf.tpl diff --git a/sls/gentoo-mirrors/files/rsync-base.sh b/sls/gentoo-mirror/files/rsync-base.sh similarity index 92% rename from sls/gentoo-mirrors/files/rsync-base.sh rename to sls/gentoo-mirror/files/rsync-base.sh index 3fb744c..dfda45a 100644 --- a/sls/gentoo-mirrors/files/rsync-base.sh +++ b/sls/gentoo-mirror/files/rsync-base.sh @@ -1,14 +1,14 @@ #!/bin/bash RSYNC="/usr/bin/rsync" -LOGDIR="/var/log" +LOGDIR="/var/log/gentoo-mirror" bname="$(basename ${0})" base="${bname%.*}" LOGFILE="${LOGDIR}/${base}.log" if [ "${base}" == "rsync-base" ]; then exit 0 fi -source "/etc/rsync/${base}.conf" +source "/etc/gentoo-mirror/${base}.conf" if flock -xn "${DST}" sleep 1; then echo "${base} is not locked" >> "${LOGFILE}" 2>&1 diff --git a/sls/gentoo-mirrors/files/rsync-conf.tpl b/sls/gentoo-mirror/files/rsync-conf.tpl similarity index 100% rename from sls/gentoo-mirrors/files/rsync-conf.tpl rename to sls/gentoo-mirror/files/rsync-conf.tpl diff --git a/sls/gentoo-mirrors/git-portage.sls b/sls/gentoo-mirror/git-portage.sls similarity index 100% rename from sls/gentoo-mirrors/git-portage.sls rename to sls/gentoo-mirror/git-portage.sls diff --git a/sls/gentoo-mirrors/rsync-distfiles.sls b/sls/gentoo-mirror/rsync-distfiles.sls similarity index 68% rename from sls/gentoo-mirrors/rsync-distfiles.sls rename to sls/gentoo-mirror/rsync-distfiles.sls index 913f9b4..5b6f171 100644 --- a/sls/gentoo-mirrors/rsync-distfiles.sls +++ b/sls/gentoo-mirror/rsync-distfiles.sls @@ -3,6 +3,7 @@ include: - nginx.tls.gentoo-mirror - rsyncd - cron + - logrotate {% set mirror_host = salt['pillar.get']('gentoo-mirror:mirror-host', 'gentoo.bakka.su') %} {% set dst_host = salt['pillar.get']('gentoo-mirror:dst-host', @@ -14,7 +15,7 @@ include: /etc/nginx/vhosts.d/gentoo-mirror.conf: file.managed: - - source: salt://gentoo-mirrors/files/gentoo_mirror.nginx.conf.tpl + - source: salt://{{ slspath }}/files/gentoo_mirror.nginx.conf.tpl - template: jinja - defaults: ssl: True @@ -31,60 +32,76 @@ include: - watch_in: - service: nginx-reload -/opt/gentoo-rsync/: +/opt/gentoo-mirror/: file.directory: - create: True - mode: 755 - user: root - group: root -/opt/gentoo-rsync/rsync-base.sh: +/opt/gentoo-mirror/rsync-base.sh: file.managed: - - source: salt://gentoo-mirrors/files/rsync-base.sh + - source: salt://{{ slspath }}/files/rsync-base.sh - mode: 755 - user: root - group: root - require: - - file: /opt/gentoo-rsync/ + - file: /opt/gentoo-mirror/ -/etc/rsync/: +/etc/gentoo-mirror/: file.directory: - create: True - mode: 755 - user: root - group: root +/var/log/gentoo-mirror/: + file.directory: + - create: True + - mode: 755 + - user: root + - group: root + +/etc/logrotate.d/gentoo-mirror: + file.managed: + - source: salt://{{ slspath }}/files/gentoo-mirror.logrotate + - mode: 644 + - user: root + - group: root + - require: + - file: /etc/logrotate.d/ + {% if 'gentoo-distfiles' in mirror_types %} "{{ default_root }}/gentoo-distfiles": file.directory: - create: True - makedirs: True -/etc/rsync/rsync-gentoo-distfiles.conf: +/etc/gentoo-mirror/rsync-gentoo-distfiles.conf: file.managed: - - source: salt://gentoo-mirrors/files/rsync-conf.tpl + - source: salt://{{ slspath }}/files/rsync-conf.tpl - template: jinja - defaults: rsync_src: "rsync://{{ mirror_host }}/gentoo-distfiles" rsync_dst: "{{ default_root }}/gentoo-distfiles" # - context: -/opt/gentoo-rsync/rsync-gentoo-distfiles.sh: +/opt/gentoo-mirror/rsync-gentoo-distfiles.sh: file.symlink: - - target: /opt/gentoo-rsync/rsync-base.sh + - target: /opt/gentoo-mirror/rsync-base.sh - require: - - file: /opt/gentoo-rsync/rsync-base.sh + - file: /opt/gentoo-mirror/rsync-base.sh rsync-gentoo-distfiles: cron.present: - identifier: rsync-gentoo-distfiles - - name: /opt/gentoo-rsync/rsync-gentoo-distfiles.sh + - name: /opt/gentoo-mirror/rsync-gentoo-distfiles.sh - user: root - minute: 0 - hour: '*/4' - require: - - file: /etc/rsync/rsync-gentoo-distfiles.conf - - file: /opt/gentoo-rsync/rsync-gentoo-distfiles.sh + - file: /etc/gentoo-mirror/rsync-gentoo-distfiles.conf + - file: /opt/gentoo-mirror/rsync-gentoo-distfiles.sh /etc/rsyncd.d/gentoo-distfiles.conf: ini.options_present: @@ -102,9 +119,9 @@ rsync-gentoo-distfiles: - create: True - makedirs: True -/etc/rsync/rsync-gentoo-portage.conf: +/etc/gentoo-mirror/rsync-gentoo-portage.conf: file.managed: - - source: salt://gentoo-mirrors/files/rsync-conf.tpl + - source: salt://{{ slspath }}/files/rsync-conf.tpl - template: jinja - defaults: rsync_src: "rsync://{{ mirror_host }}/gentoo-portage" @@ -112,22 +129,22 @@ rsync-gentoo-distfiles: rsync_opts: "+ --checksums" # - context: -/opt/gentoo-rsync/rsync-gentoo-portage.sh: +/opt/gentoo-mirror/rsync-gentoo-portage.sh: file.symlink: - - target: /opt/gentoo-rsync/rsync-base.sh + - target: /opt/gentoo-mirror/rsync-base.sh - require: - - file: /opt/gentoo-rsync/rsync-base.sh + - file: /opt/gentoo-mirror/rsync-base.sh rsync-gentoo-portage: cron.present: - identifier: rsync-gentoo-portage - - name: /opt/gentoo-rsync/rsync-gentoo-portage.sh + - name: /opt/gentoo-mirror/rsync-gentoo-portage.sh - user: root - minute: 0 - hour: '*/4' - require: - - file: /etc/rsync/rsync-gentoo-portage.conf - - file: /opt/gentoo-rsync/rsync-gentoo-portage.sh + - file: /etc/gentoo-mirror/rsync-gentoo-portage.conf + - file: /opt/gentoo-mirror/rsync-gentoo-portage.sh /etc/rsyncd.d/gentoo-portage.conf: ini.options_present: @@ -147,20 +164,20 @@ rsync-gentoo-portage: - makedirs: True {% for inst in salt['pillar.get']('gentoo-mirror:gentoo-package-repos', []) %} -/opt/gentoo-rsync/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.sh: +/opt/gentoo-mirror/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.sh: file.symlink: - - target: /opt/gentoo-rsync/rsync-base.sh + - target: /opt/gentoo-mirror/rsync-base.sh - require: - - file: /opt/gentoo-rsync/rsync-base.sh + - file: /opt/gentoo-mirror/rsync-base.sh "{{ default_root }}/{{ inst.get('rsync_dst', 'gentoo-packages/'+inst['arch']+'/'+inst['cpu_arch']) }}": file.directory: - create: True - makedirs: True -/etc/rsync/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.conf: +/etc/gentoo-mirror/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.conf: file.managed: - - source: salt://gentoo-mirrors/files/rsync-conf.tpl + - source: salt://{{ slspath }}/files/rsync-conf.tpl - template: jinja - defaults: rsync_src: "{{ inst.get('rsync_src', 'rsync://'+mirror_host+'/gentoo-packages/'+inst['arch']+'/'+inst['cpu_arch']) }}" @@ -169,14 +186,14 @@ rsync-gentoo-portage: rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages: cron.present: - identifier: rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages - - name: /opt/gentoo-rsync/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.sh + - name: /opt/gentoo-mirror/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.sh - user: root - dayweek: "{{ inst.get('day','*') }}" - hour: "{{ inst.get('hour','*/4') }}" - minute: "{{ inst.get('minute','0') }}" - require: - - file: /etc/rsync/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.conf - - file: /opt/gentoo-rsync/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.sh + - file: /etc/gentoo-mirror/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.conf + - file: /opt/gentoo-mirror/rsync-gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.sh /etc/rsyncd.d/gentoo-{{ inst['arch'] }}-{{ inst['cpu_arch'] }}-packages.conf: ini.options_present: diff --git a/sls/nginx/tls/gentoo-mirror.sls b/sls/nginx/tls/gentoo-mirror.sls new file mode 100644 index 0000000..90953ed --- /dev/null +++ b/sls/nginx/tls/gentoo-mirror.sls @@ -0,0 +1,35 @@ +{%- set cert_chain_key = salt.pillar.get('gentoo-mirror:cert-chain-key', 'gentoo-mirror') %} +{%- set privkey_key = salt.pillar.get('gentoo-mirror:privkey-key', cert_chain_key) %} +include: + - nginx + +/etc/ssl/nginx/gentoo-mirror/: + file.directory: + - create: True + - mode: 750 + - user: root + - group: nginx + +/etc/ssl/nginx/gentoo-mirror/certificate.pem: + file.managed: + - source: salt://ssl/certificate-chain.tpl + - template: jinja + - defaults: + cert_chain_key: "{{ cert_chain_key }}" + - mode: 644 + - user: root + - group: nginx + - watch_in: + - service: nginx-reload + +/etc/ssl/nginx/gentoo-mirror/privkey.pem: + file.managed: + - source: salt://ssl/privkey.tpl + - template: jinja + - defaults: + privkey_key: "{{ privkey_key }}" + - mode: 600 + - user: root + - group: root + - watch_in: + - service: nginx-reload