Page MenuHomePhabricator

Make /usr/bin/php a wrapper that picks the right PHP version on CI slaves
Closed, ResolvedPublic

Description

Most composer invoked things utilize env php so we probably can't control them via $PHP_BIN.

We should make /usr/bin/php be some wrapper shell script that figures out the right PHP version to use based on env variables, and then passes arguments onwards. Or something.

Event Timeline

Legoktm raised the priority of this task from to High.
Legoktm updated the task description. (Show Details)
Legoktm added subscribers: Legoktm, hashar.

On Debian systems, php is managed by the 'alternative` system. When we wanted to run tests with HHVM I have split the jobs so that Zend 5.3 runs on Precise and the HHVM jobs are directed to Trusty. On trusty host php is made to point to hhvm via:

modules/contint/manifests/hhvm.pp:

alternatives::select { 'php':
    path    => '/usr/bin/hhvm',
    require => Package['hhvm'],
}

The result on a Trusty instance:

$ readlink /usr/bin/php
/etc/alternatives/php
$ update-alternatives --list php
/usr/bin/hhvm
/usr/bin/php5
$ readlink /etc/alternatives/php
/usr/bin/hhvm
$ update-alternatives --query php
Name: php
Link: /usr/bin/php
Status: manual
Best: /usr/bin/php5
Value: /usr/bin/hhvm         <---- What is actually set

Alternative: /usr/bin/hhvm
Priority: 40

Alternative: /usr/bin/php5
Priority: 50

Since php is hardcoded in a bunch of places (usually via a shebang such as: #!/usr/bin/env php) we could:

  • ship our own php entry point that recognizes PHP_BIN and switch/case
  • mark that script has the alternative for php

Later, if we ever ship multiple Zend PHP version (i.e.: 5.3 + 5.5) we will be able to install them in parallel (eg: /opt/php/5.3 , /opt/php/5.5) and switch between them 'easily'.

Change 269109 had a related patch set uploaded (by Hashar):
(WIP) php flavored entry point (WIP)

https://gerrit.wikimedia.org/r/269109

https://gerrit.wikimedia.org/r/269109
Lame https://gerrit.wikimedia.org/r/269109 being a slave script bin/php:

#!/bin/bash

set -e
set -u

PHP_FLAVOR=${PHP_FLAVOR:-/usr/bin/env php}

$PHP_FLAVOR "$@"

Change 269109 merged by jenkins-bot:
Add bin/php wrapper entry point

https://gerrit.wikimedia.org/r/269109

Change 269370 had a related patch set uploaded (by Legoktm):
contint: Use slave-scripts/bin/php wrapper script

https://gerrit.wikimedia.org/r/269370

Legoktm lowered the priority of this task from High to Medium.Feb 9 2016, 12:04 PM

Change 269370 had a related patch set uploaded (by Legoktm):
contint: Use slave-scripts/bin/php wrapper script

https://gerrit.wikimedia.org/r/269370

I have cherry-picked this to the integration-puppetmaster, so lowering priority to normal. Leaving open until we get this merged into ops/puppet.

Still cause a death loop of doom T126327 (should merge that ticket):

8750 ?        S      0:00          \_ /bin/bash -xe /tmp/hudson7884178629744784487.sh
 8752 ?        S      0:00          |   \_ /bin/bash -eu /srv/deployment/integration/slave-scripts/bin/mw-install-mysql.sh
 8767 ?        S      0:00          |       \_ /bin/bash /usr/bin/php maintenance/install.php --confpath /mnt/jenkins-workspace/workspace/mediawiki-core-qunit/src --dbtype=mysql --dbserver=127.0.0.1:3306 --dbuser=jenkins_u2 --dbpass=pw_jenkins_u2 --dbname=jenkins_u2_mw --pass testpass TestWiki WikiAdmin
 8768 ?        S      0:00          |           \_ /bin/bash /usr/bin/php maintenance/install.php --confpath /mnt/jenkins-workspace/workspace/mediawiki-core-qunit/src --dbtype=mysql --dbserver=127.0.0.1:3306 --dbuser=jenkins_u2 --dbpass=pw_jenkins_u2 --dbname=jenkins_u2_mw --pass testpass TestWiki WikiAdmin
 8769 ?        S      0:00          |               \_ /bin/bash /usr/bin/php maintenance/install.php --confpath /mnt/jenkins-workspace/workspace/mediawiki-core-qunit/src --dbtype=mysql --dbserver=127.0.0.1:3306 --dbuser=jenkins_u2 --dbpass=pw_jenkins_u2 --dbname=jenkins_u2_mw --pass testpass TestWiki WikiAdmin
 8770 ?        S      0:00          |                   \_ /bin/bash /usr/bin/php maintenance/install.php --confpath /mnt/jenkins-workspace/workspace/mediawiki-core-qunit/src --dbtype=mysql --dbserver=127.0.0.1:3306 --dbuser=jenkins_u2 --dbpass=pw_jenkins_u2 --dbname=jenkins_u2_mw --pass testpass TestWiki WikiAdmin

Change 269524 had a related patch set uploaded (by Legoktm):
Don't default to php for $PHP_BIN

https://gerrit.wikimedia.org/r/269524

Change 269527 had a related patch set uploaded (by Legoktm):
bin/php: Prevent against infinite recursion

https://gerrit.wikimedia.org/r/269527

Change 269524 merged by jenkins-bot:
Don't default to php for $PHP_BIN

https://gerrit.wikimedia.org/r/269524

Change 269527 merged by jenkins-bot:
bin/php: Prevent against infinite recursion

https://gerrit.wikimedia.org/r/269527

@Legoktm worked hard and committed to get that implemented and working properly. Today looks like everything is working fine and that will let us later easily switch between different PHP flavor on the same host.

Using Debian alternative system, php points to a slave-script /srv/deployment/integration/slave-scripts/bin/php . That one executes whatever is set in PHP_BIN env variable which we set to /usr/bin/php5 or /usr/bin/hhvm by injecting the parameter with Zuul.

Kudos @Legoktm.

hashar added a project: Blocked-on-Operations.

We still need the puppet patch https://gerrit.wikimedia.org/r/#/c/269370/ to be merged (it is cherry picked on integration puppet master though). So reopening this task until it is reviewed/merged by SRE.

Change 269370 merged by Dzahn:
contint: Use slave-scripts/bin/php wrapper script

https://gerrit.wikimedia.org/r/269370

Change 285934 had a related patch set uploaded (by Hashar):
dib: add /usr/bin/php wrapper

https://gerrit.wikimedia.org/r/285934

Change 285934 merged by jenkins-bot:
dib: add /usr/bin/php wrapper

https://gerrit.wikimedia.org/r/285934

contint::php requires contint::slave_scripts and that ends up causing:

Error: Duplicate declaration: Git::Clone[jenkins CI slave scripts] is already declared in file /opt/git/integration/config/dib/puppet/ciimage.pp:33; cannot redeclare at /puppet/modules/contint/manifests/slave_scripts.pp:18 on node ci-trusty-wikimedia-1461845395.eqiad.wmflabs

Since I copy pasted the cloning of slave scripts in the dib puppet manifest :D

Change 285935 had a related patch set uploaded (by Hashar):
dib: we can now use contint::slave_scripts

https://gerrit.wikimedia.org/r/285935

Change 285935 merged by jenkins-bot:
dib: we can now use contint::slave_scripts

https://gerrit.wikimedia.org/r/285935

On a Trusty instance:

$ readlink -f `which php`
/srv/deployment/integration/slave-scripts/bin/php

Mentioned in SAL [2016-04-28T12:42:17Z] <hashar> Rebuild Nodepool Trusty instance to include the PHP wrapper script T126211