handle php logrotate
This commit is contained in:
@@ -10,6 +10,7 @@ This Ansible role installs and configures PHP with support for multiple versions
|
|||||||
- Create and manage PHP-FPM pools with custom configurations
|
- Create and manage PHP-FPM pools with custom configurations
|
||||||
- Support for multiple pools across different PHP versions
|
- Support for multiple pools across different PHP versions
|
||||||
- Automatic log directory creation with proper ownership
|
- Automatic log directory creation with proper ownership
|
||||||
|
- Automatic logrotate configuration for PHP-FPM logs
|
||||||
- Support for PHP-FPM
|
- Support for PHP-FPM
|
||||||
- Automatic repository setup (Sury repository for latest PHP versions)
|
- Automatic repository setup (Sury repository for latest PHP versions)
|
||||||
|
|
||||||
@@ -74,6 +75,9 @@ php_pools:
|
|||||||
|
|
||||||
# Remove default www pool
|
# Remove default www pool
|
||||||
php_remove_default_pool: false
|
php_remove_default_pool: false
|
||||||
|
|
||||||
|
# Logrotate configuration for PHP-FPM logs
|
||||||
|
php_logrotate_enabled: true
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example Playbooks
|
## Example Playbooks
|
||||||
@@ -184,6 +188,8 @@ The role will manage PHP-FPM services for each installed version:
|
|||||||
- Log directories are automatically created with proper ownership
|
- Log directories are automatically created with proper ownership
|
||||||
- Pool sockets are created with specific naming: `php{version}-fpm-{pool_name}.sock`
|
- Pool sockets are created with specific naming: `php{version}-fpm-{pool_name}.sock`
|
||||||
- You can create multiple pools for the same PHP version with different configurations
|
- You can create multiple pools for the same PHP version with different configurations
|
||||||
|
- Logrotate configuration is automatically created if logrotate is installed on the system
|
||||||
|
- PHP-FPM logs are rotated daily with 31 days retention and bzip2 compression
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -34,3 +34,6 @@ php_pools:
|
|||||||
admin_value_post_max_size: "16M"
|
admin_value_post_max_size: "16M"
|
||||||
|
|
||||||
php_remove_default_pool: false
|
php_remove_default_pool: false
|
||||||
|
|
||||||
|
# Logrotate configuration for PHP logs
|
||||||
|
php_logrotate_enabled: true
|
||||||
|
|||||||
@@ -33,3 +33,19 @@
|
|||||||
- php_remove_default_pool | bool
|
- php_remove_default_pool | bool
|
||||||
notify:
|
notify:
|
||||||
- restart php-fpm services
|
- restart php-fpm services
|
||||||
|
|
||||||
|
- name: php | check if logrotate is installed
|
||||||
|
package_facts:
|
||||||
|
manager: "auto"
|
||||||
|
|
||||||
|
- name: php | create logrotate configuration for php-fpm logs
|
||||||
|
template:
|
||||||
|
src: php-fpm.logrotate.j2
|
||||||
|
dest: "/etc/logrotate.d/php-fpm"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
when:
|
||||||
|
- php_logrotate_enabled | default(true) | bool
|
||||||
|
- "'logrotate' in ansible_facts.packages"
|
||||||
|
- php_pools is defined and php_pools | length > 0
|
||||||
|
|||||||
22
templates/php-fpm.logrotate.j2
Normal file
22
templates/php-fpm.logrotate.j2
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
daily
|
||||||
|
rotate 31
|
||||||
|
compress
|
||||||
|
compresscmd /bin/bzip2
|
||||||
|
uncompresscmd /bin/bunzip2
|
||||||
|
compressoptions -9
|
||||||
|
compressext .bz2
|
||||||
|
missingok
|
||||||
|
dateext
|
||||||
|
dateformat -%Y%m%d-%s
|
||||||
|
dateyesterday
|
||||||
|
notifempty
|
||||||
|
sharedscripts
|
||||||
|
su root adm
|
||||||
|
|
||||||
|
/var/log/php/*/*/php-slow.log
|
||||||
|
/var/log/php/*/*/php-errors.log
|
||||||
|
{
|
||||||
|
postrotate
|
||||||
|
if [ -d /run/systemd/system ]; then systemctl kill -s HUP rsyslog.service; else invoke-rc.d rsyslog rotate > /dev/null; fi
|
||||||
|
endscript
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user