syncwrap 1.5.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/History.rdoc +19 -0
  3. data/Manifest.txt +82 -34
  4. data/README.rdoc +96 -48
  5. data/Rakefile +0 -65
  6. data/bin/syncwrap +27 -0
  7. data/examples/LAYOUT.rdoc +70 -0
  8. data/examples/Rakefile +16 -0
  9. data/examples/ec2.rb +44 -0
  10. data/examples/hello.rb +14 -0
  11. data/examples/hello_binding.rb +27 -0
  12. data/examples/jruby.rb +11 -0
  13. data/examples/private/aws.json +4 -0
  14. data/examples/rput.rb +24 -0
  15. data/examples/sync/home/bob/.ssh/authorized_keys +1 -0
  16. data/examples/sync/tmp/sample.erb +3 -0
  17. data/lib/syncwrap/amazon_ec2.rb +236 -0
  18. data/lib/syncwrap/amazon_ws.rb +308 -0
  19. data/lib/syncwrap/base.rb +4 -2
  20. data/lib/syncwrap/cli.rb +328 -0
  21. data/lib/syncwrap/component.rb +443 -0
  22. data/lib/syncwrap/components/commercial_jdk.rb +76 -0
  23. data/lib/syncwrap/components/cruby_vm.rb +144 -0
  24. data/lib/syncwrap/components/etc_hosts.rb +44 -0
  25. data/lib/syncwrap/{geminabox.rb → components/geminabox.rb} +12 -17
  26. data/lib/syncwrap/components/hashdot.rb +97 -0
  27. data/lib/syncwrap/components/iyyov.rb +144 -0
  28. data/lib/syncwrap/components/iyyov_daemon.rb +125 -0
  29. data/lib/syncwrap/components/jruby_vm.rb +122 -0
  30. data/lib/syncwrap/components/mdraid.rb +204 -0
  31. data/lib/syncwrap/components/network.rb +99 -0
  32. data/lib/syncwrap/components/open_jdk.rb +70 -0
  33. data/lib/syncwrap/components/postgresql.rb +159 -0
  34. data/lib/syncwrap/components/qpid.rb +303 -0
  35. data/lib/syncwrap/components/rhel.rb +71 -0
  36. data/lib/syncwrap/components/run_user.rb +99 -0
  37. data/lib/syncwrap/components/ubuntu.rb +85 -0
  38. data/lib/syncwrap/components/users.rb +200 -0
  39. data/lib/syncwrap/context.rb +260 -0
  40. data/lib/syncwrap/distro.rb +53 -60
  41. data/lib/syncwrap/formatter.rb +149 -0
  42. data/lib/syncwrap/host.rb +134 -0
  43. data/lib/syncwrap/main.rb +62 -0
  44. data/lib/syncwrap/path_util.rb +55 -0
  45. data/lib/syncwrap/rsync.rb +227 -0
  46. data/lib/syncwrap/ruby_support.rb +110 -0
  47. data/lib/syncwrap/shell.rb +207 -0
  48. data/lib/syncwrap.rb +367 -1
  49. data/{etc → sync/etc}/gemrc +1 -3
  50. data/sync/etc/hosts.erb +8 -0
  51. data/{etc/init.d/iyyov → sync/etc/init.d/iyyov.erb} +35 -7
  52. data/sync/etc/sysconfig/pgsql/postgresql.erb +2 -0
  53. data/sync/src/hashdot/Makefile.erb +98 -0
  54. data/sync/src/hashdot/profiles/default.hdp.erb +25 -0
  55. data/sync/src/hashdot/profiles/jruby-common.hdp +28 -0
  56. data/sync/src/hashdot/profiles/jruby-shortlived.hdp +9 -0
  57. data/sync/src/hashdot/profiles/jruby.hdp.erb +13 -0
  58. data/sync/src/hashdot/profiles/shortlived.hdp +6 -0
  59. data/sync/var/iyyov/default/config.rb +1 -0
  60. data/sync/var/iyyov/default/daemon.rb.erb +15 -0
  61. data/sync/var/iyyov/jobs.rb.erb +4 -0
  62. data/test/muddled_sync.rb +13 -0
  63. data/test/setup.rb +39 -0
  64. data/test/sync/d1/bar +1 -0
  65. data/test/sync/d1/foo.erb +1 -0
  66. data/test/sync/d3/d2/bar +1 -0
  67. data/test/sync/d3/d2/foo.erb +1 -0
  68. data/test/test_components.rb +108 -0
  69. data/test/test_context.rb +107 -0
  70. data/test/test_context_rput.rb +289 -0
  71. data/test/test_rsync.rb +138 -0
  72. data/test/test_shell.rb +233 -0
  73. data/test/test_space.rb +218 -0
  74. data/test/test_space_main.rb +40 -0
  75. data/test/zfile +1 -0
  76. metadata +204 -71
  77. data/etc/sysconfig/pgsql/postgresql +0 -2
  78. data/lib/syncwrap/aws.rb +0 -448
  79. data/lib/syncwrap/common.rb +0 -161
  80. data/lib/syncwrap/ec2.rb +0 -59
  81. data/lib/syncwrap/hashdot.rb +0 -70
  82. data/lib/syncwrap/iyyov.rb +0 -139
  83. data/lib/syncwrap/java.rb +0 -61
  84. data/lib/syncwrap/jruby.rb +0 -118
  85. data/lib/syncwrap/postgresql.rb +0 -135
  86. data/lib/syncwrap/qpid.rb +0 -251
  87. data/lib/syncwrap/remote_task.rb +0 -199
  88. data/lib/syncwrap/rhel.rb +0 -67
  89. data/lib/syncwrap/ubuntu.rb +0 -78
  90. data/lib/syncwrap/user_run.rb +0 -102
  91. data/test/test_syncwrap.rb +0 -202
  92. data/var/iyyov/jobs.rb +0 -11
  93. /data/{etc → sync/etc}/corosync/corosync.conf +0 -0
  94. /data/{etc → sync/etc}/corosync/uidgid.d/qpid +0 -0
  95. /data/{etc → sync/etc}/init.d/qpidd +0 -0
  96. /data/{etc → sync/etc}/sysctl.d/61-postgresql-shm.conf +0 -0
  97. /data/{usr/local → sync/jruby}/bin/jgem +0 -0
  98. /data/{postgresql → sync/postgresql}/rhel/pg_hba.conf +0 -0
  99. /data/{postgresql → sync/postgresql}/rhel/pg_ident.conf +0 -0
  100. /data/{postgresql → sync/postgresql}/rhel/postgresql.conf +0 -0
  101. /data/{postgresql → sync/postgresql}/ubuntu/environment +0 -0
  102. /data/{postgresql → sync/postgresql}/ubuntu/pg_ctl.conf +0 -0
  103. /data/{postgresql → sync/postgresql}/ubuntu/pg_hba.conf +0 -0
  104. /data/{postgresql → sync/postgresql}/ubuntu/pg_ident.conf +0 -0
  105. /data/{postgresql → sync/postgresql}/ubuntu/postgresql.conf +0 -0
  106. /data/{postgresql → sync/postgresql}/ubuntu/start.conf +0 -0
  107. /data/{usr → sync/usr}/local/etc/qpidd.conf +0 -0
@@ -0,0 +1,204 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ module SyncWrap
20
+
21
+ # Handles assembling mdraid (Linux Software RAID) arrays, lvm
22
+ # volumes, creating and mounting filesystems from previously
23
+ # attached raw devices.
24
+ #
25
+ # Host component dependencies: <Distro>
26
+ class MDRaid < Component
27
+
28
+ # An instance number used for mdraid and volume group
29
+ # names. Increment this when applying multiple components of this
30
+ # type to the same host. Default: 0
31
+ attr_accessor :instance
32
+
33
+ # A number, range, or array of raw device names. See #raw_devices=
34
+ # for interpretation. Software raid is only used for >1 raw
35
+ # device. Default: 0
36
+ attr_reader :raw_devices
37
+
38
+ # Block device read-ahead setting for the raw devices, in 512-byte
39
+ # blocks. Default: 32
40
+ attr_accessor :raw_read_ahead
41
+
42
+ # Attempt to unmount and remove from fstab any existing mount of
43
+ # the specified raw devices. _WARNING:_ this may increase the
44
+ # danger of data loss!
45
+ # (Default: false)
46
+ attr_accessor :do_unmount
47
+
48
+ # Numeric RAID level.
49
+ # (Default: 10 if there are at least 4 raw devices, otherwise 0.)
50
+ attr_accessor :raid_level
51
+
52
+ # RAID md device read-ahead setting, in 512-byte blocks.
53
+ # Default: 64
54
+ attr_accessor :raid_read_ahead
55
+
56
+ # RAID chunk size in KB
57
+ # Default: 256
58
+ attr_accessor :raid_chunk
59
+
60
+ # A table of [ slice, path (,name) ] rows where; slice is a
61
+ # floating point ratio in range (0.0,1.0], path is the mount
62
+ # point, and name is the lvm name, defaulting if omitted to the
63
+ # last path element. The sum of all slice values in the table
64
+ # should be 1.0. Default: [ [ 1.0, '/data' ] ]
65
+ attr_accessor :lvm_volumes
66
+
67
+ # File System Type. Default: 'ext4'
68
+ attr_accessor :fs_type
69
+
70
+ # Array of FS specific options to pass as mkfs -t fs_type _OPTS_
71
+ # Default: [] (none)
72
+ attr_accessor :fs_opts
73
+
74
+ # Mount options Array
75
+ # Default: [ defaults auto noatime nodiratime ]
76
+ attr_accessor :mount_opts
77
+
78
+ def initialize( opts = {} )
79
+ @instance = 0 #FIXME: Or compute from existing volumes?
80
+
81
+ @raw_devices = []
82
+ @raw_read_ahead = 32 #512B blocks
83
+ @do_unmount = false
84
+
85
+ @raid_level = nil #default_raid_level
86
+ @raid_read_ahead = 64 #512B blocks
87
+ @raid_chunk = 256 #K
88
+
89
+ @lvm_volumes = [ [ 1.0, '/data' ] ]
90
+ @fs_type = 'ext4'
91
+ @fs_opts = []
92
+ @mount_opts = %w[ defaults auto noatime nodiratime ]
93
+
94
+ super
95
+ end
96
+
97
+ # Set raw devices to assemble.
98
+ # * Interprets an Integer val as a count of N devices with names
99
+ # /dev/xvdh1 to /dev/xvdhN.
100
+ # * Interprets a Range value as /dev/xvdhN for each N
101
+ # in range.
102
+ # * Interprets an Array as the actual device path strings.
103
+ def raw_devices=( val )
104
+ @raw_devices = case val
105
+ when Integer
106
+ val.times.map { |i| "/dev/xvdh#{i+1}" }
107
+ when Range
108
+ val.map { |i| "/dev/xvdh#{i}" }
109
+ when Array
110
+ val
111
+ else
112
+ raise "Unsupported raw_devices setting #{val.inspect}"
113
+ end
114
+ end
115
+
116
+ # Install only if _all_ lvm_volumes paths do not yet exist.
117
+ def install
118
+ return if raw_devices.empty? || lvm_volumes.empty?
119
+
120
+ paths = lvm_volumes.map { |r| r[1] }
121
+ test = paths.map { |p| "! -e #{p}" }.join( " -a " )
122
+
123
+ sudo( "if [ #{test} ]; then", close: "fi" ) do
124
+
125
+ dist_install( "mdadm", "lvm2", minimal: true )
126
+
127
+ raw_devices.each do |d|
128
+ unmount_device( d ) if do_unmount
129
+ sudo "blockdev --setra #{raw_read_ahead} #{d}"
130
+ end
131
+
132
+ if raw_devices.count > 1
133
+ dev = "/dev/md#{instance}"
134
+ create_raid( dev )
135
+ else
136
+ dev = raw_devices.first
137
+ end
138
+
139
+ create_volumes( dev )
140
+
141
+ end
142
+ end
143
+
144
+ private
145
+
146
+ def unmount_device( dev )
147
+ sudo <<-SH
148
+ if mount | grep -q '^#{dev} '; then
149
+ umount #{dev}
150
+ sed -r -i '\\|^#{dev}\\s|d' /etc/fstab
151
+ fi
152
+ SH
153
+ end
154
+
155
+ def create_raid( md )
156
+ rlevel = raid_level || default_raid_level
157
+
158
+ sudo <<-SH
159
+ mdadm --create #{md} --level=#{rlevel} --chunk=#{raid_chunk} \
160
+ --raid-devices=#{raw_devices.count} #{raw_devices.join ' '}
161
+ touch /etc/mdadm.conf
162
+ echo "DEVICE #{raw_devices.join ' '}" >> /etc/mdadm.conf
163
+ mdadm --detail --scan >> /etc/mdadm.conf
164
+ blockdev --setra #{raid_read_ahead} #{md}
165
+ SH
166
+ end
167
+
168
+ def create_volumes( dev )
169
+ vg = "vg#{instance}"
170
+ sudo <<-SH
171
+ dd if=/dev/zero of=#{dev} bs=512 count=1
172
+ pvcreate #{dev}
173
+ vgcreate #{vg} #{dev}
174
+ SH
175
+
176
+ lvm_volumes.each do |v|
177
+ create_volume( *v )
178
+ end
179
+ end
180
+
181
+ def create_volume( slice, path, name = nil )
182
+ name ||= File.basename( path )
183
+ vg = "vg#{instance}"
184
+ sudo <<-SH
185
+ lvcreate -l #{(slice * 100).round}%vg -n #{name} #{vg}
186
+ mkfs -t #{fs_type} #{fs_opts.join ' '} /dev/#{vg}/#{name}
187
+ mkdir -p #{path}
188
+ echo '/dev/#{vg}/#{name} #{path} #{fs_type} #{mount_opts.join ','} 0 0' \
189
+ >> /etc/fstab
190
+ mount #{path}
191
+ SH
192
+ end
193
+
194
+ def default_raid_level
195
+ if raw_devices.count >= 4
196
+ 10
197
+ else
198
+ 0
199
+ end
200
+ end
201
+
202
+ end
203
+
204
+ end
@@ -0,0 +1,99 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ require 'syncwrap/components/ubuntu'
20
+ require 'syncwrap/components/rhel'
21
+
22
+ module SyncWrap
23
+
24
+ # Make updates to system configration for hostname and name
25
+ # resolution. These changes are distro specific.
26
+ #
27
+ # Host component dependencies: <Distro>
28
+ class Network < Component
29
+
30
+ # A default DNS domain name to use for name search, for addition
31
+ # to /etc/resolver.conf, etc. (default: nil)
32
+ attr_accessor :dns_domain
33
+
34
+ def initialize( opts = {} )
35
+ @dns_domain = nil
36
+ super
37
+ end
38
+
39
+ def install
40
+ update_hostname
41
+ update_resolver
42
+ end
43
+
44
+ def update_hostname
45
+ name = host.name
46
+
47
+ case distro
48
+ when RHEL
49
+ # If HOSTNAME not already set correctly in network file,
50
+ # backup, delete old line, append new line.
51
+ sudo <<-SH
52
+ if ! grep -q '^HOSTNAME=#{name}$' /etc/sysconfig/network; then
53
+ cp -f /etc/sysconfig/network /etc/sysconfig/network~
54
+ sed -i '/^HOSTNAME=.*/d' /etc/sysconfig/network
55
+ echo 'HOSTNAME=#{name}' >> /etc/sysconfig/network
56
+ hostname #{name}
57
+ fi
58
+ SH
59
+ when Ubuntu
60
+ sudo <<-SH
61
+ if [ ! -e /etc/hostname -o "$(< /etc/hostname)" != "#{name}" ]; then
62
+ echo #{name} > /etc/hostname
63
+ hostname #{name}
64
+ fi
65
+ SH
66
+ end
67
+ end
68
+
69
+ def update_resolver
70
+ if dns_domain
71
+ # (Temporary) inclusion direct to resolver.conf
72
+ sudo <<-SH
73
+ if ! grep -q 'search.* #{dns_domain}' /etc/resolver.conf; then
74
+ cp -f /etc/resolver.conf /etc/resolver.conf~
75
+ sed -i '/^search/d' /etc/resolver.conf
76
+ echo 'search #{dns_domain}' >> /etc/resolver.conf
77
+ fi
78
+ SH
79
+
80
+ case distro
81
+ when RHEL
82
+ # FIXME:
83
+ warn "Network: not sure if resolver.conf change is permanent?"
84
+ when Ubuntu
85
+ f='/etc/network/interfaces'
86
+ sudo <<-SH
87
+ if ! grep -E -q '^\\s*dns-domain #{dns_domain}' #{f}; then
88
+ cp -f #{f} #{f}~
89
+ sed -r -i '/^\\s*dns-domain/d' #{f}
90
+ echo ' dns-domain #{dns_domain}' >> #{f}
91
+ fi
92
+ SH
93
+ end
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ # For distro class comparison only (pre-load for safety)
20
+ require 'syncwrap/components/rhel'
21
+ require 'syncwrap/components/ubuntu'
22
+
23
+ module SyncWrap
24
+
25
+ # Provision an OpenJDK via Linux distro managed packages.
26
+ #
27
+ # Oracle, Java, and OpenJDK are registered trademarks of Oracle
28
+ # and/or its affiliates.
29
+ # See http://openjdk.java.net/legal/openjdk-trademark-notice.html.
30
+ #
31
+ # Host component dependencies: <Distro>
32
+ class OpenJDK < Component
33
+
34
+ # The JDK major and/or minor version number, i.e "1.7" or "7" is 7.
35
+ # Marketing picked the version scheme.
36
+ attr_accessor :jdk_major_minor
37
+
38
+ def initialize( opts = {} )
39
+ @jdk_major_minor = 7
40
+
41
+ super
42
+ end
43
+
44
+ def jdk_dir
45
+ case distro
46
+ when RHEL
47
+ "/usr/lib/jvm/java-1.#{jdk_major_minor}.0"
48
+ when Ubuntu
49
+ "/usr/lib/jvm/java-#{jdk_major_minor}-openjdk-amd64"
50
+ else
51
+ raise ContextError, "Unknown distro jdk_dir"
52
+ end
53
+ end
54
+
55
+ # Install including development headers for things like Hashdot.
56
+ def install
57
+ case distro
58
+ when RHEL
59
+ dist_install( "java-1.#{jdk_major_minor}.0-openjdk",
60
+ "java-1.#{jdk_major_minor}.0-openjdk-devel" )
61
+ when Ubuntu
62
+ dist_install( "openjdk-#{jdk_major_minor}-jdk" )
63
+ else
64
+ raise ContextError, "Unknown distro type"
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,159 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ # For distro class comparison only (pre-load for safety)
20
+ require 'syncwrap/components/rhel'
21
+ require 'syncwrap/components/ubuntu'
22
+
23
+ module SyncWrap
24
+
25
+ # Provisions for install and configuration of PostgreSQL
26
+ #
27
+ # Host component dependencies: <Distro>
28
+ class PostgreSQL < Component
29
+
30
+ # Location of postgresql data dir
31
+ attr_accessor :pg_data_dir
32
+
33
+ # The distro default data dir (set if known to be different than
34
+ # distro-specific default, nil -> computed in accessor)
35
+ attr_writer :pg_default_data_dir
36
+
37
+ def initialize( opts = {} )
38
+ @pg_data_dir = '/pg/data'
39
+ @pg_default_data_dir = nil
40
+ super
41
+ end
42
+
43
+ def pg_default_data_dir
44
+ @pg_default_data_dir ||
45
+ case distro
46
+ when RHEL
47
+ '/var/lib/pgsql9/data'
48
+ when Ubuntu
49
+ '/var/lib/postgresql/9.1/main'
50
+ else
51
+ raise ContextError, "Distro #{distro.class.name} not supported"
52
+ end
53
+ end
54
+
55
+ def pg_deploy_config
56
+ case distro
57
+ when RHEL
58
+ 'postgresql/rhel'
59
+ when Ubuntu
60
+ 'postgresql/ubuntu'
61
+ else
62
+ raise ContextError, "Distro #{distro.class.name} not supported"
63
+ end
64
+ end
65
+
66
+ def pg_config_dir
67
+ case distro
68
+ when RHEL
69
+ pg_data_dir
70
+ when Ubuntu
71
+ '/etc/postgresql/9.1/main'
72
+ else
73
+ raise ContextError, "Distro #{distro.class.name} not supported"
74
+ end
75
+ end
76
+
77
+ def install
78
+ package_install
79
+ changes = setup_data_dir
80
+ changes += pg_configure
81
+ if changes.empty?
82
+ pg_start
83
+ else
84
+ pg_restart
85
+ end
86
+ end
87
+
88
+ def package_install
89
+ dist_install 'postgresql'
90
+ if distro.is_a?( Ubuntu )
91
+ pg_stop
92
+ rput( 'etc/sysctl.d/61-postgresql-shm.conf', :user => 'root' )
93
+ sudo "sysctl -p /etc/sysctl.d/61-postgresql-shm.conf"
94
+ end
95
+ end
96
+
97
+ def setup_data_dir
98
+ changes = []
99
+
100
+ case distro
101
+
102
+ when RHEL
103
+ unless pg_data_dir == pg_default_data_dir
104
+ changes = rput( 'etc/sysconfig/pgsql/postgresql', :user => 'root' )
105
+ end
106
+
107
+ sudo( "if [ ! -d '#{pg_data_dir}/base' ]; then", close: "fi" ) do
108
+ unless pg_data_dir == pg_default_data_dir
109
+ # (Per Amazon Linux)
110
+ # Install PGDATA var override for init.d/postgresql
111
+ sudo <<-SH
112
+ mkdir -p #{pg_data_dir}
113
+ chown postgres:postgres #{pg_data_dir}
114
+ chmod 700 #{pg_data_dir}
115
+ SH
116
+ end
117
+ dist_service( 'postgresql', 'initdb' )
118
+ end
119
+
120
+ when Ubuntu
121
+ unless pg_data_dir == pg_default_data_dir
122
+ sudo <<-SH
123
+ mkdir -p #{pg_data_dir}
124
+ chown postgres:postgres #{pg_data_dir}
125
+ chmod 700 #{pg_data_dir}
126
+ mv #{pg_default_data_dir}/* #{pg_data_dir}/
127
+ SH
128
+ end
129
+ else
130
+ raise ContextError, "Distro #{distro.class.name} not supported"
131
+ end
132
+
133
+ changes
134
+ end
135
+
136
+ # Update PostgreSQL config files
137
+ def pg_configure
138
+ changes = rput( "#{pg_deploy_config}/", pg_config_dir, :user => 'postgres' )
139
+ if !changes.empty? && pg_config_dir == pg_data_dir
140
+ sudo( "chmod 700 #{pg_data_dir}" )
141
+ end
142
+ changes
143
+ end
144
+
145
+ def pg_start
146
+ dist_service( 'postgresql', 'start' )
147
+ end
148
+
149
+ def pg_restart
150
+ dist_service( 'postgresql', 'restart' )
151
+ end
152
+
153
+ def pg_stop
154
+ dist_service( 'postgresql', 'stop' )
155
+ end
156
+
157
+ end
158
+
159
+ end