Browse Source

php socket activation

master
Jörg Thalheim 7 years ago
parent
commit
46c8dfe23b
  1. 5
      roles/php/files/php-fpm-stop.service
  2. 10
      roles/php/files/php-fpm-stop.timer
  3. 11
      roles/php/files/php-fpm.service
  4. 5
      roles/php/files/php-fpm.socket
  5. 8
      roles/php/files/stop-php-fpm
  6. 4
      roles/php/handlers/main.yml
  7. 25
      roles/php/tasks/main.yml
  8. 2
      roles/php/templates/php-fpm.conf.j2

5
roles/php/files/php-fpm-stop.service

@ -0,0 +1,5 @@
[Unit]
Description="Stop php-fpm"
[Service]
ExecStart=/usr/local/bin/stop-php-fpm

10
roles/php/files/php-fpm-stop.timer

@ -0,0 +1,10 @@
[Unit]
Description=Stop php-fpm
[Timer]
OnBootSec=2min
OnUnitActiveSec=2min
Persistent=true
[Install]
WantedBy=multi-user.target

11
roles/php/files/php-fpm.service

@ -0,0 +1,11 @@
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=notify
PIDFile=/run/php-fpm/php-fpm.pid
PrivateTmp=true
Environment="FPM_SOCKETS=/var/run/php-fpm.socket=3"
ExecStart=/usr/bin/php-fpm --nodaemonize --pid /run/php-fpm/php-fpm.pid
ExecReload=/bin/kill -USR2 $MAINPID

5
roles/php/files/php-fpm.socket

@ -0,0 +1,5 @@
[Socket]
ListenStream=9000
[Install]
WantedBy=sockets.target

8
roles/php/files/stop-php-fpm

@ -0,0 +1,8 @@
#!/bin/bash
PID=$(cat /run/php-fpm/php-fpm.pid)
CHILDREN=$(ps -o pid --no-headers --ppid "$PID" | wc -l)
if [ $CHILDREN == "0" ]; then
kill "$PID"
fi

4
roles/php/handlers/main.yml

@ -1,2 +1,4 @@
- name: restart php-fpm
- name: stop php-fpm
service: name=php-fpm state=restarted
- name: Reload systemd
action: command systemctl daemon-reload

25
roles/php/tasks/main.yml

@ -1,10 +1,27 @@
- name: install php-fpm
pacman: name=php-fpm state=present
- name: Enable php-fpm
service: name=php-fpm state=started enabled=yes
- name: php-fpm.ini
template: src=php-fpm.conf.j2 dest=/etc/php/php-fpm.conf mode=0644 backup=yes
notify: restart php-fpm
notify: stop php-fpm
- name: php.ini
template: src=php.ini.j2 dest=/etc/php/php.ini mode=0644 backup=yes
notify: restart php-fpm
notify: stop php-fpm
- copy: src={{ item }} dest=/etc/systemd/system/{{ item }} mode=0644
with_items:
- php-fpm.service
- php-fpm.socket
- php-fpm-stop.timer
- php-fpm-stop.service
notify: Reload systemd
- copy: src=stop-php-fpm dest=/usr/local/bin/stop-php-fpm mode=0755
- shell: /usr/bin/systemctl --quiet is-active php-fpm.socket
register: fpm_socket_started
ignore_errors: True
- name: Stop php-fpm
service: name=php-fpm.service state=stopped
when: fpm_socket_started.rc != 0
- name: Start php-fpm socket activation
service: name={{item}} state=started enabled=yes
with_items:
- php-fpm.socket
- php-fpm-stop.timer

2
roles/php/templates/php-fpm.conf.j2

@ -158,7 +158,7 @@ group = http
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 0.0.0.0:9000
listen = /var/run/php-fpm.socket ; pseudo socket, will no be used really
; Set listen(2) backlog.
; Default Value: 65535 (-1 on FreeBSD and OpenBSD)

Loading…
Cancel
Save