dust-deploy 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/changelog.md CHANGED
@@ -1,6 +1,26 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ 0.5.0
5
+ ------------
6
+
7
+ - improved mysql recipe. it now accepts every option (change your configuration accordingly)
8
+
9
+ recipes:
10
+ mysql:
11
+ mysqld:
12
+ bind-address: 0.0.0.0
13
+ port: 1234
14
+ mysqldump:
15
+ quick: false
16
+ isamchk:
17
+ key_buffer: 128M
18
+
19
+ - fixes a bug in the ssh_authorized_keys recipe with ~user shortcut, uses new get_home method now
20
+ - fixes a bug in the duplicity recipe occuring when using yaml files with multiple hostnames
21
+ - fixes a bug where @node.get_home was returning nil
22
+
23
+
4
24
  0.4.5
5
25
  ------------
6
26
 
@@ -4,7 +4,7 @@ class BasicSetup < Recipe
4
4
  # install some basic packages
5
5
  ::Dust.print_msg "installing basic packages\n"
6
6
 
7
- @node.install_package 'screen', :indent => 2
7
+ @node.install_package 'tmux', :indent => 2
8
8
  @node.install_package 'rsync', :indent => 2
9
9
  @node.install_package 'psmisc', :indent => 2 if @node.uses_apt?
10
10
 
@@ -8,9 +8,11 @@ class Duplicity < Recipe
8
8
 
9
9
  # return if config simply says 'remove'
10
10
  return if @config == 'remove'
11
-
12
- @config.each do |scenario, config|
13
-
11
+
12
+ @config.each do |scenario, c|
13
+ # cloning is necessary if we have configurations with multiple hostnames
14
+ config = c.clone
15
+
14
16
  # if directory config options is not given, use hostname-scenario
15
17
  config['directory'] ||= "#{@node['hostname']}-#{scenario}"
16
18
 
@@ -36,7 +38,7 @@ class Duplicity < Recipe
36
38
  ::Dust.print_msg 'checking if ssh key is in known_hosts'
37
39
  unless ::Dust.print_result @node.exec("grep -q '#{config['hostkey']}' /root/.ssh/known_hosts")[:exit_code] == 0
38
40
  @node.mkdir '/root/.ssh', :indent => 2
39
- @node.append '/root/.ssh/known_hosts', config['hostkey'], :indent => 2
41
+ @node.append '/root/.ssh/known_hosts', "#{config['hostkey']}\n", :indent => 2
40
42
  end
41
43
  end
42
44
 
@@ -4,41 +4,98 @@ class Mysql < Recipe
4
4
  return unless @node.uses_apt? :quiet=>false
5
5
  @node.install_package 'mysql-server'
6
6
 
7
+ @config = default_config.deep_merge @config
8
+
7
9
  ::Dust.print_msg "configuring mysql\n"
10
+ ::Dust.print_ok "listen on #{@config['mysqld']['bind-address']}:#{@config['mysqld']['port']}", :indent => 2
8
11
 
9
- # defaults
10
- @config['bind_address'] ||= '127.0.0.1'
11
- @config['port'] ||= 3306
12
+ @config['mysqld']['innodb_buffer_pool_size'] = get_innodb_buffer_pool_size
13
+ ::Dust.print_ok "set innodb buffer pool to '#{@config['mysqld']['innodb_buffer_pool_size']}'", :indent => 2
12
14
 
13
- ::Dust.print_ok "listen on #{@config['bind_address']}:#{@config['port']}", :indent => 2
14
-
15
- @config['innodb_file_per_table'] ||= 1
16
- @config['innodb_thread_concurrency'] ||= 0
17
- @config['innodb_flush_log_at_trx_commit'] ||= 1
15
+ @node.write '/etc/mysql/my.cnf', generate_my_cnf
16
+ @node.chmod '644', '/etc/mysql/my.cnf'
18
17
 
18
+ @node.restart_service 'mysql' if options.restart?
19
+ @node.reload_service 'mysql' if options.reload?
20
+ end
21
+
22
+
23
+ private
24
+
25
+ def default_config
26
+ { 'client' => {
27
+ 'port' => 3306,
28
+ 'socket' => '/var/run/mysqld/mysqld.sock'
29
+ },
30
+ 'mysqld_safe' => {
31
+ 'socket' => '/var/run/mysqld/mysqld.sock',
32
+ 'nice' => 0
33
+ },
34
+ 'mysqld' => {
35
+ 'bind-address' => '127.0.0.1',
36
+ 'port' => 3306,
37
+ 'user' => 'mysql',
38
+ 'pid-file' => '/var/run/mysqld/mysqld.pid',
39
+ 'socket' => '/var/run/mysqld/mysqld.sock',
40
+ 'language' => '/usr/share/mysql/english',
41
+ 'basedir' => '/usr',
42
+ 'datadir' => '/var/lib/mysql',
43
+ 'tmpdir' => '/tmp',
44
+ 'skip-external-locking' => true,
45
+ 'key_buffer' => '16M',
46
+ 'max_allowed_packet' => '16M',
47
+ 'thread_stack' => '192K',
48
+ 'thread_cache_size' => 8,
49
+ 'myisam-recover' => 'BACKUP',
50
+ 'query_cache_limit' => '1M',
51
+ 'query_cache_size' => '16M',
52
+ 'expire_logs_days' => 10,
53
+ 'max_binlog_size' => '100M',
54
+ 'innodb_file_per_table' => 1,
55
+ 'innodb_thread_concurrency' => 0,
56
+ 'innodb_flush_log_at_trx_commit' => 1
57
+ },
58
+ 'mysqldump' => {
59
+ 'quick' => true,
60
+ 'quote-names' => true,
61
+ 'max_allowed_packet' => '16M'
62
+ },
63
+ 'mysql' => {},
64
+ 'isamchk' => {
65
+ 'key_buffer' => '16M',
66
+ }
67
+ }
68
+ end
69
+
70
+ def get_innodb_buffer_pool_size
19
71
  # allocate 70% of the available ram to mysql
20
72
  # but leave max 1gb to system
21
- unless @config['innodb_buffer_pool_size']
73
+ unless @config['mysqld']['innodb_buffer_pool_size']
22
74
  ::Dust.print_msg 'autoconfiguring innodb buffer size', :indent => 2
23
75
  @node.collect_facts :quiet => true
24
-
76
+
25
77
  # get system memory (in kb)
26
78
  system_mem = ::Dust.convert_size @node['memorysize']
27
-
79
+
28
80
  # allocate 70% of the available ram to mysql
29
81
  buffer_pool = (system_mem * 0.70).to_i / 1024
30
-
31
- @config['innodb_buffer_pool_size'] = "#{buffer_pool}M"
82
+
32
83
  ::Dust.print_ok
84
+ "#{buffer_pool}M"
33
85
  end
34
-
35
- ::Dust.print_ok "setting innodb buffer pool to '#{@config['innodb_buffer_pool_size']}'", :indent => 2
36
-
37
- @node.deploy_file "#{@template_path}/my.cnf", '/etc/mysql/my.cnf', :binding => binding
38
- @node.chmod '644', '/etc/mysql/my.cnf'
39
-
40
- @node.restart_service 'mysql-server' if options.restart?
41
- @node.reload_service 'mysql-server' if options.reload?
86
+ end
87
+
88
+ def generate_my_cnf
89
+ my_cnf = ''
90
+ @config.each do |category, config|
91
+ my_cnf.concat "[#{category}]\n"
92
+ config.each { |key, value| my_cnf.concat "#{key} = #{value}\n" }
93
+ my_cnf.concat "\n"
94
+ end
95
+
96
+ # add includedir
97
+ my_cnf.concat "!includedir /etc/mysql/conf.d/\n"
98
+ my_cnf
42
99
  end
43
100
  end
44
101
 
@@ -42,15 +42,16 @@ class SshAuthorizedKeys < Recipe
42
42
  # create user, if not existent
43
43
  next unless @node.create_user user
44
44
 
45
+ home = @node.get_home user
45
46
  # check and create necessary directories
46
- next unless @node.mkdir("~#{user}/.ssh")
47
+ next unless @node.mkdir("#{home}/.ssh")
47
48
 
48
49
  # deploy authorized_keys
49
- next unless @node.write "~#{user}/.ssh/authorized_keys", authorized_keys
50
+ next unless @node.write "#{home}/.ssh/authorized_keys", authorized_keys
50
51
 
51
52
  # check permissions
52
- @node.chown "#{user}:#{user}", "~#{user}/.ssh"
53
- @node.chmod '0644', "~#{user}/.ssh/authorized_keys"
53
+ @node.chown "#{user}:#{user}", "#{home}/.ssh"
54
+ @node.chmod '0644', "#{home}/.ssh/authorized_keys"
54
55
  end
55
56
 
56
57
  # remove authorized_keys files for all other users
@@ -60,8 +61,9 @@ class SshAuthorizedKeys < Recipe
60
61
  ::Dust.print_msg "deleting other authorized_keys files\n"
61
62
  @node.get_system_users(:quiet => true).each do |user|
62
63
  next if users.keys.include? user
63
- if @node.file_exists? "~#{user}/.ssh/authorized_keys", :quiet => true
64
- @node.rm "~#{user}/.ssh/authorized_keys", :indent => 2
64
+ home = @node.get_home user
65
+ if @node.file_exists? "#{home}/.ssh/authorized_keys", :quiet => true
66
+ @node.rm "#{home}/.ssh/authorized_keys", :indent => 2
65
67
  end
66
68
  end
67
69
  end
data/lib/dust/server.rb CHANGED
@@ -80,8 +80,10 @@ module Dust
80
80
  f.print content
81
81
  f.close
82
82
 
83
- Dust.print_result scp(f.path, destination, :quiet => true), options
83
+ ret = Dust.print_result scp(f.path, destination, :quiet => true), options
84
84
  f.unlink
85
+
86
+ ret
85
87
  end
86
88
 
87
89
  def append destination, newcontent, options = {}
@@ -420,6 +422,19 @@ module Dust
420
422
  Dust.print_result exec(cmd)[:exit_code], options
421
423
  end
422
424
 
425
+ # returns the home directory of this user
426
+ def get_home user, options = {}
427
+ options = default_options(:quiet => true).merge options
428
+
429
+ Dust.print_msg "getting home directory of #{user}"
430
+ ret = exec "grep #{user} /etc/passwd |cut -d':' -f6"
431
+ if Dust.print_result ret[:exit_code]
432
+ return ret[:stdout].chomp
433
+ else
434
+ return false
435
+ end
436
+ end
437
+
423
438
  # collect additional system facts using puppets facter
424
439
  def collect_facts options = {}
425
440
  options = default_options.merge options
data/lib/dust/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dust
2
- VERSION = "0.4.5"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
7
  - 5
9
- version: 0.4.5
8
+ - 0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - kris kechagia
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-01-23 00:00:00 +01:00
17
+ date: 2012-01-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency