{"id":10397,"date":"2017-08-02T05:56:56","date_gmt":"2017-08-02T03:56:56","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/"},"modified":"2017-08-02T05:56:56","modified_gmt":"2017-08-02T03:56:56","slug":"oracle-cloud-script-to-stop-all-paas-services","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/","title":{"rendered":"Oracle Cloud: script to stop all PaaS services"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nWith metered cloud services, keeping all your instances running may become expensive. The goal is to start them only when you need them. Here is a script that stops all instances you have on the Oracle Cloud Service PaaS. You can schedule it for example to stop them at the end of the business day, or when they are not active for a long time. The scripts use the REST API called with curl, JSON output parsed with jq, HTTP status explained with links.<br \/>\n<!--more--><br \/>\nIn the first part of the script, I set the variables. Set them to your user:password, identity domain, cloud service url, ssh key:<\/p>\n<pre><code>\nu=\"MyEmail@Domain.net:MyPassword\"\ni=a521642\nr=https:\/\/dbcs.emea.oraclecloud.com\nk=\"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxAEm1WHYbJa50t61YhM53u4sljjSFGK458fgdljjkNqfihcRxSf2ENw6iaYhiBTPogG9IDaEqW+SbwpororD2\/bep16\/hHybGswD34jU7bf9kaaKi5gOgASChid4e322zrnwOtlzfHiiquhiUDgLwpQxCYVV5zU1RQ2NS3F3a45bepqkn\/GuPY5x\/KSn576+7HBCYVbao\/PTwZAeTVbo6Xb4ZQQrOIsLJxxDCQsr0\/g7ZS8\/OJHt8kotydu13n3rANB2y312XtTsW9mAwpfXuCuqDM5+dIjUdmtflkYtqsfrqSpLevVfVt1L7hqo+JGo7OBO0doVs6lQSCblZhYHh Me@MyLaptop\"\n<\/code><\/pre>\n<p>Here is the script. It starts to download the certificate if not already there. Then queries for all non stopped services and stops them. Finally, the last line displays the status of all services.<\/p>\n<pre><code>\n[ -f cacert.pem ] || curl --remote-name --time-cond cacert.pem https:\/\/curl.haxx.se\/ca\/cacert.pem\n&nbsp;\nfor s in $( curl -s --request GET --cacert cacert.pem --user $u --header \"X-ID-TENANT-NAME:$i\" $r\/paas\/service\/dbcs\/api\/v1.1\/instances\/$i | jq -r '.services[]|select(.status!=\"Stopped\")|.service_name' )\ndo\n # call the 'Stop service' REST API and get the http status\n httpstatus=$(curl --include --request POST --cacert cacert.pem --user $u --header \"X-ID-TENANT-NAME:$i\" --header \"Content-Type:application\/json\" --data '{\"lifecycleState\":\"Stop\"}' $r\/paas\/service\/dbcs\/api\/v1.1\/instances\/$i\/$s | awk '{print &gt;\"\/dev\/stderr\"} \/^HTTP\/{print $2}')\n # look for http status in documentation\n links -dump -width 300 https:\/\/docs.oracle.com\/en\/cloud\/paas\/java-cloud\/jsrmr\/Status%20Codes.html | grep -B 1 -A 1 \" $httpstatus \"\ndone\n&nbsp;\nsleep 1\ncurl -s --request GET --cacert cacert.pem --user $u --header \"X-ID-TENANT-NAME:$i\" $r\/paas\/service\/dbcs\/api\/v1.1\/instances\/$i | jq .\n<\/code><\/pre>\n<p>The script requires:<\/p>\n<ul>\n<li>curl to call the REST API<\/li>\n<li>jq to format and extract the returned JSON<\/li>\n<li>links to get the HTTP status description from the documentation<\/li>\n<\/ul>\n<p>The Cloud is all about automation and the REST API makes it very easy to do from command line or script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . With metered cloud services, keeping all your instances running may become expensive. The goal is to start them only when you need them. Here is a script that stops all instances you have on the Oracle Cloud Service PaaS. You can schedule it for example to stop them at the end [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":10398,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[955,59],"tags":[135,96,458],"type_dbi":[],"class_list":["post-10397","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud","category-oracle","tag-cloud","tag-oracle","tag-oracle-20c"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Oracle Cloud: script to stop all PaaS services - dbi Blog<\/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:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle Cloud: script to stop all PaaS services\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . With metered cloud services, keeping all your instances running may become expensive. The goal is to start them only when you need them. Here is a script that stops all instances you have on the Oracle Cloud Service PaaS. You can schedule it for example to stop them at the end [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-02T03:56:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1777\" \/>\n\t<meta property=\"og:image:height\" content=\"674\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Oracle Cloud: script to stop all PaaS services\",\"datePublished\":\"2017-08-02T03:56:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\"},\"wordCount\":201,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png\",\"keywords\":[\"Cloud\",\"Oracle\",\"Oracle 20c\"],\"articleSection\":[\"Cloud\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\",\"name\":\"Oracle Cloud: script to stop all PaaS services - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png\",\"datePublished\":\"2017-08-02T03:56:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png\",\"width\":1777,\"height\":674},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle Cloud: script to stop all PaaS services\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Oracle Cloud: script to stop all PaaS services - dbi Blog","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:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/","og_locale":"en_US","og_type":"article","og_title":"Oracle Cloud: script to stop all PaaS services","og_description":"By Franck Pachot . With metered cloud services, keeping all your instances running may become expensive. The goal is to start them only when you need them. Here is a script that stops all instances you have on the Oracle Cloud Service PaaS. You can schedule it for example to stop them at the end [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/","og_site_name":"dbi Blog","article_published_time":"2017-08-02T03:56:56+00:00","og_image":[{"width":1777,"height":674,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png","type":"image\/png"}],"author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Oracle Cloud: script to stop all PaaS services","datePublished":"2017-08-02T03:56:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/"},"wordCount":201,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png","keywords":["Cloud","Oracle","Oracle 20c"],"articleSection":["Cloud","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/","url":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/","name":"Oracle Cloud: script to stop all PaaS services - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png","datePublished":"2017-08-02T03:56:56+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureCloudStopped.png","width":1777,"height":674},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-cloud-script-to-stop-all-paas-services\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Oracle Cloud: script to stop all PaaS services"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/10397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=10397"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/10397\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/10398"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=10397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=10397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=10397"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=10397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}