nginx.rb 1.53 KB
Newer Older
ogom's avatar
ogom committed
1 2 3 4 5 6 7 8 9
#
# Cookbook Name:: gitlab
# Recipe:: nginx
#

gitlab = node['gitlab']

# 7. Nginx
## Installation
10
package "nginx" do
ogom's avatar
ogom committed
11
  action :install
12
end if gitlab['install_nginx']
ogom's avatar
ogom committed
13 14

## Site Configuration
ogom's avatar
ogom committed
15 16
path = platform_family?("rhel") ? "/etc/nginx/conf.d/gitlab.conf" : "/etc/nginx/sites-available/gitlab"
template path do
ogom's avatar
ogom committed
17
  source "nginx.erb"
ogom's avatar
ogom committed
18
  mode 0644
ogom's avatar
ogom committed
19 20 21
  variables({
    :path => gitlab['path'],
    :host => gitlab['host'],
Marin Jankovski's avatar
Marin Jankovski committed
22 23 24 25
    :port => gitlab['port'],
    :url => gitlab['url'],
    :ssl_certificate_path => gitlab['ssl_certificate_path'],
    :ssl_certificate_key_path => gitlab['ssl_certificate_key_path']
ogom's avatar
ogom committed
26 27 28
  })
end

ogom's avatar
ogom committed
29 30 31 32
if platform_family?("rhel")
  directory gitlab['home'] do
    mode 0755
  end
33 34 35 36 37 38

  %w( default.conf ssl.conf virtual.conf ).each do |conf|
    file "/etc/nginx/conf.d/#{conf}" do
      action :delete
    end
  end
ogom's avatar
ogom committed
39 40 41 42
else
  link "/etc/nginx/sites-enabled/gitlab" do
    to "/etc/nginx/sites-available/gitlab"
  end
ogom's avatar
ogom committed
43

ogom's avatar
ogom committed
44 45 46
  file "/etc/nginx/sites-enabled/default" do
    action :delete
  end
ogom's avatar
ogom committed
47 48
end

Marin Jankovski's avatar
Marin Jankovski committed
49
if gitlab['port'] == "443"
Marin Jankovski's avatar
Marin Jankovski committed
50
  directory "#{gitlab['ssl_certificate_path']}" do
Marin Jankovski's avatar
Marin Jankovski committed
51 52 53 54
    recursive true
    mode 0755
  end

Marin Jankovski's avatar
Marin Jankovski committed
55 56 57 58 59 60
  directory "#{gitlab['ssl_certificate_key_path']}" do
    recursive true
    mode 0755
  end

  file "#{gitlab['ssl_certificate_path']}/#{gitlab['host']}.crt" do
Marin Jankovski's avatar
Marin Jankovski committed
61 62 63 64
    content gitlab['ssl_certificate']
    mode 0600
  end

Marin Jankovski's avatar
Marin Jankovski committed
65
  file "#{gitlab['ssl_certificate_key_path']}/#{gitlab['host']}.key" do
Marin Jankovski's avatar
Marin Jankovski committed
66 67 68 69
    content gitlab['ssl_certificate_key']
    mode 0600
  end
end
ogom's avatar
ogom committed
70
## Restart
Marin Jankovski's avatar
Marin Jankovski committed
71 72 73 74 75

service "nginx" do
  action :enable
end

ogom's avatar
ogom committed
76 77 78
service "nginx" do
  action :restart
end