Class: DanarchyDeploy::Applicator::PHPFPM

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/applicator/phpfpm.rb

Class Method Summary collapse

Class Method Details

.disable_phpfpm(app, options) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/danarchy_deploy/applicator/phpfpm.rb', line 71

def self.disable_phpfpm(app, options)
  if options[:pretend]
    puts "   - Fake run: Remove #{app[:user_phpcfg]}"
  else
    puts "\n  ! Disabling PHP-FPM for '#{app[:username]}'."
    if File.exist?(app[:phpcfg])
      File.delete(app[:phpcfg]) 
      puts "    |_ Removed: #{app[:phpcfg]}"
    end
  end
end

.enable_phpfpm(app, options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/danarchy_deploy/applicator/phpfpm.rb', line 41

def self.enable_phpfpm(app, options)
  tmpdir = "/home/#{app[:username]}/tmp"

  if !options[:pretend]
    puts "\n  |+ Enabling PHP-FPM for '#{app[:username]}'."
    FileUtils.mkdir_p(File.dirname(app[:phpcfg]))
    FileUtils.mkdir_p(tmpdir, mode: 1750)
    FileUtils.chown(app[:username], app[:username], tmpdir)
  end

  pool = app[:domain].gsub('.','_')
  web_user = 'nginx'  if app[:nginx]
  web_user = 'apache' if app[:apache]
  source = options[:deploy_dir] + '/templates/applications/php/phpfpm.conf.erb'
  templates = [{ target: app[:phpcfg],
                 source: source,
                 variables: { pool: pool,
                              username: app[:username],
                              web_user: web_user,
                              tmp:      tmpdir },
                 dir_perms: { owner: 'root',
                              group: 'root',
                              mode: '0755' },
                 file_perms: { owner: 'root',
                               group: 'root',
                               mode: '0644' } }]

  DanarchyDeploy::Templater.new(templates, options)
end

.generate_paths(app, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/danarchy_deploy/applicator/phpfpm.rb', line 19

def self.generate_paths(app, options)
  phpfpm_config = Dir['/etc/**/php-fpm.conf'].last
  sites_enabled = nil

  if phpfpm_config.nil? && options[:pretend]
    sites_enabled = '/etc/php/fpm-pretend/sites_enabled/'
    puts "   - Fake run: Testing deployment using #{sites_enabled}"
  elsif phpfpm_config.nil? && !options[:pretend]
    abort("\n  ! ERROR: Could not establish php-fpm.conf location!")
  else
    puts "   |+ Found php-fpm.conf at: #{phpfpm_config}."
    phpfpm_config = File.readlines(phpfpm_config)
    sites_enabled = phpfpm_config.grep(/^include/).last.gsub(/(^.*=|\*$|\*.conf)/, '').chomp        
  end

  app[:phpcfg] = app[:phpcfg] ?
                   app[:phpcfg] :
                   "/home/#{app[:username]}/php-fpm/sites-enabled/#{app[:domain]}.conf"
  # app[:phpcfg] = sites_enabled + "#{app[:domain].gsub('.','_')}.conf"
  app
end

.new(app, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/danarchy_deploy/applicator/phpfpm.rb', line 5

def self.new(app, options)
  puts "\n" + self.name
  puts "\n > Checking #{app[:username]}'s PHP-FPM config."

  app = generate_paths(app, options)
  if app[:phpfpm] == 'enabled'
    enable_phpfpm(app, options)
  elsif app[:phpfpm] == 'disabled'
    disable_phpfpm(app, options)
  end

  app
end