public
Description: master respository for deprec - deployment recipes for capistrano
Homepage: http://www.deprec.org/
Clone URL: git://github.com/mbailey/deprec.git
deprec / lib / deprec / recipes / mysql.rb
100644 116 lines (90 sloc) 3.274 kb
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright 2006-2008 by Mike Bailey. All rights reserved.
Capistrano::Configuration.instance(:must_exist).load do
  namespace :deprec do
    namespace :mysql do
      
      # Installation
      
      desc "Install mysql"
      task :install, :roles => :db do
        install_deps
        # symlink_mysql_sockfile # XXX still needed?
      end
      
      # Install dependencies for Mysql
      task :install_deps, :roles => :db do
        apt.install( {:base => %w(mysql-server mysql-client)}, :stable )
      end
      
      # task :symlink_mysql_sockfile, :roles => :db do
      # # rails puts "socket: /tmp/mysql.sock" into config/database.yml
      # # this is not the location for our ubuntu's mysql socket file
      # # so we create this link to make deployment using rails defaults simpler
      # sudo "ln -sf /var/run/mysqld/mysqld.sock /tmp/mysql.sock"
      # end
      
      # Configuration
      
      SYSTEM_CONFIG_FILES[:mysql] = [
        
        {:template => "my.cnf.erb",
         :path => '/etc/mysql/my.cnf',
         :mode => 0644,
         :owner => 'root:root'}
      ]
      
      desc "Generate configuration file(s) for mysql from template(s)"
      task :config_gen do
        SYSTEM_CONFIG_FILES[:mysql].each do |file|
          deprec2.render_template(:mysql, file)
        end
      end
      
      desc "Push mysql config files to server"
      task :config, :roles => :db do
        deprec2.push_configs(:mysql, SYSTEM_CONFIG_FILES[:mysql])
      end
      
      task :activate, :roles => :db do
        send(run_method, "update-rc.d mysql defaults")
      end
      
      task :deactivate, :roles => :db do
        send(run_method, "update-rc.d -f mysql remove")
      end
      
      # Control
      
      desc "Start Mysql"
      task :start, :roles => :db do
        send(run_method, "/etc/init.d/mysql start")
      end
      
      desc "Stop Mysql"
      task :stop, :roles => :db do
        send(run_method, "/etc/init.d/mysql stop")
      end
      
      desc "Restart Mysql"
      task :restart, :roles => :db do
        send(run_method, "/etc/init.d/mysql restart")
      end
      
      desc "Reload Mysql"
      task :reload, :roles => :db do
        send(run_method, "/etc/init.d/mysql reload")
      end
      
      
      task :backup, :roles => :db do
      end
      
      task :restore, :roles => :db do
      end
            
    end
  end
end
 
#
# Setup replication
#
 
# setup user for repl
# GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.yourdomain.com' IDENTIFIED BY 'slavepass';
 
# get current position of binlog
# mysql> FLUSH TABLES WITH READ LOCK;
# Query OK, 0 rows affected (0.00 sec)
#
# mysql> SHOW MASTER STATUS;
# +------------------+----------+--------------+------------------+
# | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
# +------------------+----------+--------------+------------------+
# | mysql-bin.000012 | 296 | | |
# +------------------+----------+--------------+------------------+
# 1 row in set (0.00 sec)
#
# # get current data
# mysqldump --all-databases --master-data >dbdump.db
#
# UNLOCK TABLES;
 
 
# Replication Features and Issues
# http://dev.mysql.com/doc/refman/5.0/en/replication-features.html