Skip to content

Commit

Permalink
move database setup attrs to database config key
Browse files Browse the repository at this point in the history
  • Loading branch information
avsh committed Apr 3, 2015
1 parent 33a393c commit f7d467d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,6 @@ Attributes
<td>Type of database, can be sqlite, mysql or pgsql</td>
<td><code>"mysql"</code></td>
</tr>
<tr>
<td><code>node['owncloud']['config']['dbinstance']</code></td>
<td>mySQL database instance name to run by the mysql_service lwrp from the mysql cookbook</td>
<td><code>"default"</code></td>
</tr>
<tr>
<td><code>node['owncloud']['config']['dbversion']</code></td>
<td>mySQL version to install by the mysql_service lwrp. Refer to https://github.com/chef-cookbooks/mysql#platform-support</td>
<td><code>nil</code></td>
</tr>
<tr>
<td><code>node['owncloud']['config']['dbname']</code></td>
<td>Name of the ownCloud database</td>
Expand All @@ -235,11 +225,6 @@ Attributes
<td>Password to access the ownCloud database</td>
<td><em>calculated</em></td>
</tr>
<tr>
<td><code>node['owncloud']['config']['dbrootpassword']</code></td>
<td>Database admin password to access a database instance</td>
<td><em>calculated</em></td>
</tr>
<tr>
<td><code>node['owncloud']['config']['dbhost']</code></td>
<td>Host running the ownCloud database</td>
Expand Down Expand Up @@ -330,6 +315,21 @@ Attributes
<td>Whether to skip settings the permissions of the ownCloud directory. Set this to true when using NFS synced folders.</td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>node['owncloud']['database']['rootpassword']</code></td>
<td>Database admin password to access a database instance</td>
<td><em>calculated</em></td>
</tr>
<tr>
<td><code>node['owncloud']['database']['instance']</code></td>
<td>mySQL database instance name to run by the mysql_service lwrp from the mysql cookbook</td>
<td><code>"default"</code></td>
</tr>
<tr>
<td><code>node['owncloud']['database']['version']</code></td>
<td>mySQL version to install by the mysql_service lwrp. Refer to https://github.com/chef-cookbooks/mysql#platform-support</td>
<td><code>nil</code></td>
</tr>
</table>

Recipes
Expand All @@ -350,7 +350,7 @@ On the first run, several passwords will be automatically generated and stored i

* `node['owncloud']['admin']['pass']`
* `node['owncloud']['config']['dbpassword']` (Only when using *MySQL* or *PostgreSQL*)
* `node['owncloud']['config']['dbrootpassword']` (Only when using *MySQL* or *PostgreSQL*)
* `node['owncloud']['database']['rootpassword']` (Only when using *MySQL* or *PostgreSQL*)

When using Chef Solo, these passwords need to be set manually.

Expand Down
7 changes: 4 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@
default['owncloud']['admin']['pass'] = nil

default['owncloud']['config']['dbtype'] = 'mysql'
default['owncloud']['config']['dbinstance'] = 'default'
default['owncloud']['config']['dbversion'] = nil
default['owncloud']['config']['dbname'] = 'owncloud'
default['owncloud']['config']['dbuser'] = 'owncloud'
default['owncloud']['config']['dbpassword'] = nil
default['owncloud']['config']['dbrootpassword'] = nil
default['owncloud']['config']['dbhost'] = '127.0.0.1'
default['owncloud']['config']['dbtableprefix'] = ''

Expand All @@ -68,3 +65,7 @@
default['owncloud']['cron']['hour'] = '*'
default['owncloud']['cron']['month'] = '*'
default['owncloud']['cron']['weekday'] = '*'

default['owncloud']['database']['instance'] = 'default'
default['owncloud']['database']['rootpassword'] = nil
default['owncloud']['database']['version'] = nil
43 changes: 22 additions & 21 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,6 @@
:required => 'optional',
:default => '"mysql"'

attribute 'owncloud/config/dbinstance',
:display_name => 'mySQL database instance name',
:description => 'mySQL database instance name to run by the mysql_service lwrp from the mysql cookbook',
:type => 'string',
:required => 'optional',
:default => '"default"'

attribute 'owncloud/config/dbversion',
:display_name => 'mySQL server version',
:description => 'mySQL version to install by the mysql_service lwrp. Refer to https://github.com/chef-cookbooks/mysql#platform-support',
:type => 'string',
:required => 'optional',
:default => 'nil'

attribute 'owncloud/config/dbname',
:display_name => 'ownCloud Database Name',
:description => 'Name of the ownCloud database',
Expand All @@ -315,13 +301,6 @@
:type => 'string',
:required => 'optional'

attribute 'owncloud/config/dbrootpassword',
:display_name => 'Database Root Password',
:description => 'Database admin password to access a database instance',
:calculated => true,
:type => 'string',
:required => 'optional'

attribute 'owncloud/config/dbhost',
:display_name => 'ownCloud Database Host',
:description => 'Host running the ownCloud database',
Expand Down Expand Up @@ -451,3 +430,25 @@
:choice => [ 'true', 'false' ],
:type => 'string',
:required => 'optional'

attribute 'owncloud/databse/rootpassword',
:display_name => 'Database Root Password',
:description => 'Database admin password to access a database instance',
:calculated => true,
:type => 'string',
:required => 'optional'

attribute 'owncloud/database/instance',
:display_name => 'mySQL database instance name',
:description => 'mySQL database instance name to run by the mysql_service lwrp from the mysql cookbook',
:type => 'string',
:required => 'optional',
:default => '"default"'

attribute 'owncloud/database/version',
:display_name => 'mySQL server version',
:description => 'mySQL version to install by the mysql_service lwrp. Refer to https://github.com/chef-cookbooks/mysql#platform-support',
:type => 'string',
:required => 'optional',
:default => 'nil'

16 changes: 8 additions & 8 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
if node['owncloud']['config']['dbpassword'].nil? and node['owncloud']['config']['dbtype'] != 'sqlite'
Chef::Application.fatal!('You must set owncloud\'s database password in chef-solo mode.')
end
if node['owncloud']['config']['dbrootpassword'].nil? and node['owncloud']['config']['dbtype'] != 'sqlite'
if node['owncloud']['database']['rootpassword'].nil? and node['owncloud']['config']['dbtype'] != 'sqlite'
Chef::Application.fatal!('You must set the database admin password in chef-solo mode.')
end
if node['owncloud']['admin']['pass'].nil?
Expand All @@ -80,7 +80,7 @@
else
unless node['owncloud']['config']['dbtype'] == 'sqlite'
node.set_unless['owncloud']['config']['dbpassword'] = secure_password
node.set_unless['owncloud']['config']['dbrootpassword'] = secure_password
node.set_unless['owncloud']['database']['rootpassword'] = secure_password
end
node.set_unless['owncloud']['admin']['pass'] = secure_password
node.save
Expand Down Expand Up @@ -121,23 +121,23 @@
when 'mysql'
if %w{ localhost 127.0.0.1 }.include?(node['owncloud']['config']['dbhost'])
# Install MySQL
dbinstance = node['owncloud']['config']['dbinstance']
dbinstance = node['owncloud']['database']['instance']

mysql2_chef_gem dbinstance do
action :install
end
mysql_service dbinstance do
version node['owncloud']['config']['dbversion']
version node['owncloud']['database']['version']
bind_address '127.0.0.1'
port '3306'
initial_root_password node['owncloud']['config']['dbrootpassword']
initial_root_password node['owncloud']['database']['rootpassword']
action [:create, :start]
end

mysql_connection_info = {
:host => '127.0.0.1',
:username => 'root',
:password => node['owncloud']['config']['dbrootpassword']
:password => node['owncloud']['database']['rootpassword']
}

mysql_database node['owncloud']['config']['dbname'] do
Expand All @@ -160,10 +160,10 @@
if ::Chef::Config[:solo]
attr = node['postgresql'] && node['postgresql']['password'] && node['postgresql']['password']['postgres']
unless attr
node.set['postgresql']['password']['postgres'] = node['owncloud']['config']['dbrootpassword']
node.set['postgresql']['password']['postgres'] = node['owncloud']['database']['rootpassword']
end
else
node.set_unless['postgresql']['password']['postgres'] = node['owncloud']['config']['dbrootpassword']
node.set_unless['postgresql']['password']['postgres'] = node['owncloud']['database']['rootpassword']
end

include_recipe 'postgresql::server'
Expand Down
2 changes: 1 addition & 1 deletion test/kitchen/cookbooks/owncloud_test/recipes/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
#

node.default['owncloud']['config']['dbrootpassword'] = 'vagrant_root'
node.default['owncloud']['database']['rootpassword'] = 'vagrant_root'
node.default['owncloud']['config']['dbpassword'] = 'database_pass'

include_recipe 'owncloud_test::common'
2 changes: 1 addition & 1 deletion test/kitchen/cookbooks/owncloud_test/recipes/nginx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

node.default['owncloud']['web_server'] = 'nginx'

node.default['owncloud']['config']['dbrootpassword'] = 'vagrant_root'
node.default['owncloud']['database']['rootpassword'] = 'vagrant_root'

node.default['owncloud']['config']['dbpassword'] = 'database_pass'

Expand Down
2 changes: 1 addition & 1 deletion test/kitchen/cookbooks/owncloud_test/recipes/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
#

node.default['owncloud']['config']['dbrootpassword'] = 'vagrant_postgres'
node.default['owncloud']['database']['rootpassword'] = 'vagrant_postgres'

node.default['owncloud']['config']['dbpassword'] = 'database_pass'
node.default['owncloud']['config']['dbtype'] = 'pgsql'
Expand Down

0 comments on commit f7d467d

Please sign in to comment.