Last active
December 12, 2015 07:09
-
-
Save alesya-h/4734672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cookbooks/nginx/recipes/pacemaker.rb | |
include_recipe 'nginx' | |
service 'nginx' do | |
action 'disable' | |
end | |
pacemaker "nginx" do | |
Chef::Log.info c = <<"END" | |
cib reset chef | |
cib use chef | |
configure | |
property stonith-enabled=false | |
primitive DrbdNginx ocf:linbit:drbd \\ | |
params drbd_resource=nginx \\ | |
op monitor interval=10s | |
ms DrbdNginxMs DrbdNginx \\ | |
meta master-max=1 master-node-max=1 \\ | |
clone-max=2 clone-node-max=1 \\ | |
notify=true | |
location NoDrbdOnNode3 DrbdNginx -inf: node3 | |
primitive DrbdNginxFs ocf:heartbeat:Filesystem \\ | |
params device="#{node[:drbd][:resources][:nginx][:dev]}" \\ | |
directory="#{node[:drbd][:resources][:nginx][:mount]}" \\ | |
fstype=ext4 | |
colocation DrbdNginxFs-with-DrbdNginxMs_Master \\ | |
inf: DrbdNginxFs DrbdNginxMs:Master | |
order DrbdNginxFs-after-DrbdNginxMs_Master \\ | |
inf: DrbdNginxMs:promote DrbdNginxFs:start | |
primitive Nginx ocf:heartbeat:nginx \\ | |
op monitor interval=10s | |
colocation Nginx-with-DrbdNginxFs inf: DrbdNginxFs Nginx | |
order Nginx-after-DrbdNginxFs inf: DrbdNginxFs Nginx | |
primitive NginxIp ocf:heartbeat:IPaddr \\ | |
params ip=\"#{node[:pacemaker][:nginx][:ip]}\" \\ | |
cidr_netmask=32 \\ | |
op monitor interval=30s | |
colocation Nginx-with-NginxIp inf: Nginx NginxIp | |
end | |
cib commit chef | |
END | |
code c | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cookbooks/pacemaker/providers/default.rb | |
action :run do | |
script "pacemaker_#{new_resource.name}" do | |
interpreter "crm" | |
flags "<" | |
code new_resource.code | |
only_if { | |
Chef::Log.info master_node=`crm node show|grep -v offline`.split(":").first | |
master_node == node.name | |
} | |
returns [0,1] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions :run | |
default_action :run | |
attribute :name, :kind_of => String, :name_attribute => true | |
attribute :code, :kind_of => String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to run some script (pacemaker configuration, to be precise) on one node of a cluster. This node have to be both online pacemaker node and one of the nodes with this configuration resource (or at least with same recipe this resource defined in). Current version selects node to run the code as first online node of the cluster, but it don't know whether the code will run on that node. What would you suggest me to do?