Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769661
D1249.id3210.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D1249.id3210.diff
View Options
diff --git a/pillar/webserver-legacy/sites.sls b/pillar/webserver-legacy/sites.sls
--- a/pillar/webserver-legacy/sites.sls
+++ b/pillar/webserver-legacy/sites.sls
@@ -44,12 +44,18 @@
# Username must be unique and use max 31 characters.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+php_fpm_instances:
+ # PHP 7.1, generally installed as package/port
+ prod:
+ command: /usr/local/sbin/php-fpm
+
web_php_sites:
www.dereckson.be:
user: web-be-dereckson-www
source: wwwroot/dereckson.be/www
target: /var/wwwroot/dereckson.be/www
autochmod: True
+ php-fpm: prod
# -------------------------------------------------------------
# Tweaks
diff --git a/roles/webserver-legacy/php-sites/files/php-fpm-pool.conf b/roles/webserver-legacy/php-sites/files/php-fpm-pool.conf
new file mode 100644
--- /dev/null
+++ b/roles/webserver-legacy/php-sites/files/php-fpm-pool.conf
@@ -0,0 +1,28 @@
+; -------------------------------------------------------------
+; php-fpm pool configuration
+; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+; Project: Nasqueron
+; License: Trivial work, not eligible to copyright
+; Source file: roles/webserver-legacy/php-sites/files/php-fpm-pool.conf
+; -------------------------------------------------------------
+;
+; <auto-generated>
+; This file is managed by our rOPS SaltStack repository.
+;
+; Changes to this file may cause incorrect behavior
+; and will be lost if the state is redeployed.
+; </auto-generated>
+
+[{{ user }}]
+listen = /var/run/web/{{ domain }}/php-fpm-pool.sock
+listen.owner = {{ user }}
+listen.group = web
+listen.mode = 0666
+
+user = {{ user }}
+group = web
+
+pm = ondemand
+pm.max_children = 10
+pm.process_idle_timeout = 10s
+pm.max_requests = 200
diff --git a/roles/webserver-legacy/php-sites/files/php-fpm.conf b/roles/webserver-legacy/php-sites/files/php-fpm.conf
new file mode 100644
--- /dev/null
+++ b/roles/webserver-legacy/php-sites/files/php-fpm.conf
@@ -0,0 +1,32 @@
+; -------------------------------------------------------------
+; php-fpm insance configuration
+; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+; Project: Nasqueron
+; License: Trivial work, not eligible to copyright
+; Source file: roles/webserver-legacy/php-sites/files/php-fpm.conf
+; -------------------------------------------------------------
+;
+; <auto-generated>
+; This file is managed by our rOPS SaltStack repository.
+;
+; Changes to this file may cause incorrect behavior
+; and will be lost if the state is redeployed.
+; </auto-generated>
+
+; All relative paths in this configuration file are relative to PHP's install
+; prefix (/usr/local). This prefix can be dynamically changed by using the
+; '-p' argument from the command line.
+
+;;;;;;;;;;;;;;;;;;
+; Global Options ;
+;;;;;;;;;;;;;;;;;;
+
+[global]
+pid = /var/run/php-fpm-{{ instance }}.pid
+error_log = /var/log/php-fpm-{{ instance }}.log
+
+;;;;;;;;;;;;;;;;;;;;
+; Pool Definitions ;
+;;;;;;;;;;;;;;;;;;;;
+
+include=/usr/local/etc/php-fpm.d/{{ instance }}-pools/*.conf
diff --git a/roles/webserver-legacy/php-sites/files/rc/instances b/roles/webserver-legacy/php-sites/files/rc/instances
new file mode 100644
--- /dev/null
+++ b/roles/webserver-legacy/php-sites/files/rc/instances
@@ -0,0 +1,17 @@
+# -------------------------------------------------------------
+# php-fpm
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/webserver-legacy/php-sites/files/rc/instances
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+php_fpm_enable="YES"
+php_fpm_instances="{{ instances }}"
diff --git a/roles/webserver-legacy/php-sites/files/rc/per_instance b/roles/webserver-legacy/php-sites/files/rc/per_instance
new file mode 100644
--- /dev/null
+++ b/roles/webserver-legacy/php-sites/files/rc/per_instance
@@ -0,0 +1,19 @@
+# -------------------------------------------------------------
+# php-fpm
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/webserver-legacy/php-sites/files/rc/per_instance
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+php_fpm_{{ instance }}_enable="YES"
+{% if command %}
+php_fpm_{{ instance }}_command="{{ command }}"
+{% endif %}
diff --git a/roles/webserver-legacy/php-sites/files/rc/php-fpm b/roles/webserver-legacy/php-sites/files/rc/php-fpm
new file mode 100644
--- /dev/null
+++ b/roles/webserver-legacy/php-sites/files/rc/php-fpm
@@ -0,0 +1,125 @@
+#!/bin/sh
+
+# PROVIDE: php-fpm
+# REQUIRE: LOGIN
+# KEYWORD: shutdown
+
+# Add the following lines to /etc/rc.conf to enable php-fpm:
+# php_fpm_(instance_)?enable (bool): Set to "NO" by default.
+# Set it to "YES" to enable php-fpm.
+# php_fpm_(instance_)?umask (str): Custom PID file path and name.
+# Set it to to define umask before process start
+# php_fpm_(instance_)?command (str): Command to run
+# Default to /usr/local/sbin/php-fpm (port binary)
+# php_fpm_instances (str): Set to "" by default.
+# If defined, list of instances to enable
+
+. /etc/rc.subr
+
+name="php_fpm"
+rcvar=php_fpm_enable
+
+start_precmd="php_fpm_prestart"
+restart_precmd="php_fpm_checkconfig"
+reload_precmd="php_fpm_checkconfig"
+configtest_cmd="php_fpm_checkconfig"
+
+load_rc_config "$name"
+
+: ${php_fpm_enable="NO"}
+: ${php_fpm_umask=""}
+: ${php_fpm_command="/usr/local/sbin/php-fpm"}
+
+extra_commands="reload configtest logrotate"
+
+sig_stop="QUIT"
+sig_reload="USR2"
+logrotate_cmd="php_fpm_logrotate"
+
+# Instances logic has been forked from the MySQL port rc service code.
+if [ -n "$2" ]; then
+ instance="$2"
+ load_rc_config ${name}_${instance}
+ case "$php_fpm_instances" in
+ "$2 "*|*" $2 "*|*" $2"|"$2")
+ eval php_fpm_umask="\${php_fpm_${instance}_umask:-\"${php_fpm_umask}\"}"
+ eval php_fpm_command="\${php_fpm_${instance}_command:-\"${php_fpm_command}\"}"
+ php_fpm_pidfile="/var/run/php-fpm-${instance}.pid"
+ php_fpm_conf="/usr/local/etc/php-fpm.d/${instance}.conf"
+ php_fpm_name=${instance}
+ ;;
+ *)
+ err 1 "$2 not found in php_fpm_instances" ;;
+ esac
+else
+ if [ -n "${php_fpm_instances}" -a -n "$1" ]; then
+ for instance in ${php_fpm_instances}; do
+ eval _enable="\${php_fpm_${instance}_enable}"
+ case "${_enable:-${php_fpm_enable}}" in
+ [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+ continue
+ ;;
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+ ;;
+ *)
+ if [ -z "$_enable" ]; then
+ _var=php_fpm_enable
+ else
+ _var=php_fpm_${instance}_enable
+ fi
+ warn "Bad value" \
+ "'${_enable:-${php_fpm_enable}}'" \
+ "for ${_var}. " \
+ "Instance ${instance} skipped."
+ continue
+ ;;
+ esac
+ echo "===> php-fpm instance: ${instance}"
+ if /usr/local/etc/rc.d/php-fpm $1 ${instance}; then
+ success="${instance} ${success}"
+ else
+ failed="${instance} (${retcode}) ${failed}"
+ fi
+ done
+ exit 0
+ else
+ php_fpm_pidfile=/var/run/php-fpm.pid
+ php_fpm_conf=/usr/local/etc/php-fpm.conf
+ fi
+fi
+
+command=${php_fpm_command}
+pidfile="${php_fpm_pidfile}"
+
+required_files="${php_fpm_conf}"
+
+php_fpm_logrotate() {
+ if [ -z "$rc_pid" ]; then
+ _run_rc_notrunning
+ return 1
+ fi
+ echo "Rotating logs $name."
+ kill -USR1 $rc_pid
+}
+
+php_fpm_checkconfig()
+{
+ echo "Performing sanity check on php-fpm configuration:"
+ eval ${command} -t --fpm-config "${php_fpm_conf}"
+}
+
+php_fpm_prestart()
+{
+ php_fpm_checkconfig
+ checkconfig=$?
+ if [ $checkconfig -ne 0 ]; then
+ return $checkconfig
+ fi
+
+ if [ ! -z "$php_fpm_umask" ]; then
+ echo "Setting umask to: ${php_fpm_umask}"
+ umask $php_fpm_umask
+ fi
+}
+
+run_rc_command "$1"
diff --git a/roles/webserver-legacy/php-sites/init.sls b/roles/webserver-legacy/php-sites/init.sls
--- a/roles/webserver-legacy/php-sites/init.sls
+++ b/roles/webserver-legacy/php-sites/init.sls
@@ -8,3 +8,4 @@
include:
- .account
- .files
+ - .php-fpm
diff --git a/roles/webserver-legacy/php-sites/php-fpm.sls b/roles/webserver-legacy/php-sites/php-fpm.sls
new file mode 100644
--- /dev/null
+++ b/roles/webserver-legacy/php-sites/php-fpm.sls
@@ -0,0 +1,81 @@
+# -------------------------------------------------------------
+# Salt — Provision PHP websites — php-fpm pools
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+{% from "map.jinja" import dirs with context %}
+
+# -------------------------------------------------------------
+# Configuration : instances
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{% for instance, config in pillar['php_fpm_instances'].iteritems() %}
+
+php-fpm_config_{{ instance }}:
+ file.managed:
+ - name: {{ dirs.etc }}/php-fpm.d/{{ instance }}.conf
+ - source: salt://roles/webserver-legacy/php-sites/files/php-fpm.conf
+ - template: jinja
+ - context:
+ instance: {{ instance }}
+
+{{ dirs.etc }}/php-fpm.d/{{ instance }}-pools:
+ file.directory
+
+{% endfor %}
+
+# -------------------------------------------------------------
+# Configuration : pools
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{% for domain, site in pillar['web_php_sites'].iteritems() %}
+
+php-fpm_pool_{{ site['user'] }}:
+ file.managed:
+ - name: {{ dirs.etc }}/php-fpm.d/prod-pools/{{ site['user'] }}.conf
+ - source: salt://roles/webserver-legacy/php-sites/files/php-fpm-pool.conf
+ - template: jinja
+ - context:
+ domain: {{ domain }}
+ user: {{ site['user' ]}}
+
+{% endfor %}
+
+# -------------------------------------------------------------
+# Service
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{% if grains['os'] == 'FreeBSD' %}
+
+{% set instances = " ".join(pillar['php_fpm_instances'].keys()) %}
+
+# roles/webserver-legacy/php-sites/files/rc/php-fpm
+
+/usr/local/etc/rc.d/php-fpm:
+ file.managed:
+ - source: salt://roles/webserver-legacy/php-sites/files/rc/php-fpm
+ - mode: 755
+
+/etc/rc.conf.d/php_fpm:
+ file.directory
+
+/etc/rc.conf.d/php_fpm/instances:
+ file.managed:
+ - source: salt://roles/webserver-legacy/php-sites/files/rc/instances
+ - template: jinja
+ - context:
+ instances: {{ instances }}
+
+{% for instance, config in pillar['php_fpm_instances'].iteritems() %}
+/etc/rc.conf.d/php_fpm/{{ instance }}:
+ file.managed:
+ - source: salt://roles/webserver-legacy/php-sites/files/rc/per_instance
+ - template: jinja
+ - context:
+ instance: {{ instance }}
+ command: {{ config['command'] | default('') }}
+{% endfor %}
+
+{% endif %}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 16:26 (1 h, 30 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259424
Default Alt Text
D1249.id3210.diff (11 KB)
Attached To
Mode
D1249: Provision php-fpm pools to legacy web server
Attached
Detach File
Event Timeline
Log In to Comment