Class: Snapback::App::Mount

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/snapback/app/mount.rb

Instance Method Summary collapse

Instance Method Details

#goObject



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
# File 'lib/snapback/app/mount.rb', line 8

def go
  volume_group_name = "#{$config['lvm']['volume_group']}"
  logical_volume_name = "#{$config['lvm']['prefix_database']}-#{$options[:database]}"
  mount_dir = get_mount_dir $options[:database]
  mysql_data_dir = $database.get_data_dir

  exec_flush

  # Stop the MySQL Server
  $database.server_stop

  on_rollback lambda {
    $database.server_start
  }

  # Create a new directory for where the MySQL database can be mounted
  # mkdir /mnt/mysql/{dbName};

  if !File.directory? mount_dir then
    run "Make mount directory", 
      "mkdir #{mount_dir}"

    on_rollback lambda {
      run "Removing mount directory",
        "rmdir #{$mount_dir}"
    }

    run "Changing permissions of mount directory",
      "chmod 0777 #{mount_dir}"
  end
  
  # # Mount the new logical volume
  # mount /dev/{vgName}/mysql-{dbName} /mnt/mysql/{dbName};
  exec_mount "/dev/#{volume_group_name}/#{logical_volume_name}", mount_dir

  # # Symbolic-link the MySQL data directory to the new logical volume
  # ln -s /mnt/mysql/{dbName} {mysql-data-dir}/{dbName}/
  exec_link "#{mysql_data_dir}/#{$options[:database]}", mount_dir

  # # Change the permissions & ownership to MySQL 
  # chown -R mysql:mysql {mysql-data-dir}/{dbName}/
  # chown -R mysql:mysql /mnt/mysql/{dbName}/
  exec_chown "#{mysql_data_dir}/#{$options[:database]}"
  exec_chown mount_dir

  # Stop the MySQL Server
  $database.server_start

  on_rollback lambda {
    $database.server_stop
  }
end