{"id":3349,"date":"2024-03-13T15:45:33","date_gmt":"2024-03-13T15:45:33","guid":{"rendered":"https:\/\/platinumsupport.in\/blog\/?p=3349"},"modified":"2024-09-21T04:36:23","modified_gmt":"2024-09-21T04:36:23","slug":"script-to-restart-web-service","status":"publish","type":"post","link":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/","title":{"rendered":"Script to restart web service"},"content":{"rendered":"\n<p><br>Here is the simple bash script that checks if a website is running on a Linux or Bitnami server and restarts the web service if it&#8217;s not.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\r\n\r\nWEBSITE_URL=\"http:\/\/example.com\"\r\nWEBSITE_STATUS=$(curl -IsS ${WEBSITE_URL} | head -n 1 | cut -d \" \" -f2)\r\n\r\nif &#91; \"${WEBSITE_STATUS}\" != \"200\" ]; then\r\n    echo \"Website is not responding. Restarting web service...\"\r\n    sudo \/opt\/bitnami\/ctlscript.sh restart apache   \/\/ this fro bitnami\n\r    sudo service apache2 restart    \/ this is for Linux running with Apache2\n    sleep 10 # Give some time for the service to restart\r\n    NEW_WEBSITE_STATUS=$(curl -IsS ${WEBSITE_URL} | head -n 1 | cut -d \" \" -f2)\r\n    if &#91; \"${NEW_WEBSITE_STATUS}\" = \"200\" ]; then\r\n        echo \"Web service restarted successfully.\"\r\n    else\r\n        echo \"Failed to restart web service. Please check manually.\"\r\n    fi\r\nelse\r\n    echo \"Website is running normally.\"\r\nfi\r\n<\/code><\/pre>\n\n\n\n<p>Here&#8217;s what the script does:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Defines the URL of the website to check (WEBSITE_URL).<\/li>\n\n\n\n<li>Uses curl to send a HEAD request to the website and captures the HTTP status code (200 for OK).<\/li>\n\n\n\n<li>If the status code is not 200, it assumes the website is not responding and restarts the Apache web service using the Bitnami control script.<\/li>\n\n\n\n<li>After restarting the service, it waits for 10 seconds to allow time for the service to start.<\/li>\n\n\n\n<li>Checks the website status again. If it returns a 200 status code, it confirms that the web service has restarted successfully.<\/li>\n\n\n\n<li>If the website still doesn&#8217;t respond after restarting the service, it prints a failure message.<\/li>\n<\/ol>\n\n\n\n<p>Make sure to replace &#8220;http:\/\/example.com&#8221; with the actual URL of your website. Also, ensure that the path to the Bitnami control script (\/opt\/bitnami\/ctlscript.sh) is correct for your installation.<\/p>\n\n\n\n<p>Save this script to a file (e.g., check_website.sh), make it executable (chmod +x check_website.sh), and then you can schedule it to run periodically using cron or any other scheduling tool you prefer. For example, you can run it every 5 minutes by adding the following line to your crontab:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/5 * * * * \/path\/to\/check_website.sh\r<\/code><\/pre>\n\n\n\n<p>Replace \/path\/to\/check_website.sh with the actual path to your script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is the simple bash script that checks if a website is running on a Linux or Bitnami server and restarts the web service if it&#8217;s not. Here&#8217;s what the script does: Make sure to replace &#8220;http:\/\/example.com&#8221; with the actual URL of your website. Also, ensure that the path to the Bitnami control script (\/opt\/bitnami\/ctlscript.sh) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3349","post","type-post","status-publish","format-standard","hentry","category-cpanel-whm-technical-support-solutions"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.13 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Script to restart web service - Knowledge Base<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Script to restart web service\" \/>\n<meta property=\"og:description\" content=\"Here is the simple bash script that checks if a website is running on a Linux or Bitnami server and restarts the web service if it&#8217;s not. Here&#8217;s what the script does: Make sure to replace &#8220;http:\/\/example.com&#8221; with the actual URL of your website. Also, ensure that the path to the Bitnami control script (\/opt\/bitnami\/ctlscript.sh) [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/platinumsupport.in\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-13T15:45:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-21T04:36:23+00:00\" \/>\n<meta name=\"author\" content=\"Anand\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anand\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\"},\"author\":{\"name\":\"Anand\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/#\/schema\/person\/aa475c6a968475a732f330a12ff18ede\"},\"headline\":\"Script to restart web service\",\"datePublished\":\"2024-03-13T15:45:33+00:00\",\"dateModified\":\"2024-09-21T04:36:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\"},\"wordCount\":242,\"publisher\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/#organization\"},\"articleSection\":[\"cPanel\/WHM\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\",\"url\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\",\"name\":\"Script to restart web service - Knowledge Base\",\"isPartOf\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/#website\"},\"datePublished\":\"2024-03-13T15:45:33+00:00\",\"dateModified\":\"2024-09-21T04:36:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/platinumsupport.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Script to restart web service\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/#website\",\"url\":\"https:\/\/platinumsupport.in\/blog\/\",\"name\":\"PlatinumSupport.in\",\"description\":\"Discover Success through Expert Guidance: Dive into the PlatinumSupport Blog for Solutions and Empowerment!\",\"publisher\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/platinumsupport.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/#organization\",\"name\":\"Tech Savy Systems\",\"url\":\"https:\/\/platinumsupport.in\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/platinumsupport.in\/blog\/wp-content\/uploads\/2024\/02\/psm-blog.png\",\"contentUrl\":\"https:\/\/platinumsupport.in\/blog\/wp-content\/uploads\/2024\/02\/psm-blog.png\",\"width\":250,\"height\":75,\"caption\":\"Tech Savy Systems\"},\"image\":{\"@id\":\"https:\/\/platinumsupport.in\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/platinumsupport.in\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/#\/schema\/person\/aa475c6a968475a732f330a12ff18ede\",\"name\":\"Anand\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/platinumsupport.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/610c86cd51134253c03e1441f07cd9c4e75bdbf5a06560ddc04e568bd85a89e5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/610c86cd51134253c03e1441f07cd9c4e75bdbf5a06560ddc04e568bd85a89e5?s=96&d=mm&r=g\",\"caption\":\"Anand\"},\"description\":\"I have been working in the web hosting support industry for over 15 years as a level 3 administrator, and I am proud to hold RED HAT certification. My expertise lies in providing support for Dedicated Servers, Cloud Servers, and VPS running various Linux operating systems such as CentOS, AlmaLinux, CloudLinux, and Ubuntu. Additionally, I am proficient in working with popular control panels like CPanel, Plesk, CWP, AApanel etc.\",\"sameAs\":[\"https:\/\/platinumsupport.in\/blog\"],\"honorificPrefix\":\"Mr\",\"honorificSuffix\":\"Er\",\"birthDate\":\"1980-11-11\",\"gender\":\"male\",\"knowsAbout\":[\"WebHosting Technical Support\"],\"knowsLanguage\":[\"English\",\"Hindi\",\"Marathi\"],\"jobTitle\":\"Level3 System Administrator\",\"worksFor\":\"PlatinumSupport.ni\",\"url\":\"https:\/\/platinumsupport.in\/blog\/author\/anand-v\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Script to restart web service - Knowledge Base","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/","og_locale":"en_US","og_type":"article","og_title":"Script to restart web service","og_description":"Here is the simple bash script that checks if a website is running on a Linux or Bitnami server and restarts the web service if it&#8217;s not. Here&#8217;s what the script does: Make sure to replace &#8220;http:\/\/example.com&#8221; with the actual URL of your website. Also, ensure that the path to the Bitnami control script (\/opt\/bitnami\/ctlscript.sh) [&hellip;]","og_url":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/","og_site_name":"Knowledge Base","article_publisher":"https:\/\/facebook.com\/platinumsupport.in","article_published_time":"2024-03-13T15:45:33+00:00","article_modified_time":"2024-09-21T04:36:23+00:00","author":"Anand","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Anand","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/#article","isPartOf":{"@id":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/"},"author":{"name":"Anand","@id":"https:\/\/platinumsupport.in\/blog\/#\/schema\/person\/aa475c6a968475a732f330a12ff18ede"},"headline":"Script to restart web service","datePublished":"2024-03-13T15:45:33+00:00","dateModified":"2024-09-21T04:36:23+00:00","mainEntityOfPage":{"@id":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/"},"wordCount":242,"publisher":{"@id":"https:\/\/platinumsupport.in\/blog\/#organization"},"articleSection":["cPanel\/WHM"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/","url":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/","name":"Script to restart web service - Knowledge Base","isPartOf":{"@id":"https:\/\/platinumsupport.in\/blog\/#website"},"datePublished":"2024-03-13T15:45:33+00:00","dateModified":"2024-09-21T04:36:23+00:00","breadcrumb":{"@id":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/platinumsupport.in\/blog\/script-to-restart-web-service\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/platinumsupport.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Script to restart web service"}]},{"@type":"WebSite","@id":"https:\/\/platinumsupport.in\/blog\/#website","url":"https:\/\/platinumsupport.in\/blog\/","name":"PlatinumSupport.in","description":"Discover Success through Expert Guidance: Dive into the PlatinumSupport Blog for Solutions and Empowerment!","publisher":{"@id":"https:\/\/platinumsupport.in\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/platinumsupport.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/platinumsupport.in\/blog\/#organization","name":"Tech Savy Systems","url":"https:\/\/platinumsupport.in\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/platinumsupport.in\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/platinumsupport.in\/blog\/wp-content\/uploads\/2024\/02\/psm-blog.png","contentUrl":"https:\/\/platinumsupport.in\/blog\/wp-content\/uploads\/2024\/02\/psm-blog.png","width":250,"height":75,"caption":"Tech Savy Systems"},"image":{"@id":"https:\/\/platinumsupport.in\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/platinumsupport.in"]},{"@type":"Person","@id":"https:\/\/platinumsupport.in\/blog\/#\/schema\/person\/aa475c6a968475a732f330a12ff18ede","name":"Anand","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/platinumsupport.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/610c86cd51134253c03e1441f07cd9c4e75bdbf5a06560ddc04e568bd85a89e5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/610c86cd51134253c03e1441f07cd9c4e75bdbf5a06560ddc04e568bd85a89e5?s=96&d=mm&r=g","caption":"Anand"},"description":"I have been working in the web hosting support industry for over 15 years as a level 3 administrator, and I am proud to hold RED HAT certification. My expertise lies in providing support for Dedicated Servers, Cloud Servers, and VPS running various Linux operating systems such as CentOS, AlmaLinux, CloudLinux, and Ubuntu. Additionally, I am proficient in working with popular control panels like CPanel, Plesk, CWP, AApanel etc.","sameAs":["https:\/\/platinumsupport.in\/blog"],"honorificPrefix":"Mr","honorificSuffix":"Er","birthDate":"1980-11-11","gender":"male","knowsAbout":["WebHosting Technical Support"],"knowsLanguage":["English","Hindi","Marathi"],"jobTitle":"Level3 System Administrator","worksFor":"PlatinumSupport.ni","url":"https:\/\/platinumsupport.in\/blog\/author\/anand-v\/"}]}},"_links":{"self":[{"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/posts\/3349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/comments?post=3349"}],"version-history":[{"count":1,"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/posts\/3349\/revisions"}],"predecessor-version":[{"id":3351,"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/posts\/3349\/revisions\/3351"}],"wp:attachment":[{"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/media?parent=3349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/categories?post=3349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/platinumsupport.in\/blog\/wp-json\/wp\/v2\/tags?post=3349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}