forked from benhoskings/babushka-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres.rb
62 lines (57 loc) · 1.89 KB
/
postgres.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
dep 'existing postgres db' do
requires 'postgres access'
met? {
!shell("psql -l") {|shell|
shell.stdout.split("\n").grep(/^\s*#{var :db_name}\s+\|/)
}.empty?
}
meet {
shell "createdb -O '#{var :username}' '#{var :db_name}'"
}
end
dep 'pg.gem' do
requires 'postgres.managed'
provides []
end
dep 'postgres access' do
requires 'postgres.managed', 'user exists'
met? { !sudo("echo '\\du' | #{which 'psql'}", :as => 'postgres').split("\n").grep(/^\W*\b#{var :username}\b/).empty? }
meet { sudo "createuser -SdR #{var :username}", :as => 'postgres' }
end
dep 'postgres backups' do
requires 'postgres.managed'
met? { shell "test -x /etc/cron.hourly/postgres_offsite_backup" }
before {
sudo("ssh #{var :offsite_host} 'true'").tap {|result|
if result
log_ok "publickey login to #{var :offsite_host}"
else
log_error "You need to add root's public key to #{var :offsite_host}:~/.ssh/authorized_keys."
end
}
}
meet {
render_erb 'postgres/offsite_backup.rb.erb', :to => '/usr/local/bin/postgres_offsite_backup', :perms => '755', :sudo => true
sudo "ln -sf /usr/local/bin/postgres_offsite_backup /etc/cron.hourly/"
}
end
dep 'postgres 9' do
requires {
on :apt, 'set.locale', 'ppa postgres.apt_repo', 'postgres.managed'
}
met? { provided? 'psql ~> 9.0.0' }
end
dep 'postgres.managed' do
installs {
via :macports, 'postgresql83-server'
via :apt, %w[postgresql postgresql-client libpq-dev]
via :brew, 'postgresql'
}
provides 'psql'
after :on => :osx do
sudo "mkdir -p /opt/local/var/db/postgresql83/defaultdb" and
sudo "chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb" and
sudo "su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'" and
sudo "launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist"
end
end