server_maint 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +12 -0
- data/lib/cookbooks/apt/.gitignore +4 -0
- data/lib/cookbooks/apt/CHANGELOG.md +25 -0
- data/lib/cookbooks/apt/CONTRIBUTING +29 -0
- data/lib/cookbooks/apt/Gemfile +3 -0
- data/lib/cookbooks/apt/LICENSE +201 -0
- data/lib/cookbooks/apt/README.md +193 -0
- data/lib/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
- data/lib/cookbooks/apt/metadata.rb +13 -0
- data/lib/cookbooks/apt/providers/preference.rb +52 -0
- data/lib/cookbooks/apt/providers/repository.rb +128 -0
- data/lib/cookbooks/apt/recipes/cacher-client.rb +54 -0
- data/lib/cookbooks/apt/recipes/cacher-ng.rb +30 -0
- data/lib/cookbooks/apt/recipes/default.rb +68 -0
- data/lib/cookbooks/apt/resources/preference.rb +29 -0
- data/lib/cookbooks/apt/resources/repository.rb +39 -0
- data/lib/cookbooks/apt/test/kitchen/Kitchenfile +3 -0
- data/lib/cookbooks/php/.gitignore +4 -0
- data/lib/cookbooks/php/CHANGELOG.md +14 -0
- data/lib/cookbooks/php/CONTRIBUTING +29 -0
- data/lib/cookbooks/php/Gemfile +3 -0
- data/lib/cookbooks/php/LICENSE +201 -0
- data/lib/cookbooks/php/README.md +253 -0
- data/lib/cookbooks/php/attributes/default.rb +86 -0
- data/lib/cookbooks/php/metadata.rb +27 -0
- data/lib/cookbooks/php/providers/pear.rb +261 -0
- data/lib/cookbooks/php/providers/pear_channel.rb +90 -0
- data/lib/cookbooks/php/recipes/default.rb +31 -0
- data/lib/cookbooks/php/recipes/module_apc.rb +37 -0
- data/lib/cookbooks/php/recipes/module_curl.rb +29 -0
- data/lib/cookbooks/php/recipes/module_fileinfo.rb +29 -0
- data/lib/cookbooks/php/recipes/module_fpdf.rb +35 -0
- data/lib/cookbooks/php/recipes/module_gd.rb +32 -0
- data/lib/cookbooks/php/recipes/module_ldap.rb +32 -0
- data/lib/cookbooks/php/recipes/module_memcache.rb +37 -0
- data/lib/cookbooks/php/recipes/module_mysql.rb +32 -0
- data/lib/cookbooks/php/recipes/module_pgsql.rb +32 -0
- data/lib/cookbooks/php/recipes/module_sqlite3.rb +30 -0
- data/lib/cookbooks/php/recipes/package.rb +43 -0
- data/lib/cookbooks/php/recipes/source.rb +79 -0
- data/lib/cookbooks/php/resources/pear.rb +30 -0
- data/lib/cookbooks/php/resources/pear_channel.rb +29 -0
- data/lib/cookbooks/php/templates/centos/php.ini.erb +1225 -0
- data/lib/cookbooks/php/templates/debian/php.ini.erb +1857 -0
- data/lib/cookbooks/php/templates/default/extension.ini.erb +7 -0
- data/lib/cookbooks/php/templates/default/php.ini.erb +1900 -0
- data/lib/cookbooks/php/templates/redhat/php.ini.erb +1225 -0
- data/lib/cookbooks/php/templates/ubuntu/php.ini.erb +1857 -0
- data/lib/cookbooks/php/test/kitchen/Kitchenfile +3 -0
- data/lib/cookbooks/php-fpm/.gitignore +1 -0
- data/lib/cookbooks/php-fpm/README.md +65 -0
- data/lib/cookbooks/php-fpm/metadata.rb +14 -0
- data/lib/cookbooks/php-fpm/recipes/default.rb +98 -0
- data/lib/cookbooks/yum/.gitignore +1 -0
- data/lib/cookbooks/yum/CHANGELOG.md +48 -0
- data/lib/cookbooks/yum/CONTRIBUTING +29 -0
- data/lib/cookbooks/yum/Gemfile +3 -0
- data/lib/cookbooks/yum/LICENSE +201 -0
- data/lib/cookbooks/yum/README.md +197 -0
- data/lib/cookbooks/yum/attributes/default.rb +37 -0
- data/lib/cookbooks/yum/metadata.rb +36 -0
- data/lib/cookbooks/yum/providers/key.rb +74 -0
- data/lib/cookbooks/yum/providers/repository.rb +111 -0
- data/lib/cookbooks/yum/recipes/default.rb +18 -0
- data/lib/cookbooks/yum/recipes/epel.rb +55 -0
- data/lib/cookbooks/yum/recipes/ius.rb +40 -0
- data/lib/cookbooks/yum/recipes/repoforge.rb +48 -0
- data/lib/cookbooks/yum/recipes/yum.rb +23 -0
- data/lib/cookbooks/yum/resources/key.rb +24 -0
- data/lib/cookbooks/yum/resources/repository.rb +38 -0
- data/lib/cookbooks/yum/templates/default/repo.erb +29 -0
- data/lib/cookbooks/yum/templates/default/yum-rhel5.conf.erb +33 -0
- data/lib/cookbooks/yum/templates/default/yum-rhel6.conf.erb +36 -0
- data/lib/cookbooks/yum/test/kitchen/Kitchenfile +23 -0
- data/lib/server_maint/version.rb +1 -1
- metadata +77 -4
@@ -0,0 +1,253 @@
|
|
1
|
+
Description
|
2
|
+
===========
|
3
|
+
|
4
|
+
Installs and configures PHP 5.3 and the PEAR package management system. Also includes LWRPs for managing PEAR (and PECL) packages along with PECL channels.
|
5
|
+
|
6
|
+
---
|
7
|
+
Requirements
|
8
|
+
============
|
9
|
+
|
10
|
+
Platform
|
11
|
+
--------
|
12
|
+
|
13
|
+
* Debian, Ubuntu
|
14
|
+
* CentOS, Red Hat, Fedora
|
15
|
+
|
16
|
+
Cookbooks
|
17
|
+
---------
|
18
|
+
|
19
|
+
* build-essential
|
20
|
+
* xml
|
21
|
+
* mysql
|
22
|
+
|
23
|
+
These cookbooks are only used when building PHP from source.
|
24
|
+
|
25
|
+
---
|
26
|
+
Attributes
|
27
|
+
==========
|
28
|
+
|
29
|
+
* `node['php']['install_method']` = method to install php with, default `package`.
|
30
|
+
* `node['php']['directives']` = Hash of directives and values to append
|
31
|
+
to `php.ini`, default `{}`.
|
32
|
+
|
33
|
+
The file also contains the following attribute types:
|
34
|
+
|
35
|
+
* platform specific locations and settings.
|
36
|
+
* source installation settings
|
37
|
+
|
38
|
+
---
|
39
|
+
Resource/Provider
|
40
|
+
=================
|
41
|
+
|
42
|
+
This cookbook includes LWRPs for managing:
|
43
|
+
|
44
|
+
* PEAR channels
|
45
|
+
* PEAR/PECL packages
|
46
|
+
|
47
|
+
`php_pear_channel`
|
48
|
+
------------------
|
49
|
+
|
50
|
+
[PEAR Channels](http://pear.php.net/manual/en/guide.users.commandline.channels.php) are alternative sources for PEAR packages. This LWRP provides and easy way to manage these channels.
|
51
|
+
|
52
|
+
# Actions
|
53
|
+
|
54
|
+
- :discover: Initialize a channel from its server.
|
55
|
+
- :add: Add a channel to the channel list, usually only used to add private channels. Public channels are usually added using the `:discover` action
|
56
|
+
- :update: Update an existing channel
|
57
|
+
- :remove: Remove a channel from the List
|
58
|
+
|
59
|
+
# Attribute Parameters
|
60
|
+
|
61
|
+
- channel_name: name attribute. The name of the channel to discover
|
62
|
+
- channel_xml: the channel.xml file of the channel you are adding
|
63
|
+
|
64
|
+
# Example
|
65
|
+
|
66
|
+
# discover the horde channel
|
67
|
+
php_pear_channel "pear.horde.org" do
|
68
|
+
action :discover
|
69
|
+
end
|
70
|
+
|
71
|
+
# download xml then add the symfony channel
|
72
|
+
remote_file "#{Chef::Config[:file_cache_path]}/symfony-channel.xml" do
|
73
|
+
source "http://pear.symfony-project.com/channel.xml"
|
74
|
+
mode 0644
|
75
|
+
end
|
76
|
+
php_pear_channel "symfony" do
|
77
|
+
channel_xml "#{Chef::Config[:file_cache_path]}/symfony-channel.xml"
|
78
|
+
action :add
|
79
|
+
end
|
80
|
+
|
81
|
+
# update the main pear channel
|
82
|
+
php_pear_channel 'pear.php.net' do
|
83
|
+
action :update
|
84
|
+
end
|
85
|
+
|
86
|
+
# update the main pecl channel
|
87
|
+
php_pear_channel 'pecl.php.net' do
|
88
|
+
action :update
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
`php_pear`
|
93
|
+
----------
|
94
|
+
|
95
|
+
[PEAR](http://pear.php.net/) is a framework and distribution system for reusable PHP components. [PECL](http://pecl.php.net/) is a repository for PHP Extensions. PECL contains C extensions for compiling into PHP. As C programs, PECL extensions run more efficiently than PEAR packages. PEARs and PECLs use the same packaging and distribution system. As such this LWRP is clever enough to abstract away the small differences and can be used for managing either. This LWRP also creates the proper module .ini file for each PECL extension at the correct location for each supported platform.
|
96
|
+
|
97
|
+
# Actions
|
98
|
+
|
99
|
+
- :install: Install a pear package - if version is provided, install that specific version
|
100
|
+
- :upgrade: Upgrade a pear package - if version is provided, upgrade to that specific version
|
101
|
+
- :remove: Remove a pear package
|
102
|
+
- :purge: Purge a pear package (this usually entails removing configuration files as well as the package itself). With pear packages this behaves the same as `:remove`
|
103
|
+
|
104
|
+
# Attribute Parameters
|
105
|
+
|
106
|
+
- package_name: name attribute. The name of the pear package to install
|
107
|
+
- version: the version of the pear package to install/upgrade. If no version is given latest is assumed.
|
108
|
+
- preferred_state: PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state
|
109
|
+
- directives: extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file
|
110
|
+
- zend_extensions: extension filenames which should be loaded with zend_extension.
|
111
|
+
- options: Add additional options to the underlying pear package command
|
112
|
+
|
113
|
+
|
114
|
+
# Example
|
115
|
+
|
116
|
+
# upgrade a pear
|
117
|
+
php_pear "XML_RPC" do
|
118
|
+
action :upgrade
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# install a specific version
|
123
|
+
php_pear "XML_RPC" do
|
124
|
+
version "1.5.4"
|
125
|
+
action :install
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
# install the mongodb pecl
|
130
|
+
php_pear "mongo" do
|
131
|
+
action :install
|
132
|
+
end
|
133
|
+
|
134
|
+
# install the xdebug pecl
|
135
|
+
php_pear "xdebug" do
|
136
|
+
# Specify that xdebug.so must be loaded as a zend extension
|
137
|
+
zend_extensions ['xdebug.so']
|
138
|
+
action :install
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
# install apc pecl with directives
|
143
|
+
php_pear "apc" do
|
144
|
+
action :install
|
145
|
+
directives(:shm_size => 128, :enable_cli => 1)
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# install the beta version of Horde_Url
|
150
|
+
# from the horde channel
|
151
|
+
hc = php_pear_channel "pear.horde.org" do
|
152
|
+
action :discover
|
153
|
+
end
|
154
|
+
php_pear "Horde_Url" do
|
155
|
+
preferred_state "beta"
|
156
|
+
channel hc.channel_name
|
157
|
+
action :install
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
# install the YAML pear from the symfony project
|
162
|
+
sc = php_pear_channel "pear.symfony-project.com" do
|
163
|
+
action :discover
|
164
|
+
end
|
165
|
+
php_pear "YAML" do
|
166
|
+
channel sc.channel_name
|
167
|
+
action :install
|
168
|
+
end
|
169
|
+
|
170
|
+
---
|
171
|
+
Recipes
|
172
|
+
=======
|
173
|
+
|
174
|
+
default
|
175
|
+
-------
|
176
|
+
|
177
|
+
Include the default recipe in a run list, to get `php`. By default `php` is installed from packages but this can be changed by using the `install_method` attribute.
|
178
|
+
|
179
|
+
package
|
180
|
+
-------
|
181
|
+
|
182
|
+
This recipe installs PHP from packages.
|
183
|
+
|
184
|
+
source
|
185
|
+
------
|
186
|
+
|
187
|
+
This recipe installs PHP from source.
|
188
|
+
|
189
|
+
---
|
190
|
+
Deprecated Recipes
|
191
|
+
==================
|
192
|
+
|
193
|
+
The following recipes are deprecated and will be removed from a future version of this cookbook.
|
194
|
+
|
195
|
+
* `module_apc`
|
196
|
+
* `module_curl`
|
197
|
+
* `module_fileinfo`
|
198
|
+
* `module_fpdf`
|
199
|
+
* `module_gd`
|
200
|
+
* `module_ldap`
|
201
|
+
* `module_memcache`
|
202
|
+
* `module_mysql`
|
203
|
+
* `module_pgsql`
|
204
|
+
* `module_sqlite3`
|
205
|
+
|
206
|
+
The installation of the php modules in these recipes can now be accomplished by installing from a native package or via the new php_pear LWRP. For example, the functionality of the `module_memcache` recipe can be enabled in the following ways:
|
207
|
+
|
208
|
+
# using apt
|
209
|
+
package "php5-memcache" do
|
210
|
+
action :install
|
211
|
+
end
|
212
|
+
|
213
|
+
# using pear LWRP
|
214
|
+
php_pear "memcache" do
|
215
|
+
action :install
|
216
|
+
end
|
217
|
+
|
218
|
+
---
|
219
|
+
Usage
|
220
|
+
=====
|
221
|
+
|
222
|
+
Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute with in a role:
|
223
|
+
|
224
|
+
name "php"
|
225
|
+
description "Install php from source"
|
226
|
+
override_attributes(
|
227
|
+
"php" => {
|
228
|
+
"install_method" => "source"
|
229
|
+
}
|
230
|
+
)
|
231
|
+
run_list(
|
232
|
+
"recipe[php]"
|
233
|
+
)
|
234
|
+
|
235
|
+
License and Author
|
236
|
+
==================
|
237
|
+
|
238
|
+
Author:: Seth Chisamore (<schisamo@opscode.com>)
|
239
|
+
Author:: Joshua Timberman (<joshua@opscode.com>)
|
240
|
+
|
241
|
+
Copyright:: 2011, Opscode, Inc
|
242
|
+
|
243
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
244
|
+
you may not use this file except in compliance with the License.
|
245
|
+
You may obtain a copy of the License at
|
246
|
+
|
247
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
248
|
+
|
249
|
+
Unless required by applicable law or agreed to in writing, software
|
250
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
251
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
252
|
+
See the License for the specific language governing permissions and
|
253
|
+
limitations under the License.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Cookbook Name:: php
|
4
|
+
# Attribute:: default
|
5
|
+
#
|
6
|
+
# Copyright 2011, Opscode, Inc.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
lib_dir = kernel['machine'] =~ /x86_64/ ? 'lib64' : 'lib'
|
22
|
+
|
23
|
+
default['php']['install_method'] = 'package'
|
24
|
+
default['php']['directives'] = {}
|
25
|
+
|
26
|
+
case node["platform_family"]
|
27
|
+
when "rhel", "fedora"
|
28
|
+
default['php']['conf_dir'] = '/etc'
|
29
|
+
default['php']['ext_conf_dir'] = '/etc/php.d'
|
30
|
+
default['php']['fpm_user'] = 'nobody'
|
31
|
+
default['php']['fpm_group'] = 'nobody'
|
32
|
+
default['php']['ext_dir'] = "/usr/#{lib_dir}/php/modules"
|
33
|
+
when "debian"
|
34
|
+
default['php']['conf_dir'] = '/etc/php5/cli'
|
35
|
+
default['php']['ext_conf_dir'] = '/etc/php5/conf.d'
|
36
|
+
default['php']['fpm_user'] = 'www-data'
|
37
|
+
default['php']['fpm_group'] = 'www-data'
|
38
|
+
else
|
39
|
+
default['php']['conf_dir'] = '/etc/php5/cli'
|
40
|
+
default['php']['ext_conf_dir'] = '/etc/php5/conf.d'
|
41
|
+
default['php']['fpm_user'] = 'www-data'
|
42
|
+
default['php']['fpm_group'] = 'www-data'
|
43
|
+
end
|
44
|
+
|
45
|
+
default['php']['url'] = 'http://us.php.net/distributions'
|
46
|
+
default['php']['version'] = '5.3.10'
|
47
|
+
default['php']['checksum'] = 'ee26ff003eaeaefb649735980d9ef1ffad3ea8c2836e6ad520de598da225eaab'
|
48
|
+
default['php']['prefix_dir'] = '/usr/local'
|
49
|
+
|
50
|
+
default['php']['configure_options'] = %W{--prefix=#{php['prefix_dir']}
|
51
|
+
--with-libdir=#{lib_dir}
|
52
|
+
--with-config-file-path=#{php['conf_dir']}
|
53
|
+
--with-config-file-scan-dir=#{php['ext_conf_dir']}
|
54
|
+
--with-pear
|
55
|
+
--enable-fpm
|
56
|
+
--with-fpm-user=#{php['fpm_user']}
|
57
|
+
--with-fpm-group=#{php['fpm_group']}
|
58
|
+
--with-zlib
|
59
|
+
--with-openssl
|
60
|
+
--with-kerberos
|
61
|
+
--with-bz2
|
62
|
+
--with-curl
|
63
|
+
--enable-ftp
|
64
|
+
--enable-zip
|
65
|
+
--enable-exif
|
66
|
+
--with-gd
|
67
|
+
--enable-gd-native-ttf
|
68
|
+
--with-gettext
|
69
|
+
--with-gmp
|
70
|
+
--with-mhash
|
71
|
+
--with-iconv
|
72
|
+
--with-imap
|
73
|
+
--with-imap-ssl
|
74
|
+
--enable-sockets
|
75
|
+
--enable-soap
|
76
|
+
--with-xmlrpc
|
77
|
+
--with-libevent-dir
|
78
|
+
--with-mcrypt
|
79
|
+
--enable-mbstring
|
80
|
+
--with-t1lib
|
81
|
+
--with-mysql
|
82
|
+
--with-mysqli=/usr/bin/mysql_config
|
83
|
+
--with-mysql-sock
|
84
|
+
--with-sqlite3
|
85
|
+
--with-pdo-mysql
|
86
|
+
--with-pdo-sqlite}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
maintainer "Opscode, Inc."
|
2
|
+
maintainer_email "cookbooks@opscode.com"
|
3
|
+
license "Apache 2.0"
|
4
|
+
description "Installs and maintains php and php modules"
|
5
|
+
version "1.1.0"
|
6
|
+
|
7
|
+
depends "build-essential"
|
8
|
+
depends "xml"
|
9
|
+
depends "mysql"
|
10
|
+
|
11
|
+
%w{ debian ubuntu centos redhat fedora scientific amazon }.each do |os|
|
12
|
+
supports os
|
13
|
+
end
|
14
|
+
|
15
|
+
recipe "php", "Installs php"
|
16
|
+
recipe "php::package", "Installs php using packages."
|
17
|
+
recipe "php::source", "Installs php from source."
|
18
|
+
recipe "php::module_apc", "Install the php5-apc package"
|
19
|
+
recipe "php::module_curl", "Install the php5-curl package"
|
20
|
+
recipe "php::module_fileinfo", "Install the php5-fileinfo package"
|
21
|
+
recipe "php::module_fpdf", "Install the php-fpdf package"
|
22
|
+
recipe "php::module_gd", "Install the php5-gd package"
|
23
|
+
recipe "php::module_ldap", "Install the php5-ldap package"
|
24
|
+
recipe "php::module_memcache", "Install the php5-memcache package"
|
25
|
+
recipe "php::module_mysql", "Install the php5-mysql package"
|
26
|
+
recipe "php::module_pgsql", "Install the php5-pgsql packag"
|
27
|
+
recipe "php::module_sqlite3", "Install the php5-sqlite3 package"
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore <schisamo@opscode.com>
|
3
|
+
# Cookbook Name:: php
|
4
|
+
# Provider:: pear_package
|
5
|
+
#
|
6
|
+
# Copyright:: 2011, Opscode, Inc <legal@opscode.com>
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'chef/mixin/shell_out'
|
22
|
+
require 'chef/mixin/language'
|
23
|
+
include Chef::Mixin::ShellOut
|
24
|
+
|
25
|
+
# the logic in all action methods mirror that of
|
26
|
+
# the Chef::Provider::Package which will make
|
27
|
+
# refactoring into core chef easy
|
28
|
+
|
29
|
+
action :install do
|
30
|
+
# If we specified a version, and it's not the current version, move to the specified version
|
31
|
+
if @new_resource.version != nil && @new_resource.version != @current_resource.version
|
32
|
+
install_version = @new_resource.version
|
33
|
+
# If it's not installed at all, install it
|
34
|
+
elsif @current_resource.version == nil
|
35
|
+
install_version = candidate_version
|
36
|
+
end
|
37
|
+
|
38
|
+
if install_version
|
39
|
+
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
|
40
|
+
status = install_package(@new_resource.package_name, install_version)
|
41
|
+
if status
|
42
|
+
new_resource.updated_by_last_action(true)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
action :upgrade do
|
48
|
+
if @current_resource.version != candidate_version
|
49
|
+
orig_version = @current_resource.version || "uninstalled"
|
50
|
+
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
|
51
|
+
status = upgrade_package(@new_resource.package_name, candidate_version)
|
52
|
+
if status
|
53
|
+
new_resource.updated_by_last_action(true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
action :remove do
|
59
|
+
if removing_package?
|
60
|
+
Chef::Log.info("Removing #{@new_resource}")
|
61
|
+
remove_package(@current_resource.package_name, @new_resource.version)
|
62
|
+
new_resource.updated_by_last_action(true)
|
63
|
+
else
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
action :purge do
|
68
|
+
if removing_package?
|
69
|
+
Chef::Log.info("Purging #{@new_resource}")
|
70
|
+
purge_package(@current_resource.package_name, @new_resource.version)
|
71
|
+
new_resource.updated_by_last_action(true)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def removing_package?
|
76
|
+
if @current_resource.version.nil?
|
77
|
+
false # nothing to remove
|
78
|
+
elsif @new_resource.version.nil?
|
79
|
+
true # remove any version of a package
|
80
|
+
elsif @new_resource.version == @current_resource.version
|
81
|
+
true # remove the version we have
|
82
|
+
else
|
83
|
+
false # we don't have the version we want to remove
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def expand_options(options)
|
88
|
+
options ? " #{options}" : ""
|
89
|
+
end
|
90
|
+
|
91
|
+
# these methods are the required overrides of
|
92
|
+
# a provider that extends from Chef::Provider::Package
|
93
|
+
# so refactoring into core Chef should be easy
|
94
|
+
|
95
|
+
def load_current_resource
|
96
|
+
@current_resource = Chef::Resource::PhpPear.new(@new_resource.name)
|
97
|
+
@current_resource.package_name(@new_resource.package_name)
|
98
|
+
@bin = 'pear'
|
99
|
+
if pecl?
|
100
|
+
Chef::Log.debug("#{@new_resource} smells like a pecl...installing package in Pecl mode.")
|
101
|
+
@bin = 'pecl'
|
102
|
+
end
|
103
|
+
Chef::Log.debug("#{@current_resource}: Installed version: #{current_installed_version} Candidate version: #{candidate_version}")
|
104
|
+
|
105
|
+
unless current_installed_version.nil?
|
106
|
+
@current_resource.version(current_installed_version)
|
107
|
+
Chef::Log.debug("Current version is #{@current_resource.version}") if @current_resource.version
|
108
|
+
end
|
109
|
+
@current_resource
|
110
|
+
end
|
111
|
+
|
112
|
+
def current_installed_version
|
113
|
+
@current_installed_version ||= begin
|
114
|
+
v = nil
|
115
|
+
version_check_cmd = "#{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} list#{expand_channel(can_haz(@new_resource, "channel"))}"
|
116
|
+
p = shell_out(version_check_cmd)
|
117
|
+
response = nil
|
118
|
+
if p.stdout =~ /\.?Installed packages/i
|
119
|
+
response = grep_for_version(p.stdout, @new_resource.package_name)
|
120
|
+
end
|
121
|
+
response
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def candidate_version
|
126
|
+
@candidate_version ||= begin
|
127
|
+
candidate_version_cmd = "#{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} search#{expand_channel(can_haz(@new_resource, "channel"))} #{@new_resource.package_name}"
|
128
|
+
p = shell_out(candidate_version_cmd)
|
129
|
+
response = nil
|
130
|
+
if p.stdout =~ /\.?Matched packages/i
|
131
|
+
response = grep_for_version(p.stdout, @new_resource.package_name)
|
132
|
+
end
|
133
|
+
response
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def install_package(name, version)
|
138
|
+
pear_shell_out("echo -e \"\\r\" | #{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} install -a#{expand_options(@new_resource.options)} #{prefix_channel(can_haz(@new_resource, "channel"))}#{name}-#{version}")
|
139
|
+
manage_pecl_ini(name, :create, can_haz(@new_resource, "directives"), can_haz(@new_resource, "zend_extensions")) if pecl?
|
140
|
+
end
|
141
|
+
|
142
|
+
def upgrade_package(name, version)
|
143
|
+
pear_shell_out("echo -e \"\\r\" | #{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} upgrade -a#{expand_options(@new_resource.options)} #{prefix_channel(can_haz(@new_resource, "channel"))}#{name}-#{version}")
|
144
|
+
manage_pecl_ini(name, :create, can_haz(@new_resource, "directives"), can_haz(@new_resource, "zend_extensions")) if pecl?
|
145
|
+
end
|
146
|
+
|
147
|
+
def remove_package(name, version)
|
148
|
+
command = "#{@bin} uninstall #{expand_options(@new_resource.options)} #{prefix_channel(can_haz(@new_resource, "channel"))}#{name}"
|
149
|
+
command << "-#{version}" if version and !version.empty?
|
150
|
+
pear_shell_out(command)
|
151
|
+
manage_pecl_ini(name, :delete) if pecl?
|
152
|
+
end
|
153
|
+
|
154
|
+
def pear_shell_out(command)
|
155
|
+
p = shell_out!(command)
|
156
|
+
# pear/pecl commands return a 0 on failures...we'll grep for it
|
157
|
+
if p.stdout.split("\n").last =~ /^ERROR:.+/i
|
158
|
+
p.invalid!
|
159
|
+
end
|
160
|
+
p
|
161
|
+
end
|
162
|
+
|
163
|
+
def purge_package(name, version)
|
164
|
+
remove_package(name, version)
|
165
|
+
end
|
166
|
+
|
167
|
+
def expand_channel(channel)
|
168
|
+
channel ? " -c #{channel}" : ""
|
169
|
+
end
|
170
|
+
|
171
|
+
def prefix_channel(channel)
|
172
|
+
channel ? "#{channel}/" : ""
|
173
|
+
end
|
174
|
+
|
175
|
+
def get_extension_dir()
|
176
|
+
@extension_dir ||= begin
|
177
|
+
p = shell_out("php-config --extension-dir")
|
178
|
+
p.stdout.strip
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_extension_files(name)
|
183
|
+
files = []
|
184
|
+
|
185
|
+
p = shell_out("#{@bin} list-files #{name}")
|
186
|
+
p.stdout.each_line.grep(/^src\s+.*\.so$/i).each do |line|
|
187
|
+
files << line.split[1]
|
188
|
+
end
|
189
|
+
|
190
|
+
files
|
191
|
+
end
|
192
|
+
|
193
|
+
def manage_pecl_ini(name, action, directives, zend_extensions)
|
194
|
+
ext_prefix = get_extension_dir()
|
195
|
+
ext_prefix << ::File::SEPARATOR if ext_prefix[-1].chr != ::File::SEPARATOR
|
196
|
+
|
197
|
+
files = get_extension_files(name)
|
198
|
+
|
199
|
+
extensions = Hash[ files.map { |filepath|
|
200
|
+
rel_file = filepath.clone
|
201
|
+
rel_file.slice! ext_prefix if rel_file.start_with? ext_prefix
|
202
|
+
|
203
|
+
zend = zend_extensions.include?(rel_file)
|
204
|
+
|
205
|
+
[ (zend ? filepath : rel_file) , zend ]
|
206
|
+
}]
|
207
|
+
|
208
|
+
template "#{node['php']['ext_conf_dir']}/#{name}.ini" do
|
209
|
+
source "extension.ini.erb"
|
210
|
+
cookbook "php"
|
211
|
+
owner "root"
|
212
|
+
group "root"
|
213
|
+
mode "0644"
|
214
|
+
variables(:name => name, :extensions => extensions, :directives => directives)
|
215
|
+
action action
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def grep_for_version(stdout, package)
|
220
|
+
v = nil
|
221
|
+
|
222
|
+
stdout.split(/\n/).grep(/^#{package}\s/i).each do |m|
|
223
|
+
# XML_RPC 1.5.4 stable
|
224
|
+
# mongo 1.1.4/(1.1.4 stable) 1.1.4 MongoDB database driver
|
225
|
+
# Horde_Url -n/a-/(1.0.0beta1 beta) Horde Url class
|
226
|
+
# Horde_Url 1.0.0beta1 (beta) 1.0.0beta1 Horde Url class
|
227
|
+
v = m.split(/\s+/)[1].strip
|
228
|
+
if v.split(/\//)[0] =~ /.\./
|
229
|
+
# 1.1.4/(1.1.4 stable)
|
230
|
+
v = v.split(/\//)[0]
|
231
|
+
else
|
232
|
+
# -n/a-/(1.0.0beta1 beta)
|
233
|
+
v = v.split(/(.*)\/\((.*)/).last.split(/\s/)[0]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
v
|
237
|
+
end
|
238
|
+
|
239
|
+
def pecl?
|
240
|
+
@pecl ||= begin
|
241
|
+
# search as a pear first since most 3rd party channels will report pears as pecls!
|
242
|
+
search_cmd = "pear -d preferred_state=#{can_haz(@new_resource, "preferred_state")} search#{expand_channel(can_haz(@new_resource, "channel"))} #{@new_resource.package_name}"
|
243
|
+
if shell_out(search_cmd).stdout =~ /\.?Matched packages/i
|
244
|
+
false
|
245
|
+
else
|
246
|
+
# fall back and search as a pecl
|
247
|
+
search_cmd = "pecl -d preferred_state=#{can_haz(@new_resource, "preferred_state")} search#{expand_channel(can_haz(@new_resource, "channel"))} #{@new_resource.package_name}"
|
248
|
+
if shell_out(search_cmd).stdout =~ /\.?Matched packages/i
|
249
|
+
true
|
250
|
+
else
|
251
|
+
false
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
# TODO remove when provider is moved into Chef core
|
258
|
+
# this allows PhpPear to work with Chef::Resource::Package
|
259
|
+
def can_haz(resource, attribute_name)
|
260
|
+
resource.respond_to?(attribute_name) ? resource.send(attribute_name) : nil
|
261
|
+
end
|