瀏覽代碼

Add (r)syslog configuration for PHP

Emmanuel Bouthenot 9 年之前
父節點
當前提交
d2efdd1a6b

+ 2 - 0
roles/webserver/handlers/php.yml

@@ -0,0 +1,2 @@
+- name: Reload rsyslog for php
+  service: name=rsyslog state=restarted

+ 13 - 0
roles/webserver/tasks/php.yml

@@ -9,6 +9,19 @@
     - php-mime-type
   when: with_php
 
+- name: Create PHP log directory
+  file: path=/var/log/php state=directory owner=root group=root mode=0755
+  when: with_php and with_fpm
+
+- name: Install PHP configuration for syslog
+  template: src={{ item.src }} dest={{ item.dest }} owner=root group=root mode=0644
+  with_items:
+    - { src: 'rsyslog/php-errors.conf.j2', dest: '/etc/rsyslog.d/php-errors.conf' }
+    - { src: 'logrotate/php-errors.j2', dest: '/etc/logrotate.d/php-errors' }
+  notify:
+      - Reload rsyslog for php
+  when: with_php and with_fpm
+
 - name: Install local PHP configuration
   template: src=php/php-config.ini.j2 dest=/etc/php5/conf.d/99-local-config.ini owner=root group=root mode=0644
   when: with_php

+ 16 - 0
roles/webserver/templates/logrotate/php-errors.j2

@@ -0,0 +1,16 @@
+{% if ansible_prolog -%}
+{% from 'templates/ansible/prolog.j2' import prolog with context %}
+{{ prolog() }}
+{% endif -%}
+
+/var/log/php/*.log
+{
+    rotate 12
+    daily
+    dateext
+    dateyesterday
+    missingok
+    notifempty
+    delaycompress
+    compress
+}

+ 8 - 0
roles/webserver/templates/rsyslog/php-errors.conf.j2

@@ -0,0 +1,8 @@
+{% if ansible_prolog -%}
+{% from 'templates/ansible/prolog.j2' import prolog with context %}
+{{ prolog() }}
+{% endif -%}
+$FileCreateMode 0644
+:msg, contains, ": PHP " /var/log/php/php-errors.log
+# Reset mode to the default: 0640
+$FileCreateMode 0640