|
31 | 31 | raise "Remote node #{remote_host} not found!" if remote_nodes.empty? |
32 | 32 | remote = remote_nodes.first |
33 | 33 |
|
34 | | - template "/etc/drbd.d/#{name}.res" do |
| 34 | + drbd_resource_template = template "/etc/drbd.d/#{name}.res" do |
35 | 35 | cookbook "drbd" |
36 | 36 | source "resource.erb" |
37 | 37 | variables( |
|
47 | 47 | owner "root" |
48 | 48 | group "root" |
49 | 49 | action :nothing |
50 | | - end.run_action(:create) |
| 50 | + end |
| 51 | + drbd_resource_template.run_action(:create) |
51 | 52 |
|
52 | 53 | # first pass only, initialize drbd |
53 | 54 | # for disks re-usage from old resources we will run with force option |
54 | | - p = execute "drbdadm -- --force create-md #{name}" do |
55 | | - only_if do |
56 | | - overview = DrbdOverview.get(name) |
57 | | - !overview.nil? && overview["state"] == "Unconfigured" |
58 | | - end |
| 55 | + drbdadm_create_md = execute "drbdadm -- --force create-md #{name}" do |
| 56 | + only_if { drbd_resource_template.updated_by_last_action? } |
59 | 57 | action :nothing |
60 | 58 | end |
61 | | - p.run_action(:run) |
| 59 | + drbdadm_create_md.run_action(:run) |
62 | 60 |
|
63 | | - if p.updated_by_last_action? |
64 | | - # we would usually do something like: |
65 | | - # notifies :restart, "service[drbd]", :immediately |
66 | | - # in the execute above; but the notification doesn't work (probably because |
67 | | - # we're already in a LWRP). So we hack around this. |
68 | | - service "drbd(#{name})" do |
69 | | - service_name "drbd" |
70 | | - action :nothing |
71 | | - end.run_action(:restart) |
| 61 | + drbdadm_up = execute "drbdadm up #{name}" do |
| 62 | + only_if { drbd_resource_template.updated_by_last_action? } |
| 63 | + action :nothing |
72 | 64 | end |
| 65 | + drbdadm_up.run_action(:run) |
73 | 66 |
|
74 | | - overview = DrbdOverview.get(name) |
75 | | - if !overview.nil? && overview["state"] != "Unconfigured" && overview["primary"].nil? |
76 | | - # claim primary based off of master |
77 | | - execute "drbdadm -- --overwrite-data-of-peer primary #{name}" do |
78 | | - only_if { master } |
79 | | - action :nothing |
80 | | - end.run_action(:run) |
| 67 | + # claim primary based off of master |
| 68 | + execute "drbdadm -- --overwrite-data-of-peer primary #{name}" do |
| 69 | + only_if { drbd_resource_template.updated_by_last_action? && master } |
| 70 | + action :nothing |
| 71 | + end.run_action(:run) |
81 | 72 |
|
82 | | - # you may now create a filesystem on the device, use it as a raw block device |
83 | | - # for disks re-usage from old resources we will run with force option |
84 | | - execute "mkfs -t #{fstype} -f #{device}" do |
85 | | - only_if { master } |
86 | | - action :nothing |
87 | | - end.run_action(:run) |
88 | | - end |
| 73 | + # you may now create a filesystem on the device, use it as a raw block device |
| 74 | + # for disks re-usage from old resources we will run with force option |
| 75 | + execute "mkfs -t #{fstype} -f #{device}" do |
| 76 | + only_if { drbd_resource_template.updated_by_last_action? && master } |
| 77 | + action :nothing |
| 78 | + end.run_action(:run) |
89 | 79 |
|
90 | 80 | unless mount.nil? or mount.empty? |
91 | 81 | directory mount do |
|
100 | 90 | action :nothing |
101 | 91 | end.run_action(:mount) |
102 | 92 | end |
| 93 | +end |
103 | 94 |
|
| 95 | +action :wait do |
| 96 | + name = new_resource.name |
104 | 97 | begin |
105 | 98 | Timeout.timeout(20) do |
106 | 99 | while true |
|
0 commit comments