{"id":26367,"date":"2015-09-09T07:52:44","date_gmt":"2015-09-09T02:22:44","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=26367"},"modified":"2016-01-19T13:32:58","modified_gmt":"2016-01-19T08:02:58","slug":"chef-recipe-to-deploy-grails-war-on-a-new-production-server","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/chef-recipe-to-deploy-grails-war-on-a-new-production-server\/","title":{"rendered":"Chef recipe to deploy Grails war on a new production server"},"content":{"rendered":"<p>Chef, a configuration management tool not only brings a lot of functionality to <a title=\"DevOps on AWS\" href=\"http:\/\/www.tothenew.com\/devops-aws\">DevOps<\/a> but can also ease the process of multiple deployments at the same time. A major use case of <a title=\"Chef DevOps\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\">Chef<\/a> is to deploy the latest code on your old as well as new production servers. Chef, with its enormously great functionalities, can even replace continuous integration tools like Jenkins for automated deployments.<\/p>\n<p>To have a basic understanding of Chef, you can <a href=\"http:\/\/www.tothenew.com\/blog\/understanding-chef-and-writing-cookbooks\/\">refer to this blog<\/a>. Below is an explanation of a Chef recipe which do the following tasks step by step on a new production server:-<\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Update the system libraries<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Installing Nginx web server<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Installing Tomcat7 application server<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Copy and replace the default Nginx virtual host file with self-made Nginx virtual host file (to proxy_pass to tomcat7)<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Copy and deploy the new war file in tomcat7 webapps folder from Chef-server to node<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Restart tomcat and Nginx service<\/span><\/li>\n<\/ol>\n<p><strong><strong>\u00a0<\/strong><\/strong><b>Note :-<\/b> You can modify the chef recipe just to deploy the war file in tomcat followed by restarting tomcat server. I am assuming that the production server is new and so all the utilities have to be installed from the scratch.<\/p>\n<p><strong><strong>\u00a0<\/strong><\/strong><b>Step 1:- Creating cookbook sample_war_deployment<\/b><\/p>\n<p style=\"padding-left: 30px\"><strong><strong>\u00a0<\/strong><\/strong>knife cookbook create sample_war_deployment<\/p>\n<p><strong><strong>\u00a0<\/strong><\/strong><b>Step 2:- Copying required files in cookbook directory<\/b><\/p>\n<p style=\"padding-left: 30px\"><strong><strong>\u00a0<\/strong><\/strong>As we need to transfer and replace two files from chef-server to the node, so both of them have to be present in the files\/default directory of the cookbook. So, I am creating a simple Nginx virtual host file to proxy_pass to tomcat7 whose path will be mentioned in my recipe as the source to Nginx default cookbook file which needs to be replaced.<\/p>\n<p style=\"padding-left: 30px\">\n[js]<br \/>\n  server{<br \/>\n  \t\tlisten 80;<\/p>\n<p>  server_name localhost;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0location \/ {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0proxy_pass http:\/\/localhost:8080;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<br \/>\n      }<br \/>\n[\/js]<\/p>\n<p>&nbsp;<\/p>\n<p>We also need to copy our sample.war file in this directory and rename it as ROOT.war.<\/p>\n<p><b>Step 3: &#8211; Creating recipe by editing default.rb\u00a0\u00a0<\/b><\/p>\n<p>[js]<\/p>\n<p>###updating libraries###<br \/>\nexecute &quot;apt-get-update&quot; do<br \/>\n  command &quot;apt-get update&quot;<br \/>\n  ignore_failure true<br \/>\nend<\/p>\n<p> ###installing nginx###<br \/>\npackage &#8216;nginx&#8217; do<br \/>\n        action :install<br \/>\nend<\/p>\n<p> ###installing tomcat7###<br \/>\npackage &#8216;tomcat7&#8217; do<br \/>\n        action :install<br \/>\nend<\/p>\n<p>###replacing nginx default vhost file by vhost file in our cookbook files\/default directory###<br \/>\ncookbook_file &quot;\/etc\/nginx\/sites-enabled\/default&quot; do<br \/>\n  source &quot;default&quot;<br \/>\n  mode &quot;0644&quot;<br \/>\n  notifies :restart, &quot;service[nginx]&quot;<br \/>\nend<\/p>\n<p>###Clearing tomcat7 webapps ROOT folder###<br \/>\nbash &#8216;Clearing tomcat7 webapps ROOT folder&#8217; do<br \/>\n  user &#8216;root&#8217;<br \/>\n  cwd &#8216;\/home\/ubuntu&#8217;<br \/>\n  code &lt;&lt;-EOH<br \/>\n  sudo rm -rf \/var\/lib\/tomcat7\/webapps\/ROOT<br \/>\n  EOH<br \/>\nend<\/p>\n<p>###copying and replacing existing ROOT.war with new ROOT.war in our cookbook files\/default directory###<br \/>\ncookbook_file &quot;\/var\/lib\/tomcat7\/webapps\/ROOT.war&quot; do<br \/>\n  source &quot;ROOT.war&quot;<br \/>\n  mode &quot;0644&quot;<br \/>\n  notifies :restart, &quot;service[nginx]&quot;<br \/>\n  notifies :restart, &quot;service[tomcat7]&quot;<br \/>\nend<\/p>\n<p>###restarting tomcat7 service###<br \/>\nservice &#8216;tomcat7&#8217; do<br \/>\n  supports :restart =&gt; true<br \/>\nend<\/p>\n<p>###restarting nginx web server###<br \/>\nservice &#8216;nginx&#8217; do<br \/>\n  supports :restart =&gt; true<br \/>\n  supports :reload =&gt;true<br \/>\nend<\/p>\n<p>[\/js]<\/p>\n<p>&nbsp;<\/p>\n<p><b>Step 4: &#8211; Uploading cookbook on to the Chef Server and adding recipe into the node\u2019s run list<\/b><\/p>\n<p style=\"padding-left: 30px\"><strong><strong>\u00a0<\/strong><\/strong>knife cookbook upload sample_war_deployment<br \/>\nknife node run_list add chef-node &#8216;recipe[sample_war_deployment]&#8217;<\/p>\n<p><strong><strong>\u00a0<\/strong><\/strong><b>Step 5: &#8211; Running Chef-client on the node<\/b><\/p>\n<p style=\"padding-left: 30px\">Execute the recipe on the node by typing the below command:-<br \/>\nsudo chef-client<\/p>\n<p>After the successful execution of the recipe, you will find all the required services installed and running in an appropriate manner on the server. When you hit your IP address, you will find your war file deployed successfully on tomcat with Nginx doing the proxy pass work.<\/p>\n<p><strong><strong>\u00a0<\/strong><\/strong>Chef is a tool to carry out automated deployment tasks in an easy way. You can also deploy same war file simultaneously on multiple nodes to take deployments to a next level.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Chef, a configuration management tool not only brings a lot of functionality to DevOps but can also ease the process of multiple deployments at the same time. A major use case of Chef is to deploy the latest code on your old as well as new production servers. Chef, with its enormously great functionalities, can [&hellip;]<\/p>\n","protected":false},"author":170,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1174,2348,7],"tags":[2346,2341,2347,2342,2344,2345,2343],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/26367"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/170"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=26367"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/26367\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=26367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=26367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=26367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}