diff --git a/roles/cs.php-fpm/tasks/004-logrotate.yml b/roles/cs.php-fpm/tasks/004-logrotate.yml new file mode 100644 index 000000000..751951c25 --- /dev/null +++ b/roles/cs.php-fpm/tasks/004-logrotate.yml @@ -0,0 +1,16 @@ +- name: Ensure PHP-FPM log directory has correct permissions + file: + path: /var/log/php-fpm + state: directory + owner: root + group: root + mode: '0755' + +- name: Create PHP-FPM logrotate configuration + template: + src: php-fpm.logrotate.conf.j2 + dest: /etc/logrotate.d/php-fpm + owner: root + group: root + mode: '0644' + \ No newline at end of file diff --git a/roles/cs.php-fpm/tasks/main.yml b/roles/cs.php-fpm/tasks/main.yml index a64ec98af..74314b404 100644 --- a/roles/cs.php-fpm/tasks/main.yml +++ b/roles/cs.php-fpm/tasks/main.yml @@ -20,6 +20,8 @@ set_fact: php_fpm_pm_max_children_default: "{{ [ [ php_fpm_pm_max_children_by_memory | int, php_fpm_pm_max_children_by_cpu | int ] | min, 4 ] | max }}" +- import_tasks: 004-logrotate.yml + - name: Calculate workers set_fact: php_fpm_pm_max_children: "{{ php_fpm_pm_max_children | default(php_fpm_pm_max_children_default, true) }}" diff --git a/roles/cs.php-fpm/templates/php-fpm.logrotate.conf.j2 b/roles/cs.php-fpm/templates/php-fpm.logrotate.conf.j2 new file mode 100644 index 000000000..1c6bbaa00 --- /dev/null +++ b/roles/cs.php-fpm/templates/php-fpm.logrotate.conf.j2 @@ -0,0 +1,13 @@ +/var/log/php-fpm/*.log { + missingok + notifempty + daily + rotate 14 + compress + delaycompress + create 0640 root root + sharedscripts + postrotate + /bin/kill -SIGUSR1 $(cat /var/run/php-fpm/php-fpm.pid 2>/dev/null) 2>/dev/null || true + endscript +}