├── .gitignore ├── .kitchen.docker.yml ├── .kitchen.vagrant.yml ├── .rubocop.yml ├── .travis.yml ├── Berksfile ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── attributes ├── default.rb └── php.rb ├── libraries ├── blackfire_collector_mock.rb └── blackfire_versions_helper.rb ├── metadata.rb ├── recipes ├── agent.rb ├── default.rb ├── mock.rb ├── php.rb └── repository.rb ├── spec └── default_spec.rb ├── templates └── default │ ├── agent.erb │ └── blackfire.ini.erb └── test └── integration ├── default └── serverspec │ └── install_spec.rb └── docker └── serverspec └── install_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .kitchen 2 | .kitchen.yml 3 | Gemfile.lock 4 | Berksfile.lock 5 | /vendor 6 | /bin 7 | -------------------------------------------------------------------------------- /.kitchen.docker.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: docker 4 | 5 | platforms: 6 | - name: debian-6 7 | driver_config: 8 | image: chef/debian-6 9 | platform: debian 10 | require_chef_omnibus: false 11 | - name: debian-7 12 | driver_config: 13 | image: chef/debian-7 14 | platform: debian 15 | require_chef_omnibus: false 16 | - name: ubuntu-12.04 17 | driver_config: 18 | image: chef/ubuntu-12.04 19 | platform: ubuntu 20 | require_chef_omnibus: false 21 | - name: ubuntu-14.04 22 | driver_config: 23 | image: chef/ubuntu-14.04 24 | platform: ubuntu 25 | require_chef_omnibus: false 26 | - name: centos-6.4 27 | driver_config: 28 | image: chef/centos-6 29 | platform: centos 30 | require_chef_omnibus: false 31 | 32 | suites: 33 | - name: docker 34 | run_list: 35 | - recipe[apt] 36 | - recipe[blackfire::mock] 37 | - recipe[blackfire] 38 | attributes: 39 | blackfire: 40 | agent: 41 | collector: 'http://127.0.0.1:8780' 42 | server_id: 'foo' 43 | server_token: 'bar' 44 | restart_mode: 'immediately' 45 | -------------------------------------------------------------------------------- /.kitchen.vagrant.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | platforms: 6 | - name: debian-7.6 7 | driver_config: 8 | box: chef/debian-7.6 9 | - name: ubuntu-14.04 10 | - name: centos-6.4 11 | - name: fedora-20 12 | 13 | suites: 14 | - name: default 15 | run_list: 16 | - recipe[apt] 17 | - recipe[blackfire::mock] 18 | - recipe[blackfire] 19 | attributes: 20 | blackfire: 21 | agent: 22 | collector: 'http://127.0.0.1:8780' 23 | server_id: 'foo' 24 | server_token: 'bar' 25 | restart_mode: 'immediately' 26 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | Documentation: 2 | Enabled: false 3 | 4 | LineLength: 5 | Enabled: false 6 | 7 | Style/ExtraSpacing: 8 | Enabled: false 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: ruby 3 | rvm: 4 | - 2.2.0 5 | bundler_args: --without development --without kitchen_vagrant 6 | cache: bundler 7 | before_install: 8 | - 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc' 9 | gemfile: 10 | - Gemfile 11 | script: 12 | - bundle exec rake travis 13 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'apt' 7 | end 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG for blackfire cookbook 2 | 3 | This file is used to list changes made in each version of blackfire cookbook. 4 | 5 | ## 2.4.0: 6 | 7 | * Use HTTPS for packages repository 8 | 9 | ## 2.3.0: 10 | 11 | * Remove unused blackfire.agent_timeout setting 12 | 13 | ## 2.2.0: 14 | 15 | * Update gpg key URL 16 | * Update copyright holder 17 | 18 | ## 2.1.0: 19 | 20 | * Add support for Amazon Linux 21 | 22 | ## 2.0.2: 23 | 24 | * Prevent agent restart when no server credentials are provided 25 | * Fix typo in generated agent configuration 26 | * Fix PHP server token documentation 27 | 28 | ## 2.0.1: 29 | 30 | * Fix missing probe credentials config 31 | * Force Blackfire repositories update on run 32 | 33 | ## 2.0.0: 34 | 35 | * Initial open-source release of blackfire cookbook 36 | * Added tests 37 | * Use Blackfire.io's API to retrieve versions 38 | * Added support for redhat based distributions 39 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | ruby '2.2.0' 4 | 5 | gem 'foodcritic' 6 | gem 'rubocop' 7 | gem 'rake' 8 | 9 | group :development do 10 | gem 'chefspec' 11 | gem 'berkshelf' 12 | gem 'test-kitchen' 13 | gem 'kitchen-vagrant' 14 | gem 'kitchen-docker' 15 | end 16 | 17 | group :deployment do 18 | gem 'stove' 19 | end 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2016 Blackfire.io 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Blackfire Cookbook 2 | =========================== 3 | 4 | This cookbook installs and configures the blackfire stack. 5 | 6 | Requirements 7 | ------------ 8 | 9 | #### Platform 10 | * Ubuntu (10.04/11.04/12.04/13.04/14.04) 11 | * Debian (6.0/7.0) 12 | * RedHat Based (CentOS 6.4 and Fedora 20 tested, others should work) 13 | 14 | #### cookbooks 15 | - apt 16 | - yum 17 | 18 | Attributes 19 | ---------- 20 | 21 | The following attributes are available to affect the installation/configuration of the Backfire stack 22 | 23 | #### blackfire::default 24 | 25 | * `node['blackfire']['agent']['version']` - Sets which version of the agent to install. Default last version. 26 | * `node['blackfire']['agent']['server_id']` - Sets the Server ID to use for the agent (See https://blackfire.io/account/agents) 27 | * `node['blackfire']['agent']['server_token']` - Sets the Server Token to use for the agent (See https://blackfire.io/account/agents) 28 | * `node['blackfire']['agent']['log_level']` - Sets the logging level for the agent. Default 1 29 | * `node['blackfire']['agent']['log_file']` - Sets where the agent write logs. Default "stderr" 30 | * `node['blackfire']['agent']['socket']` - Sets where the socket the agent will listen to. Default "unix:///var/run/blackfire/agent.sock" 31 | 32 | #### blackfire::php 33 | * `node['blackfire']['php']['version']` - Sets which version of the PHP extension will be installed. Default last version. 34 | * `node['blackfire']['php']['log_level']` - Sets the logging level for the PHP extension. 35 | * `node['blackfire']['php']['log_file']` - Sets where the PHP extension write logs. 36 | * `node['blackfire']['php']['ini_path']` - Sets where the PHP configuration will be written. 37 | * `node['blackfire']['php']['server_id']` - Sets the Server ID to use for probe fine-grained configuration (See https://blackfire.io/doc/configuration#probe-configuration) 38 | * `node['blackfire']['php']['server_token']` - Sets the Server Token to use for probe fine-grained configuration (See https://blackfire.io/doc/configuration#probe-configuration) 39 | 40 | Usage 41 | ----- 42 | #### blackfire::default 43 | Add agent Server ID and token and include `blackfire` in your node's `run_list`: 44 | 45 | ```json 46 | { 47 | "name":"my_node", 48 | "run_list": [ 49 | "recipe[blackfire]" 50 | ], 51 | "blackfire": { 52 | "agent": { 53 | "server_id": "my-agent-server-id", 54 | "server_token": "my-agent-server-token" 55 | } 56 | } 57 | } 58 | ``` 59 | 60 | #### blackfire::agent 61 | 62 | Used if you wish to install only the agent. 63 | 64 | #### blackfire::php 65 | 66 | Used if you wish to install only the PHP extension. 67 | 68 | ### Note about blackfire::php 69 | 70 | This cookbook makes no assumption about the webserver you use. 71 | 72 | Therefore this is *your* responsability to write a wrapper and notify your 73 | webserver (ie. Apache or php5-fpm) for reload/restart or subscribe the good 74 | resources. 75 | 76 | You can obtain futher informations on wrapper cookbooks here: 77 | https://www.getchef.com/blog/2013/12/03/doing-wrapper-cookbooks-right/ 78 | 79 | One way to do that (maybe the best to avoid disturbing logs messages): 80 | 81 | ```ruby 82 | include_recipe "blackfire" 83 | 84 | begin 85 | r = resources(:ruby_block => "blackfire-php-restart-webserver") 86 | r.block do 87 | end 88 | r.notifies :reload, "service[php5-fpm]" 89 | rescue Chef::Exceptions::ResourceNotFound 90 | Chef::Log.warn 'could not find resource "ruby_block[blackfire-php-restart-webserver]" to override!' 91 | end 92 | 93 | ``` 94 | 95 | Contributing 96 | ------------ 97 | 98 | 1. Fork the repository on Github 99 | 2. Create a named feature branch (like `add_component_x`) 100 | 3. Write you change 101 | 4. Write tests for your change (if applicable) 102 | 5. Run the tests, ensuring they all pass 103 | 6. Submit a Pull Request using Github 104 | 105 | Tests 106 | ----- 107 | 108 | Three test suites exist: 109 | 110 | - two using kitchen.ci (meant to be run localy by contributors) 111 | - one using rspec (meant to be run by travis, not localy). 112 | 113 | These test suites can be launched by using `rake integration:vagrant` or 114 | `rake integration:docker` for the kitchen.ci one and `rake travis` for rspec. 115 | 116 | Supermarket share 117 | ----------------- 118 | 119 | You need [stove](http://sethvargo.github.io/stove/) to publish the cookbook on 120 | supermarket. Once it's done use `rake publish` 121 | 122 | License and Authors 123 | ------------------- 124 | - Author:: Tugdual Saunier () 125 | 126 | ```text 127 | Copyright:: 2014-2016 Blackfire.io 128 | 129 | See LICENSE file 130 | ``` 131 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require './libraries/blackfire_versions_helper.rb' 2 | require './libraries/blackfire_collector_mock.rb' 3 | require 'rspec/core/rake_task' 4 | require 'stove/rake_task' 5 | require 'rubocop/rake_task' 6 | require 'foodcritic' 7 | require 'kitchen' 8 | 9 | # Style tests. Rubocop and Foodcritic 10 | namespace :style do 11 | desc 'Run Ruby style checks' 12 | RuboCop::RakeTask.new(:ruby) 13 | 14 | desc 'Run Chef style checks' 15 | FoodCritic::Rake::LintTask.new(:chef) 16 | end 17 | 18 | desc 'Run all style checks' 19 | task style: ['style:chef', 'style:ruby'] 20 | 21 | # Rspec and ChefSpec 22 | desc 'Run ChefSpec examples' 23 | RSpec::Core::RakeTask.new(:spec) 24 | 25 | # Integration tests. Kitchen.ci 26 | namespace :integration do 27 | desc 'Run Kitchen Tests with Vagrant' 28 | task :vagrant do 29 | Kitchen.logger = Kitchen.default_file_logger 30 | @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.vagrant.yml') 31 | Kitchen::Config.new(loader: @loader).instances.each do |instance| 32 | instance.test(:always) 33 | end 34 | end 35 | 36 | desc 'Run Kitchen Tests with Docker' 37 | task :docker do 38 | Kitchen.logger = Kitchen.default_file_logger 39 | @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.docker.yml') 40 | Kitchen::Config.new(loader: @loader).instances.each do |instance| 41 | instance.test(:always) 42 | end 43 | end 44 | 45 | desc 'Run Kitchen Tests with cloud plugins' 46 | task :cloud do 47 | run_kitchen = true 48 | if ENV['TRAVIS'] == 'true' && ENV['TRAVIS_PULL_REQUEST'] != 'false' 49 | run_kitchen = false 50 | end 51 | 52 | if run_kitchen 53 | Kitchen.logger = Kitchen.default_file_logger 54 | @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.cloud.yml') 55 | config = Kitchen::Config.new(loader: @loader) 56 | config.instances.each do |instance| 57 | instance.test(:always) 58 | end 59 | end 60 | end 61 | end 62 | 63 | namespace :blackfire do 64 | desc 'Show current blackfire versions packages' 65 | task :versions do 66 | puts "Agent: #{Blackfire::Versions.agent}" 67 | puts "Probe: #{Blackfire::Versions.probe}" 68 | end 69 | 70 | namespace :collector do 71 | desc 'Run the mock collector for debug purpose' 72 | task :mock do 73 | Blackfire::CollectorMock.run('http://localhost:8780') 74 | sleep(10) 75 | end 76 | end 77 | end 78 | 79 | desc 'Deploy to supermarket' 80 | Stove::RakeTask.new 81 | 82 | desc 'Run all tests on Travis' 83 | task travis: %w(style blackfire:versions spec) 84 | 85 | # Default 86 | task default: %w(style integration:vagrant) 87 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Tugdual Saunier () 3 | # Cookbook Name:: blackfire 4 | # Attributes:: default 5 | # 6 | # Copyright 2018, Blackfire 7 | # Copyright 2014-2015, SensioLabs 8 | 9 | default['blackfire']['repository'] = 'https://packages.blackfire.io' 10 | default['blackfire']['install_repository'] = true 11 | 12 | default['blackfire']['agent']['version'] = nil 13 | default['blackfire']['agent']['collector'] = 'https://blackfire.io' 14 | default['blackfire']['agent']['server_id'] = nil 15 | default['blackfire']['agent']['server_token'] = nil 16 | default['blackfire']['agent']['log_level'] = 1 17 | default['blackfire']['agent']['log_file'] = 'stderr' 18 | default['blackfire']['agent']['socket'] = 'unix:///var/run/blackfire/agent.sock' 19 | default['blackfire']['agent']['restart_mode'] = :delayed 20 | -------------------------------------------------------------------------------- /attributes/php.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Tugdual Saunier () 3 | # Cookbook Name:: blackfire 4 | # Attributes:: php 5 | # 6 | # Copyright 2018, Blackfire 7 | # Copyright 2014-2015, SensioLabs 8 | 9 | default['blackfire']['php']['version'] = nil 10 | default['blackfire']['php']['log_level'] = nil 11 | default['blackfire']['php']['log_file'] = nil 12 | default['blackfire']['php']['server_id'] = nil 13 | default['blackfire']['php']['server_token'] = nil 14 | 15 | if platform_family?('rhel', 'fedora', 'amazon') 16 | default['blackfire']['php']['ini_path'] = '/etc/php.d/zz-blackfire.ini' 17 | elsif platform?('debian') && node['platform_version'].to_f < 7.0 18 | default['blackfire']['php']['ini_path'] = '/etc/php5/conf.d/blackfire.ini' 19 | elsif platform?('ubuntu') && node['platform_version'].to_f <= 13.04 20 | default['blackfire']['php']['ini_path'] = '/etc/php5/conf.d/blackfire.ini' 21 | else 22 | default['blackfire']['php']['ini_path'] = '/etc/php5/mods-available/blackfire.ini' 23 | end 24 | -------------------------------------------------------------------------------- /libraries/blackfire_collector_mock.rb: -------------------------------------------------------------------------------- 1 | require 'socket' 2 | require 'uri' 3 | 4 | module Blackfire 5 | class CollectorMock 6 | @response = < node[cookbook_name]['agent']['ca_cert'], 24 | 'collector' => node[cookbook_name]['agent']['collector'], 25 | 'server_id' => node[cookbook_name]['agent']['server_id'], 26 | 'server_token' => node[cookbook_name]['agent']['server_token'], 27 | 'log_file' => node[cookbook_name]['agent']['log_file'], 28 | 'log_level' => node[cookbook_name]['agent']['log_level'], 29 | 'socket' => node[cookbook_name]['agent']['socket'], 30 | 'spec' => node[cookbook_name]['agent']['spec'] 31 | ) 32 | end 33 | 34 | service 'blackfire-agent' do 35 | not_if { node[cookbook_name]['agent']['server_id'].to_s.empty? } 36 | not_if { node[cookbook_name]['agent']['server_token'].to_s.empty? } 37 | supports status: true, start: true, stop: true, restart: true 38 | action [:enable] 39 | subscribes :restart, 'template[/etc/blackfire/agent]', node[cookbook_name]['agent']['restart_mode'] 40 | end 41 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: blackfire 3 | # Recipe:: default 4 | # 5 | # Copyright 2018, Blackfire 6 | # Copyright 2014-2015, SensioLabs 7 | # See LICENSE file 8 | # 9 | 10 | include_recipe "#{cookbook_name}::agent" 11 | include_recipe "#{cookbook_name}::php" 12 | -------------------------------------------------------------------------------- /recipes/mock.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: blackfire 3 | # Recipe:: mock 4 | # 5 | # Copyright 2018, Blackfire 6 | # Copyright 2014-2015, SensioLabs 7 | # See LICENSE file 8 | # 9 | 10 | ruby_block 'run Blackfire Collector Mock' do 11 | block do 12 | Blackfire::CollectorMock.run(node[cookbook_name]['agent']['collector']) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /recipes/php.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: blackfire 3 | # Recipe:: php 4 | # 5 | # Copyright 2018, Blackfire 6 | # Copyright 2014-2015, SensioLabs 7 | # See LICENSE file 8 | # 9 | 10 | include_recipe "#{cookbook_name}::repository" 11 | 12 | ruby_block 'blackfire-php-restart-webserver' do 13 | block do 14 | Chef::Log.warn "\033[31mBlackfire PHP extension has been updated.\033[0m" 15 | Chef::Log.warn "\033[31mPlease restart your WebServers or\033[0m" 16 | Chef::Log.warn "\033[31mconsider having your resources subscribing to\033[0m" 17 | Chef::Log.warn "\033[31mblackfire::php resources\033[0m" 18 | end 19 | action :nothing 20 | end 21 | 22 | probe_version = node[cookbook_name]['php']['version'] ? node[cookbook_name]['php']['version'] : Blackfire::Versions.probe(node) 23 | 24 | probe_version << '-1' if platform_family?('rhel', 'fedora', 'amazon') 25 | 26 | package 'blackfire-php' do 27 | version probe_version 28 | notifies :run, 'ruby_block[blackfire-php-restart-webserver]' 29 | end 30 | 31 | template node[cookbook_name]['php']['ini_path'] do 32 | source 'blackfire.ini.erb' 33 | variables( 34 | 'log_file' => node[cookbook_name]['php']['log_file'], 35 | 'log_level' => node[cookbook_name]['php']['log_level'], 36 | 'socket' => node[cookbook_name]['agent']['socket'], 37 | 'server_id' => node[cookbook_name]['php']['server_id'], 38 | 'server_token' => node[cookbook_name]['php']['server_token'] 39 | ) 40 | notifies :run, 'ruby_block[blackfire-php-restart-webserver]', :immediately 41 | end 42 | -------------------------------------------------------------------------------- /recipes/repository.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: blackfire 3 | # Recipe:: repository 4 | # 5 | # Copyright 2018, Blackfire 6 | # Copyright 2014-2015, SensioLabs 7 | # See LICENSE file 8 | # 9 | 10 | case node['platform_family'] 11 | when 'rhel', 'fedora', 'amazon' 12 | yum_repository 'blackfire' do 13 | description 'blackfire' 14 | baseurl "#{node[cookbook_name]['repository']}/fedora/$releasever/$basearch" 15 | gpgkey "#{node[cookbook_name]['repository']}/gpg.key" 16 | gpgcheck false 17 | sslverify true 18 | sslcacert '/etc/pki/tls/certs/ca-bundle.crt' 19 | action [:create, :makecache] 20 | only_if { node['blackfire']['install_repository'] } 21 | end 22 | else 23 | r = apt_repository 'blackfire' do 24 | uri "#{node[cookbook_name]['repository']}/#{node['platform']}" 25 | distribution 'any' 26 | key "#{node[cookbook_name]['repository']}/gpg.key" 27 | components ['main'] 28 | action :nothing 29 | only_if { node['blackfire']['install_repository'] } 30 | end 31 | r.run_action(:add) 32 | 33 | unless r.updated? 34 | execute 'blackfire repository update' do 35 | command "apt-get update -o Dir::Etc::sourcelist='sources.list.d/#{r.name}.list' -o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0'" 36 | ignore_failure true 37 | action :run 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /spec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | ChefSpec::Coverage.start! 5 | 6 | at_exit { ChefSpec::Coverage.report! } 7 | 8 | describe 'blackfire::default' do 9 | let(:chef_run) do 10 | ChefSpec::SoloRunner.converge('blackfire::default') 11 | end 12 | 13 | it 'Install blackfire repository' do 14 | expect(chef_run).to add_apt_repository('blackfire') 15 | end 16 | 17 | it 'Install blackfire packages' do 18 | expect(chef_run).to install_package('blackfire-agent') 19 | expect(chef_run).to install_package('blackfire-php') 20 | end 21 | 22 | it 'Creates config file' do 23 | expect(chef_run).to create_template('/etc/blackfire/agent') 24 | end 25 | 26 | it 'Enables blackfire agent' do 27 | expect(chef_run).to enable_service('blackfire-agent') 28 | expect(chef_run.template('/etc/blackfire/agent')).to notify('service[blackfire-agent]').to(:restart) 29 | end 30 | end 31 | 32 | describe 'blackfire::default without repository installation' do 33 | let(:chef_run) do 34 | ChefSpec::SoloRunner.new do |node| 35 | node.set['blackfire']['install_repository'] = false 36 | end.converge('blackfire::default') 37 | end 38 | 39 | it 'Install blackfire repository' do 40 | expect(chef_run).to_not add_apt_repository('blackfire') 41 | end 42 | 43 | it 'Install blackfire packages' do 44 | expect(chef_run).to install_package('blackfire-agent') 45 | expect(chef_run).to install_package('blackfire-php') 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /templates/default/agent.erb: -------------------------------------------------------------------------------- 1 | [blackfire] 2 | ; 3 | ; This is a configuration file for Blackfire's Agent. 4 | ; This file has been generated by Chef. 5 | ; Be careful, any changes could be overwritten 6 | ; 7 | 8 | ; 9 | ; setting: ca-cert 10 | ; desc : Sets the PEM encoded certificates 11 | ; default: 12 | ca-cert=<%= @ca_cert %> 13 | 14 | ; 15 | ; setting: collector 16 | ; desc : Sets the URL of Blackfire's data collector 17 | ; default: https://blackfire.io 18 | collector=<%= @collector %> 19 | 20 | ; 21 | ; setting: log-file 22 | ; desc : Sets the path of the log file. Use stderr to log to stderr 23 | ; default: stderr 24 | log-file=<%= @log_file %> 25 | 26 | ; 27 | ; setting: log-level 28 | ; desc : log verbosity level (4: debug, 3: info, 2: warning, 1: error) 29 | ; default: 1 30 | log-level=<%= @log_level %> 31 | 32 | ; 33 | ; setting: server-id 34 | ; desc : Sets the server id used to authenticate with Blackfire API 35 | ; default: 36 | server-id=<%= @server_id %> 37 | 38 | ; 39 | ; setting: server-token 40 | ; desc : Sets the server token used to authenticate with Blackfire API. It is unsafe to set this from the command line 41 | ; default: 42 | server-token=<%= @server_token %> 43 | 44 | ; 45 | ; setting: socket 46 | ; desc : Sets the socket the agent should read traces from. Possible value can be a unix socket or a TCP address. ie: unix:///var/run/blackfire/agent.sock or tcp://127.0.0.1:8307 47 | ; default: unix:///var/run/blackfire/agent.sock 48 | socket=<%= @socket %> 49 | 50 | ; 51 | ; setting: spec 52 | ; desc : Sets the path to the json specifications file 53 | ; default: 54 | spec=<%= @spec %> 55 | -------------------------------------------------------------------------------- /templates/default/blackfire.ini.erb: -------------------------------------------------------------------------------- 1 | ; priority=90 2 | [blackfire] 3 | extension=blackfire.so 4 | blackfire.agent_socket = <%= @socket %> 5 | <% if @server_id %> 6 | blackfire.server_id = <%= @server_id %> 7 | <% else %> 8 | ;blackfire.server_id = 9 | <% end %> 10 | <% if @server_token %> 11 | blackfire.server_token = <%= @server_token %> 12 | <% else %> 13 | ;blackfire.server_token = 14 | <% end %> 15 | <% if @log_level %> 16 | blackfire.log_level = <%= @log_level %> 17 | <% else %> 18 | ;blackfire.log_level = 3 19 | <% end %> 20 | <% if @log_file %> 21 | blackfire.log_file = <%= @log_file %> 22 | <% else %> 23 | ;blackfire.log_file = /tmp/blackfire.log 24 | <% end %> 25 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/install_spec.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | 3 | set :backend, :exec 4 | 5 | describe file('/etc/blackfire/agent') do 6 | it { should be_file } 7 | it { should be_mode 644 } 8 | it { should be_owned_by 'root' } 9 | it { should be_grouped_into 'root' } 10 | end 11 | 12 | describe service('blackfire-agent') do 13 | it { should be_enabled } 14 | it { should be_running } 15 | end 16 | 17 | describe user('blackfire') do 18 | it { should exist } 19 | end 20 | -------------------------------------------------------------------------------- /test/integration/docker/serverspec/install_spec.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | 3 | set :backend, :exec 4 | 5 | describe file('/etc/blackfire/agent') do 6 | it { should be_file } 7 | it { should be_mode 644 } 8 | it { should be_owned_by 'root' } 9 | it { should be_grouped_into 'root' } 10 | end 11 | 12 | describe service('blackfire-agent') do 13 | it { should be_enabled } 14 | end 15 | 16 | # service::should_be_runing fails with docker and centos 17 | # so we use process instead 18 | describe process('blackfire-agent') do 19 | it { should be_running } 20 | end 21 | 22 | describe user('blackfire') do 23 | it { should exist } 24 | end 25 | --------------------------------------------------------------------------------