This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.rb
134 lines (110 loc) · 3.57 KB
/
default.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
application_name = "viewshare"
::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)
node.set_unless[application_name]["secret_key"] = "#{Array.new(4).fill {secure_password}.join}"
node.set_unless[application_name]["rabbitmq_user_password"] = secure_password
node.save unless Chef::Config[:solo]
app_node = node[application_name]
db_user = "root"
db_passwd = node['mysql']['server_root_password']
db_name = app_node['database_name']
rabbitmq_user_name = "viewshare_user"
rabbitmq_user_passwd = app_node[:rabbitmq_user_password]
rabbitmq_vhost_name = "/viewshare"
mysql_database db_name do
connection ({:host => "localhost", :username => db_user, :password => db_passwd})
action :create
end
rabbitmq_vhost rabbitmq_vhost_name do
action :add
end
rabbitmq_user rabbitmq_user_name do
password rabbitmq_user_passwd
action :add
end
rabbitmq_user rabbitmq_user_name do
vhost rabbitmq_vhost_name
permissions "\".*\" \".*\" \".*\""
action :set_permissions
end
root_path = "/srv/#{application_name}"
django_settings = {"root_path"=>root_path}
if app_node["email_settings_bag"] && app_node["email_settings_item"] then
django_settings["email_settings"] = data_bag_item(app_node[:email_settings_bag], app_node[:email_settings_item])
end
application application_name do
path root_path
owner "nobody"
group "nogroup"
repository app_node[:repository]
revision app_node[:revision]
migrate true
packages ["csstidy", "git-core", "libevent-dev"]
django do
requirements "requirements.txt"
settings_template "settings.py.erb"
local_settings_file "viewshare_site_settings.py"
debug app_node[:debug]
collectstatic !app_node[:debug]
database do
database db_name
adapter "mysql"
username db_user
password db_passwd
host "localhost"
end
settings django_settings
end
gunicorn do
app_module :django
host "127.0.0.1"
port app_node[:application_port]
worker_class "gevent"
autostart true
timeout 600
max_requests 1500
#server_hooks :post_fork => "from psycogreen.gevent import patch_psycopg; patch_psycopg()"
end
celery do
config "celeryconfig.py"
django true
broker do
transport "amqp"
host "127.0.0.1"
user rabbitmq_user_name
password rabbitmq_user_passwd
vhost rabbitmq_vhost_name
end
end
nginx_load_balancer do
application_port app_node[:application_port]
template "nginx.conf.erb"
static_files "/static" => "#{root_path}/shared/static",
"/media" => "#{root_path}/shared/media"
locations "/static/CACHE" => {"alias" => "#{root_path}/shared/static/CACHE",
"expires" => "max",
"gzip_static" => "on"},
"/fileuploads" => {"alias" => "#{root_path}/shared/upload",
"internal" => nil}
server_name app_node[:server_name]
port app_node[:port]
end
end
if app_node["auth_protect"] then
cookbook_file "#{node['nginx']['dir']}/conf.d/#{application_name}.htpass" do
source "htpasswd"
owner node['nginx']['user']
mode 00600
notifies :restart, resources(:service => "nginx")
end
end
nginx_site "000-default" do
enable false
end
nginx_site "default" do
enable false
end
if node[:recipes].include?("iptables")
iptables_rule application_name do
variables(:port => node[application_name][:port])
end
end