Now lets converge and verify if the cookbook is working as expected
We can use chef common attributes such as only_if and not_if to avoid writing ruby conditional statements Refer Here. Refer Here for usage of only_if gaurd
We have one more problem, whenever we converge apache server is getting restarted. It should only restart
in the case of new installation
When info.php is changed.
In chef we have a concept called as notifications where one resource can notify other resource to execute Refer Here for official docs
Lets implement notification functionality Refer Here
Notifies can notify only one resource. If you have to notify multiple resources, then use subscribes over notify Refer Here
file '/tmp/txt' do
action :create
end
service 'apache'
action :nothing
subscribes :restart, 'file[/tmp/txt]'
end
service 'tomcat8'
action :nothing
subscribes :restart, 'file[/tmp/txt]'
end
In the lampserver i have deleted the unnecessary files Refer Here
Now we have only one problem the content of info.php is only one line so we are using content property. What if the content is a large file with multiple lines
file '/var/www/html/info.php' do
content '<?php phpinfo(); ?>'
action :create
notifies :restart, "service[#{package_name}]"
end
We can solve above problem by creating file to be copied in the cookbook itself and use the file in cookbook to create file in remote node.
Lets generate a file called as info.php in chef cookbook. Refer Here for the changeset