Commit 060c9b82f10ef3f426f653439daba66c30e84927
1 parent
95d60940
Exists in
master
and in
17 other branches
Start with the postgresql recipe
Showing
2 changed files
with
176 additions
and
0 deletions
Show diff stats
files/gitlab-cookbooks/gitlab/recipes/redis.rb
... | ... | @@ -0,0 +1,156 @@ |
1 | +# | |
2 | +# Copyright:: Copyright (c) 2012 Opscode, Inc. | |
3 | +# License:: Apache License, Version 2.0 | |
4 | +# | |
5 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | +# you may not use this file except in compliance with the License. | |
7 | +# You may obtain a copy of the License at | |
8 | +# | |
9 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
10 | +# | |
11 | +# Unless required by applicable law or agreed to in writing, software | |
12 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | +# See the License for the specific language governing permissions and | |
15 | +# limitations under the License. | |
16 | +# | |
17 | + | |
18 | +postgresql_dir = node['gitlab']['postgresql']['dir'] | |
19 | +postgresql_data_dir = node['gitlab']['postgresql']['data_dir'] | |
20 | +postgresql_data_dir_symlink = File.join(postgresql_dir, "data") | |
21 | +postgresql_log_dir = node['gitlab']['postgresql']['log_directory'] | |
22 | + | |
23 | +user node['gitlab']['postgresql']['username'] do | |
24 | + system true | |
25 | + shell node['gitlab']['postgresql']['shell'] | |
26 | + home node['gitlab']['postgresql']['home'] | |
27 | +end | |
28 | + | |
29 | +directory postgresql_log_dir do | |
30 | + owner node['gitlab']['postgresql']['username'] | |
31 | + recursive true | |
32 | +end | |
33 | + | |
34 | +directory postgresql_dir do | |
35 | + owner node['gitlab']['postgresql']['username'] | |
36 | + mode "0700" | |
37 | +end | |
38 | + | |
39 | +directory postgresql_data_dir do | |
40 | + owner node['gitlab']['postgresql']['username'] | |
41 | + mode "0700" | |
42 | + recursive true | |
43 | +end | |
44 | + | |
45 | +link postgresql_data_dir_symlink do | |
46 | + to postgresql_data_dir | |
47 | + not_if { postgresql_data_dir == postgresql_data_dir_symlink } | |
48 | +end | |
49 | + | |
50 | +file File.join(node['gitlab']['postgresql']['home'], ".profile") do | |
51 | + owner node['gitlab']['postgresql']['username'] | |
52 | + mode "0644" | |
53 | + content <<-EOH | |
54 | +PATH=#{node['gitlab']['postgresql']['user_path']} | |
55 | +EOH | |
56 | +end | |
57 | + | |
58 | +if File.directory?("/etc/sysctl.d") && File.exists?("/etc/init.d/procps") | |
59 | + # smells like ubuntu... | |
60 | + service "procps" do | |
61 | + action :nothing | |
62 | + end | |
63 | + | |
64 | + template "/etc/sysctl.d/90-postgresql.conf" do | |
65 | + source "90-postgresql.conf.sysctl.erb" | |
66 | + owner "root" | |
67 | + mode "0644" | |
68 | + variables(node['gitlab']['postgresql'].to_hash) | |
69 | + notifies :start, 'service[procps]', :immediately | |
70 | + end | |
71 | +else | |
72 | + # hope this works... | |
73 | + execute "sysctl" do | |
74 | + command "/sbin/sysctl -p /etc/sysctl.conf" | |
75 | + action :nothing | |
76 | + end | |
77 | + | |
78 | + bash "add shm settings" do | |
79 | + user "root" | |
80 | + code <<-EOF | |
81 | + echo 'kernel.shmmax = #{node['gitlab']['postgresql']['shmmax']}' >> /etc/sysctl.conf | |
82 | + echo 'kernel.shmall = #{node['gitlab']['postgresql']['shmall']}' >> /etc/sysctl.conf | |
83 | + EOF | |
84 | + notifies :run, 'execute[sysctl]', :immediately | |
85 | + not_if "egrep '^kernel.shmmax = ' /etc/sysctl.conf" | |
86 | + end | |
87 | +end | |
88 | + | |
89 | +execute "/opt/gitlab/embedded/bin/initdb -D #{postgresql_data_dir} -E UTF8" do | |
90 | + user node['gitlab']['postgresql']['username'] | |
91 | + not_if { File.exists?(File.join(postgresql_data_dir, "PG_VERSION")) } | |
92 | +end | |
93 | + | |
94 | +postgresql_config = File.join(postgresql_data_dir, "postgresql.conf") | |
95 | + | |
96 | +template postgresql_config do | |
97 | + source "postgresql.conf.erb" | |
98 | + owner node['gitlab']['postgresql']['username'] | |
99 | + mode "0644" | |
100 | + variables(node['gitlab']['postgresql'].to_hash) | |
101 | + notifies :restart, 'service[postgresql]' if OmnibusHelper.should_notify?("postgresql") | |
102 | +end | |
103 | + | |
104 | +pg_hba_config = File.join(postgresql_data_dir, "pg_hba.conf") | |
105 | + | |
106 | +template pg_hba_config do | |
107 | + source "pg_hba.conf.erb" | |
108 | + owner node['gitlab']['postgresql']['username'] | |
109 | + mode "0644" | |
110 | + variables(node['gitlab']['postgresql'].to_hash) | |
111 | + notifies :restart, 'service[postgresql]' if OmnibusHelper.should_notify?("postgresql") | |
112 | +end | |
113 | + | |
114 | +should_notify = OmnibusHelper.should_notify?("postgresql") | |
115 | + | |
116 | +runit_service "postgresql" do | |
117 | + down node['gitlab']['postgresql']['ha'] | |
118 | + control(['t']) | |
119 | + options({ | |
120 | + :log_directory => postgresql_log_dir, | |
121 | + :svlogd_size => node['gitlab']['postgresql']['svlogd_size'], | |
122 | + :svlogd_num => node['gitlab']['postgresql']['svlogd_num'] | |
123 | + }.merge(params)) | |
124 | +end | |
125 | + | |
126 | +if node['gitlab']['bootstrap']['enable'] | |
127 | + execute "/opt/gitlab/bin/gitlab-ctl start postgresql" do | |
128 | + retries 20 | |
129 | + end | |
130 | +end | |
131 | + | |
132 | +### | |
133 | +# Create the database, migrate it, and create the users we need, and grant them | |
134 | +# privileges. | |
135 | +### | |
136 | +pg_helper = PgHelper.new(node) | |
137 | +pg_port = node['gitlab']['postgresql']['port'] | |
138 | +pg_user = node['gitlab']['postgresql']['username'] | |
139 | +bin_dir = "/opt/gitlab/embedded/bin" | |
140 | +db_name = "gitlabhq_production" | |
141 | + | |
142 | +sql_user = node['gitlab']['postgresql']['sql_user'] | |
143 | +sql_user_passwd = node['gitlab']['postgresql']['sql_password'] | |
144 | + | |
145 | +execute "#{bin_dir}/psql --port #{pg_port} -d template1 -c \"CREATE USER #{sql_user} WITH ENCRYPTED PASSWORD '#{sql_user_passwd}'\"" do | |
146 | + user pg_user | |
147 | + not_if { !pg_helper.is_running? || pg_helper.sql_user_exists? } | |
148 | +end | |
149 | + | |
150 | +execute "create #{db_name} database" do | |
151 | + command "#{bin_dir}/createdb --port #{pg_port} -O #{sql_user} #{db_name}" | |
152 | + user pg_user | |
153 | + not_if { !pg_helper.is_running? || pg_helper.database_exists?(db_name) } | |
154 | + retries 30 | |
155 | + # notifies :run, "execute[migrate_database]", :immediately | |
156 | +end | ... | ... |
files/gitlab-cookbooks/gitlab/recipes/redis_disable.rb
... | ... | @@ -0,0 +1,20 @@ |
1 | +# | |
2 | +# Copyright:: Copyright (c) 2012 Opscode, Inc. | |
3 | +# License:: Apache License, Version 2.0 | |
4 | +# | |
5 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | +# you may not use this file except in compliance with the License. | |
7 | +# You may obtain a copy of the License at | |
8 | +# | |
9 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
10 | +# | |
11 | +# Unless required by applicable law or agreed to in writing, software | |
12 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | +# See the License for the specific language governing permissions and | |
15 | +# limitations under the License. | |
16 | +# | |
17 | + | |
18 | +runit_service "postgresql" do | |
19 | + action :disable | |
20 | +end | ... | ... |