Commit b0d0efc2 authored by Vincent Pelletier's avatar Vincent Pelletier

stack.logrotate: Fix support for stopped processes.

When a process is stopped:
- it may not have emitted logs since previous rotation: add "missingok"
  As a direct consequence: stop using logrotate recipe.
- its pid file (if applicable) may be missing: test its non-empty presence
  before calling slapos-kill
Also, stop using slapos.cookbook:logrotate.
Update obvious users (cloudooo, neoppod, erp5, monitor, re6stnet).
parent 80ea6aed
......@@ -150,12 +150,10 @@ crl =
{%- endif %}
[apache-logrotate]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = apache
log = ${apache-conf-parameter-dict:error-log} ${apache-conf-parameter-dict:access-log}
post = {{ bin_directory }}/slapos-kill --pidfile ${apache-conf-parameter-dict:pid-file} -s USR1
post = test ! -s ${apache-conf-parameter-dict:pid-file} || {{ bin_directory }}/slapos-kill --pidfile ${apache-conf-parameter-dict:pid-file} -s USR1
[publish]
recipe = slapos.cookbook:publish.serialised
......
......@@ -83,5 +83,5 @@ template-logrotate-base = ${template-logrotate-base:rendered}
[template-cloudooo-instance]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/instance-cloudooo.cfg.in
md5sum = 3de0b4732e5132448027c1387a4de3c9
md5sum = e1a4a73aeb8b978e953a3f4f39b98a4d
mode = 640
......@@ -22,9 +22,7 @@ port = ${neo-admin:port}
path = ${directory:promises}/neo-admin-promise
[logrotate-admin]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = neo-admin
log = ${neo-admin:logfile}
post = {{ bin_directory }}/slapos-kill -n neoadmin -s RTMIN+1 ${:log}
......
......@@ -30,9 +30,7 @@ port = ${neo-master:port}
path = ${directory:promises}/neo-master-promise
[logrotate-master]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = neo-master
log = ${neo-master:logfile}
post = {{ bin_directory }}/slapos-kill -n neomaster -s RTMIN+1 ${:log}
......@@ -88,11 +88,6 @@ database-adapter = MySQL
wait-database = 60
engine = {{ slapparameter_dict.get('engine', '') }}
[logrotate-storage]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
{% for i in range(slapparameter_dict.get('storage-count', 1)) -%}
{% set storage_id = 'neo-storage-' ~ i -%}
[{{ section(storage_id) }}]
......@@ -103,7 +98,7 @@ logfile = ${directory:log}/{{ 'neostorage-' ~ i }}.log
database-parameters = root@neo{{ i }}${my-cnf-parameters:socket}
[{{ section('logrotate-storage-' ~ i) }}]
< = logrotate-storage
< = logrotate-entry-base
name = {{ storage_id }}
log = {{ '${' + storage_id + ':logfile}' }}
post = {{ bin_directory }}/slapos-kill -n neostorage -s RTMIN+1 ${:log}
......@@ -129,9 +124,7 @@ log = ${buildout:directory}/var/log
tmp = ${buildout:directory}/tmp
[logrotate-mysql]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = mariadb
log = ${my-cnf-parameters:error-log} ${my-cnf-parameters:slow-query-log}
post = ${mysqld:mysql-base-directory}/bin/mysql --defaults-file="${my-cnf:rendered}" -e "FLUSH LOGS"
......
......@@ -89,15 +89,15 @@ md5sum = f3259726bd5d824c569dc7db6b7d26a0
[instance-neo-admin]
<= download-base-neo
md5sum = ec1e2d9d2a1da092621f1b01ce6af322
md5sum = d5eb14e3d83d7787950de913d7e29aad
[instance-neo-master]
<= download-base-neo
md5sum = 82f3f76f54ee9db355966a7ada61f56e
md5sum = c6e0db7344a26a55580102e3cc33c984
[instance-neo-storage-mysql]
<= download-base-neo
md5sum = cd2a978a09c5686205592923866f6584
md5sum = 22206396eff084af3e0587494a012174
[template-neo-my-cnf]
<= download-base-neo
......
......@@ -102,7 +102,7 @@ context =
< = logrotate-entry-base
name = apache
log = ${apache-conf:error-log} ${apache-conf:access-log}
post = {{ parameter_dict['bin-directory'] }}/slapos-kill --pidfile ${apache-conf:pid-file} -s USR1
post = test ! -s ${apache-conf:pid-file} || {{ parameter_dict['bin-directory'] }}/slapos-kill --pidfile ${apache-conf:pid-file} -s USR1
[re6st-registry-conf-dict]
port = 9201
......@@ -192,7 +192,7 @@ command = {{ python_bin }} ${re6st-registry:drop-service-wrapper}
< = logrotate-entry-base
name = re6stnet
log = ${re6st-registry-conf-dict:logfile}
post = {{ parameter_dict['bin-directory'] }}/slapos-kill --pidfile ${re6st-registry:pid-file} -s USR1
post = test ! -s ${re6st-registry:pid-file} || {{ parameter_dict['bin-directory'] }}/slapos-kill --pidfile ${re6st-registry:pid-file} -s USR1
[re6st-registry-promise]
recipe = slapos.cookbook:check_port_listening
......
......@@ -88,7 +88,7 @@ extra-context =
[template-re6stnet]
< = download-base
filename = instance-re6stnet.cfg.in
md5sum = c5f535e1e25cb91f66d28f04684f0858
md5sum = 6e9452d283e82e2f512a9f9edb17fe3a
[template-apache-conf]
< = download-base
......
......@@ -19,11 +19,11 @@ md5sum = 372e5247d0a1514f3406228407b10d77
[template-mariadb]
filename = instance-mariadb.cfg.in
md5sum = 5eaf56d0f5c70a12980d3c4cea27c36d
md5sum = 11e7faca5233868c1643854e4c898588
[template-kumofs]
filename = instance-kumofs.cfg.in
md5sum = 763db0c4a94649296e74fe1f53c03940
md5sum = 42d2a2c7cb5bf5122b6cfd8f53a5576f
[template-cloudooo]
filename = instance-cloudoo.cfg.in
......@@ -83,15 +83,15 @@ md5sum = b5f49c90017684aa3389ef3f97ece509
[template-zeo]
filename = instance-zeo.cfg.in
md5sum = 84aba4fa10d3087fbcc1d979df90fab9
md5sum = 7610bafda245c008ccf0b6ea58ce21c2
[template-zope]
filename = instance-zope.cfg.in
md5sum = 3a029d0d94e4f60395b8b202f5422e91
md5sum = 70caadf8819a76875cf5abf2f979f4d6
[template-balancer]
filename = instance-balancer.cfg.in
md5sum = aa2092e478131d7c6d55fa9d12b6b0f2
md5sum = d71c49f91b3455e6866f4b2db591009f
[template-haproxy-cfg]
filename = haproxy.cfg.in
......
......@@ -185,12 +185,10 @@ crl =
{%- endif %}
[logrotate-apache]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = apache
log = ${apache-conf-parameter-dict:error-log} ${apache-conf-parameter-dict:access-log}
post = {{ parameter_dict['bin-directory'] }}/slapos-kill --pidfile ${apache-conf-parameter-dict:pid-file} -s USR1
post = test ! -s ${apache-conf-parameter-dict:pid-file} || {{ parameter_dict['bin-directory'] }}/slapos-kill --pidfile ${apache-conf-parameter-dict:pid-file} -s USR1
[directory]
recipe = slapos.cookbook:mkdirectory
......
......@@ -63,9 +63,7 @@ kumo-server-binary = {{ parameter_dict['kumo-location'] }}/bin/kumo-server
shell-path = {{ parameter_dict['dash-location'] }}/bin/dash
[logrotate-entry-kumofs]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = kumofs
log = ${kumofs-instance:kumo-gateway-log} ${kumofs-instance:kumo-manager-log} ${kumofs-instance:kumo-server-log}
......
......@@ -174,9 +174,7 @@ template = inline:#!{{ parameter_dict['dash-location'] }}/bin/dash
rendered = ${directory:services}/mariadb
[logrotate-entry-mariadb]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
< = logrotate-entry-base
name = mariadb
log = ${my-cnf-parameters:error-log} ${my-cnf-parameters:slow-query-log}
post = "${binary-wrap-mysql:wrapper-path}" -B -u root -e "FLUSH LOGS"
......
......@@ -8,11 +8,6 @@
{% set default_backup_path = buildout_directory ~ '/srv/backup/zodb' -%}
{% set bin_directory = parameter_dict['buildout-bin-directory'] -%}
[logrotate-base]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
[zeo-base]
recipe = slapos.cookbook:zeo
log-path = ${directory:log}/${:base-name}.log
......@@ -53,10 +48,10 @@ port = {{ current_port }}
storage = {{ dumps(storage_list) }}
[{{ section("logrotate-" ~ zeo_section_name) }}]
< = logrotate-base
< = logrotate-entry-base
name = {{ "${" ~ zeo_section_name ~ ":base-name}" }}
log = {{ "${" ~ zeo_section_name ~ ":log-path}" }}
post = {{ bin_directory }}/slapos-kill --pidfile {{ "${" ~ zeo_section_name ~ ":pid-path}" }} -s USR2
post = test ! -s {{ "${" ~ zeo_section_name ~":pid-path}" }} || {{ bin_directory }}/slapos-kill --pidfile {{ "${" ~ zeo_section_name ~ ":pid-path}" }} -s USR2
[{{ section(zeo_section_name ~ "-promise") }}]
recipe = slapos.cookbook:check_port_listening
......
......@@ -260,11 +260,6 @@ timerserver-interval = {{ dumps(timerserver_interval) }}
< = jinja2-template-base
template = {{ parameter_dict['zope-conf-template'] }}
[logrotate-entry-base]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
{% macro zope(
index,
port,
......@@ -356,7 +351,7 @@ path = ${directory:promises}/{{ zope_tunnel_base_name }}
< = logrotate-entry-base
name = {{ name }}
log = {{ '${' ~ conf_parameter_name ~ ':event-log}' }} {{ '${' ~ conf_parameter_name ~ ':z2-log}' }} {{ '${' ~ conf_parameter_name ~ ':longrequest-logger-file}' }} {{ ' '.join(log_list) }}
post = {{ bin_directory }}/slapos-kill --pidfile {{ '${' ~ conf_parameter_name ~ ':pid-file}' }} -s USR2
post = test ! -s {{ '${' ~ conf_parameter_name ~ ':pid-file}' }} || {{ bin_directory }}/slapos-kill --pidfile {{ '${' ~ conf_parameter_name ~ ':pid-file}' }} -s USR2
{% endmacro -%}
{% for i in range(slapparameter_dict['instance-count']) -%}
......
......@@ -6,13 +6,29 @@ extends =
parts =
template-logrotate-base
[logrotate-conf-template]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/logrotate.conf.in
md5sum = 24f021a248f2802ee70857cf3d8832f2
# XXX: following mode should be the default
mode = 644
[logrotate-entry-template]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/logrotate_entry.in
md5sum = 7a5ec8f141c61826a14db8619acba314
# XXX: following mode should be the default
mode = 644
[template-logrotate-base]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/${:filename}.in
rendered = ${buildout:directory}/${:filename}
filename = instance-logrotate-base.cfg
md5sum = 4f940a5b5a6abac039738b45633c709c
md5sum = 3e3e572c5537f77e83b1ee157d1c9852
context =
key dcron_location dcron:location
key gzip_location gzip:location
key logrotate_location logrotate:location
key logrotate_conf_template logrotate-conf-template:target
key logrotate_entry_template logrotate-entry-template:target
......@@ -17,27 +17,52 @@ recipe = slapos.cookbook:simplelogger
wrapper = ${logrotate-directory:bin}/cron_simplelogger
log = ${logrotate-directory:log}/cron.log
[logrotate]
recipe = slapos.cookbook:logrotate
logrotate-entries = ${logrotate-directory:logrotate-entries}
backup = ${logrotate-directory:logrotate-backup}
logrotate-binary = {{ logrotate_location }}/usr/sbin/logrotate
[logrotate-conf-parameter]
gzip-binary = {{ gzip_location }}/bin/gzip
gunzip-binary = {{ gzip_location }}/bin/gunzip
wrapper = ${logrotate-directory:bin}/logrotate
conf = ${logrotate-directory:etc}/logrotate.conf
state-file = ${logrotate-directory:srv}/logrotate.status
logrotate-entries = ${logrotate-directory:logrotate-entries}
[logrotate-conf]
recipe = slapos.recipe.template:jinja2
template = {{ logrotate_conf_template }}
rendered = ${logrotate-directory:etc}/logrotate.conf
context =
section parameter_dict logrotate-conf-parameter
[logrotate-entry-base]
# User must define keys:
# - "name" to generate configuration path (must be unique in partition)
# - "log" space-separated list of file paths to be rotated
# User may override keys:
# - "post" with commands to execute after rotation
# - "pre" with commands to execute before rotation
recipe = slapos.recipe.template:jinja2
template = {{ logrotate_entry_template }}
rendered = ${logrotate-conf-parameter:logrotate-entries}/${:name}
context =
key backup logrotate-directory:logrotate-backup
key log :log
key post :post
key pre :pre
post =
pre =
[logrotate]
recipe = slapos.cookbook:wrapper
parameters-extra = true
command-line = {{ logrotate_location }}/usr/sbin/logrotate -s "${logrotate-directory:srv}/logrotate.status" "${logrotate-conf:rendered}"
wrapper-path = ${logrotate-directory:bin}/logrotate
[cron-entry-logrotate]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = logrotate
frequency = 0 0 * * *
command = ${logrotate:wrapper}
command = ${logrotate:wrapper-path}
[logrotate-entry-base]
recipe = slapos.cookbook:logrotate.d
logrotate-entries = ${logrotate:logrotate-entries}
logrotate-entries = ${logrotate-directory:logrotate-entries}
backup = ${logrotate-directory:backup}
[logrotate-entry-cron]
......@@ -58,4 +83,3 @@ backup = ${:srv}/backup
etc = ${buildout:directory}/etc
services = ${:etc}/run
log = ${buildout:directory}/var/log
compresscmd {{ parameter_dict['gzip-binary'] }}
compressoptions -9
uncompresscmd {{ parameter_dict['gunzip-binary'] }}
include {{ parameter_dict['logrotate-entries'] }}
{{ log }} {
daily
dateext
rotate 3650
compress
delaycompress
notifempty
sharedscripts
create
olddir {{ backup }}
missingok
{% if pre %}prerotate {
{{ pre }}
}{% endif %}
{% if post %}postrotate {
{{ post }}
}{% endif %}
}
......@@ -102,7 +102,7 @@ recipe = slapos.recipe.template:jinja2
filename = template-monitor.cfg
template = ${:_profile_base_location_}/instance-monitor.cfg.jinja2.in
rendered = ${buildout:directory}/template-monitor.cfg
md5sum = 8433adc2ad0bc3a443ff941580593fb0
md5sum = be07297494e08377c4dfecb26c2919ef
context =
key apache_location apache:location
key gzip_location gzip:location
......
......@@ -82,7 +82,7 @@ base-url = ${monitor-instance-parameter:monitor-base-url}
monitor-hal-json = ${monitor-directory:public}/monitor.hal.json
service-pid-folder = ${monitor-directory:pids}
crond-folder = ${logrotate-directory:cron-entries}
logrotate-folder = ${logrotate:logrotate-entries}
logrotate-folder = ${logrotate-directory:logrotate-entries}
promise-runner = {{ monitor_runpromise }}
promise-folder = ${directory:promises}
monitor-promise-folder = ${monitor-directory:promises}
......
  • NEO logs aren't rotated correctly since this commit. The issue seems to come from the 2 [logrotate-entry-base] sections of stack/logrotate/instance-logrotate-base.cfg.in

    /cc @yusei

  • Indeed, this is a rebase conflict which was not detected (by me and by git) against 8b8afc35, as I had this commit for a long time locally. Should be fixed in 1de12d19 .

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment