From b3e64eb60080b9ccc162812070c15bfbfa0243d1 Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Sat, 25 Jul 2015 11:39:50 +0200 Subject: [PATCH 1/2] Add hhvm support to php ng formula --- php/ng/hhvm/config.sls | 16 ++++++++++++++++ php/ng/hhvm/init.sls | 23 +++++++++++++++++++++++ php/ng/hhvm/install.sls | 2 ++ php/ng/hhvm/repo.sls | 19 +++++++++++++++++++ php/ng/hhvm/service.sls | 19 +++++++++++++++++++ php/ng/map.jinja | 28 ++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 php/ng/hhvm/config.sls create mode 100644 php/ng/hhvm/init.sls create mode 100644 php/ng/hhvm/install.sls create mode 100644 php/ng/hhvm/repo.sls create mode 100644 php/ng/hhvm/service.sls diff --git a/php/ng/hhvm/config.sls b/php/ng/hhvm/config.sls new file mode 100644 index 0000000..095bb5c --- /dev/null +++ b/php/ng/hhvm/config.sls @@ -0,0 +1,16 @@ +# Manages the php-hhvm main ini file +{% from "php/ng/map.jinja" import php with context %} +{% from "php/ng/ini.jinja" import php_ini %} + +{% set ini_settings = php.ini.defaults %} +{% do ini_settings.update(php.hhvm.config.ini.settings) %} + +{% set conf_settings = php.lookup.hhvm.defaults %} +{% do conf_settings.update(php.hhvm.config.conf.settings) %} + +php_hhvm_ini_config: + {{ php_ini(php.lookup.hhvm.ini, php.hhvm.config.ini.opts, ini_settings) }} + +php_hhvm_conf_config: + {{ php_ini(php.lookup.hhvm.conf, php.hhvm.config.conf.opts, conf_settings) }} + diff --git a/php/ng/hhvm/init.sls b/php/ng/hhvm/init.sls new file mode 100644 index 0000000..deea0f9 --- /dev/null +++ b/php/ng/hhvm/init.sls @@ -0,0 +1,23 @@ +# Meta-state to fully install php.hhvm + +include: + - php.ng.hhvm.repo + - php.ng.hhvm.config + - php.ng.hhvm.service + +extend: + php_hhvm_service: + service: + - watch: + - file: php_hhvm_ini_cnfig + - file: php_hhvm_conf_config + - require: + - sls: php.ng.hhvm.config + php_hhvm_ini_config: + file: + - require: + - pkg: php_install_hhvm + php_hhvm_conf_config: + file: + - require: + - pkg: php_install_hhvm diff --git a/php/ng/hhvm/install.sls b/php/ng/hhvm/install.sls new file mode 100644 index 0000000..1c1b277 --- /dev/null +++ b/php/ng/hhvm/install.sls @@ -0,0 +1,2 @@ +{% set state = 'hhvm' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/hhvm/repo.sls b/php/ng/hhvm/repo.sls new file mode 100644 index 0000000..fa790a0 --- /dev/null +++ b/php/ng/hhvm/repo.sls @@ -0,0 +1,19 @@ +# Manages the php-hhvm service. +{% from "php/ng/map.jinja" import php with context %} + +include: + - php.ng.hhvm.install + + +{% if salt['grains.get']('os_family') == 'Debian' -%} + +hhvm_repo: + pkgrepo.managed: + - name: deb http://dl.hhvm.com/{{ salt['grains.get']('os')|lower }} {{ salt['grains.get']('oscodename')}} main + - file: /etc/apt/sources.list.d/hhvm.list + - keyid: 0x5a16e7281be7a449 + - keyserver: keyserver.ubuntu.com + - refresh_db: True + - require_in: + - pkg: php_install_hhvm +{%- endif %} diff --git a/php/ng/hhvm/service.sls b/php/ng/hhvm/service.sls new file mode 100644 index 0000000..d7bcce9 --- /dev/null +++ b/php/ng/hhvm/service.sls @@ -0,0 +1,19 @@ +# Manages the php-hhvm service. +{% from "php/ng/map.jinja" import php with context %} +{% from "php/ng/macro.jinja" import sls_block %} + +{% set service_function = {True:'running', False:'dead'}.get(php.hhvm.service.enabled) %} + +include: + - php.ng.hhvm.install + +php_hhvm_service: + service.{{ service_function }}: + {{ sls_block(php.hhvm.service.opts) }} + - name: {{ php.lookup.hhvm.service }} + - enable: {{ php.hhvm.service.enabled }} + - require: + - sls: php.ng.hhvm.install + - watch: + - pkg: php_install_hhvm + diff --git a/php/ng/map.jinja b/php/ng/map.jinja index b540bc8..6e30cca 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -11,6 +11,7 @@ 'apache2': 'libapache2-mod-php5', 'curl': 'php5-curl', 'fpm': 'php5-fpm', + 'hhvm': 'hhvm', 'gd': 'php5-gd', 'gmp': 'php5-gmp', 'geoip': 'php5-geoip', @@ -50,6 +51,17 @@ ('include', '/etc/php5/fpm/pool.d/*.conf'), ]), }, + 'hhvm': { + 'conf': '/etc/hhvm/server.ini', + 'ini': '/etc/hhvm/php.ini', + 'service': 'hhvm', + 'defaults': odict([ + ('global', odict([ + ('pid', '/var/run/hhvm.pid'), + ('error_log', '/var/log/hhvm.log'), + ])), + ]), + }, 'cli': { 'ini': '/etc/php5/cli/php.ini', }, @@ -198,6 +210,22 @@ }, 'pools': {}, }, + 'hhvm': { + 'service': { + 'enabled': True, + 'opts': {}, + }, + 'config': { + 'ini': { + 'opts': {}, + 'settings': {}, + }, + 'conf': { + 'opts': {}, + 'settings': {}, + }, + }, + }, 'cli': { 'ini': { 'opts': {}, From f5c967fb6cbd0e7e189743b8c0ff203f13c19be5 Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Sat, 25 Jul 2015 22:15:28 +0200 Subject: [PATCH 2/2] Improve config file handling hhvm. In order to reuse the default structure of this formula I changed the config a little bit to configure hhvm files. --- README.rst | 25 +++++++++++++++++++++++++ php/ng/hhvm/config.sls | 12 ++++++------ php/ng/hhvm/init.sls | 2 +- php/ng/map.jinja | 29 +++++++++++++++++++++-------- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index 5bbfd83..d764a13 100644 --- a/README.rst +++ b/README.rst @@ -270,6 +270,31 @@ Manages php-fpm pool config files. Manages the php-fpm service. +``php.ng.hhvm`` +--------------- + +Meta-state that combines php.ng.hhvm states + +``php.ng.hhvm.config`` +---------------------- + +Manages the php-hhvm config files + +``php.ng.hhvm.install`` +----------------------- + +Installs the php-hhvm package + +``php.ng.hhvm.repo`` +-------------------- + +Configures the hhvm repo for debian/ubuntu + +``php.ng.hhvm.service`` +----------------------- + +Manages the php-hhvm service. + ``php.ng.gd`` ------------- diff --git a/php/ng/hhvm/config.sls b/php/ng/hhvm/config.sls index 095bb5c..f257a6f 100644 --- a/php/ng/hhvm/config.sls +++ b/php/ng/hhvm/config.sls @@ -2,15 +2,15 @@ {% from "php/ng/map.jinja" import php with context %} {% from "php/ng/ini.jinja" import php_ini %} -{% set ini_settings = php.ini.defaults %} -{% do ini_settings.update(php.hhvm.config.ini.settings) %} +{% set server_settings = php.lookup.hhvm.server %} +{% do server_settings.update(php.hhvm.config.server.settings) %} -{% set conf_settings = php.lookup.hhvm.defaults %} -{% do conf_settings.update(php.hhvm.config.conf.settings) %} +{% set php_settings = php.lookup.hhvm.php %} +{% do php_settings.update(php.hhvm.config.php.settings) %} php_hhvm_ini_config: - {{ php_ini(php.lookup.hhvm.ini, php.hhvm.config.ini.opts, ini_settings) }} + {{ php_ini(php.lookup.hhvm.conf, php.hhvm.config.server.opts, server_settings) }} php_hhvm_conf_config: - {{ php_ini(php.lookup.hhvm.conf, php.hhvm.config.conf.opts, conf_settings) }} + {{ php_ini(php.lookup.hhvm.ini, php.hhvm.config.php.opts, php_settings) }} diff --git a/php/ng/hhvm/init.sls b/php/ng/hhvm/init.sls index deea0f9..080edb6 100644 --- a/php/ng/hhvm/init.sls +++ b/php/ng/hhvm/init.sls @@ -9,7 +9,7 @@ extend: php_hhvm_service: service: - watch: - - file: php_hhvm_ini_cnfig + - file: php_hhvm_ini_config - file: php_hhvm_conf_config - require: - sls: php.ng.hhvm.config diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 6e30cca..0ae6188 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -55,12 +55,25 @@ 'conf': '/etc/hhvm/server.ini', 'ini': '/etc/hhvm/php.ini', 'service': 'hhvm', - 'defaults': odict([ - ('global', odict([ - ('pid', '/var/run/hhvm.pid'), - ('error_log', '/var/log/hhvm.log'), - ])), - ]), + 'defaults': {}, + 'server': odict([ + ('pid', '/var/run/hhvm.pid'), + ('hhvm.server.port', '9000'), + ('hhvm.server.type', 'fastcgi'), + ('hhvm.server.default_document', 'index.php'), + ('hhvm.log.use_log_file', 'true'), + ('hhvm.log.file', '/var/log/hhvm/error.log'), + ('hhvm.repo.central.path', '/var/run/hhvm/hhvm.hhbc'), + ]), + 'php': odict([ + ('session.save_handler', 'files'), + ('session.save_path', '/var/lib/hhvm/sessions'), + ('session.gc_maxlifetime', '1440'), + ('hhvm.log.level', 'Warning'), + ('hhvm.log.always_log_unhandled_exceptions', 'true'), + ('hhvm.log.runtime_error_reporting_level', '8191'), + ('hhvm.mysql.typed_results', 'false'), + ]), }, 'cli': { 'ini': '/etc/php5/cli/php.ini', @@ -216,11 +229,11 @@ 'opts': {}, }, 'config': { - 'ini': { + 'server': { 'opts': {}, 'settings': {}, }, - 'conf': { + 'php': { 'opts': {}, 'settings': {}, },