Class: Calatrava::Apache

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/calatrava/apache.rb

Instance Method Summary collapse

Methods included from Rake::DSL

#transient

Instance Method Details

#apache_conf_dirObject



25
# File 'lib/calatrava/apache.rb', line 25

def apache_conf_dir ; "#{apache_dir}/conf"; end

#apache_dirObject



22
# File 'lib/calatrava/apache.rb', line 22

def apache_dir ; "web/apache" ; end

#apache_logs_dirObject



24
# File 'lib/calatrava/apache.rb', line 24

def apache_logs_dir ; "#{apache_dir}/logs" ; end

#apache_public_dirObject



23
# File 'lib/calatrava/apache.rb', line 23

def apache_public_dir ; "#{apache_dir}/public" ; end

#ensure_httpdObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/calatrava/apache.rb', line 52

def ensure_httpd
  if !@httpd
    if `uname -a`.chomp["amzn1"]
      @httpd = "httpd"
    elsif `uname`.chomp == "Linux"
      @httpd = "apache2"
    elsif `uname`.chomp == "Darwin"
      @httpd = "httpd"
    else
      raise "Calatrava does not support running apache on this platform."
    end
  end
end

#httpd(command, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/calatrava/apache.rb', line 27

def httpd(command, opts = {})
  ensure_httpd
  cmd = %Q{#{@httpd} -d #{apache_dir} -f conf/httpd.conf -e DEBUG -k #{command} -DNO_DETACH -DFOREGROUND}
  puts cmd
  if opts[:background]
    fork do
      exec cmd
    end
  else
    exec cmd
  end
end

#install_tasksObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/calatrava/apache.rb', line 66

def install_tasks
  directory apache_logs_dir
  file apache_public_dir do
    cd apache_dir do
      ln_s "../public", "public"
    end
  end

  file "#{apache_conf_dir}/httpd.conf" => 'configure:calatrava_env' do
    cp Calatrava::Project.current.config.path("httpd.conf"), apache_conf_dir
  end

  desc "launch a non-daemon apache instance on port 8888 which will serve our local app and also proxy to backend services"
  task :start => ['web:build', apache_public_dir, apache_logs_dir, "#{apache_conf_dir}/httpd.conf", 'web:autocompile'] do
    launch_apache
  end

  task :background => ['web:build', apache_public_dir, apache_logs_dir, "#{apache_conf_dir}/httpd.conf"] do
    launch_apache :background => true
  end

  desc "Reload the apache configuration"
  task :reload do
    reload_apache
  end

  desc "Stop the apache configuration"
  task :stop do
    stop_apache
  end

  desc "Cleans apache config"
  task :clean do
    rm_rf apache_logs_dir
    rm_rf File.join(apache_conf_dir, 'httpd.conf')
  end

end

#launch_apache(opts = {}) ⇒ Object



40
41
42
# File 'lib/calatrava/apache.rb', line 40

def launch_apache(opts = {})
  httpd :start, opts
end

#reload_apacheObject



48
49
50
# File 'lib/calatrava/apache.rb', line 48

def reload_apache
  httpd :restart
end

#stop_apacheObject



44
45
46
# File 'lib/calatrava/apache.rb', line 44

def stop_apache
  httpd 'graceful-stop'
end