php socket activation

This commit is contained in:
Jörg Thalheim 2014-08-21 21:25:40 +02:00
parent 9dffeb8646
commit 46c8dfe23b
8 changed files with 64 additions and 6 deletions

View File

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

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)