GithubHelp home page GithubHelp logo

obingul / autostopping Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sinanpetrustoma/autostopping

0.0 0.0 0.0 67 KB

Shell scripts to stop all Autonomous Databases, DB Systems VMs, Compute VMs, and OAC native instances using OCI CLI.

autostopping's Introduction

Following instructions are for stopping:

  • Autonomous Databases
  • Compute VMs
  • DBCS VMs
  • OAC native

Step 1: Install and configure OCI CLI on a Compute Intance (Linux VM with one CPU would be ok) in your tenancy. https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/cliinstall.htm It takes about 10min

This version uses Instance Principals for Authenticaion: create a Dynamic Group and add a rule for the OCID of the compute instance where the scripts will run create a policy in the root compartment as follows: Allow dynamic-group <group_name> to use all-resources in tenancy

Step 2: Save the delivered shell scripts on the VM, e.g. in /home/opc/ocicli/autostopping/ Create a sub-directory named log: i.e. /home/opc/ocicli/autostopping/log/

Step 3: Change the WHITELIST_FILE path in the .sh scripts accordingly. See Step 7. e.g.: WHITELIST_FILE="/home/opc/ocicli/autostopping/whitelist.txt"

Step 4: Make the shell scripts executable chmod +x /home/opc/ocicli/autostopping/*.sh

Step 5: As we are using Instance Principals for Authentication, there is no config file contaning the Tenancy ID: Change the value of TENANCY_OCID to your tenancy ID in all scripts

Step 6: Create an automation using corntab. In the following example shutting down the resources every day at 6p.m. and keeping the log files for 7 days. 0 18 * * * /home/opc/ocicli/autostopping/stop_adbs.sh > /home/opc/ocicli/autostopping/log/stop_adbs_date '+\%Y\%m\%d_\%H\%M\%S'.log 0 18 * * * /home/opc/ocicli/autostopping/stop_dbsystem_nodes.sh > /home/opc/ocicli/autostopping/log/stop_dbsystem_nodes_date '+\%Y\%m\%d_\%H\%M\%S'.log 0 18 * * * /home/opc/ocicli/autostopping/stop_computes.sh > /home/opc/ocicli/autostopping/log/stop_computes_date '+\%Y\%m\%d_\%H\%M\%S'.log 0 18 * * * /home/opc/ocicli/autostopping/stop_oac.sh > /home/opc/ocicli/autostopping/log/stop_oac_date '+\%Y\%m\%d_\%H\%M\%S'.log 0 3 * * * find /home/opc/ocicli/autostopping/log/ -type f -mtime +7 -name '*.log' -execdir rm -- '{}' ;

make sure your environment is sourced in cron by add following line to crontab (change the path to your .profile file): SHELL=/bin/bash BASH_ENV=/home/opc/.bash_profile

IMPORTANT: the scripts do not start the resources in the next morning: Option 1: every one in the team starts only the resources needed manually. Option 2: duplicate the scripts and replace "stop" by "start" and create crontab roles to run them

Step 7 (Optional): To prevent specific instances from auto stop, add a TAG named "AutoStopping" with the value "NO" to the resource

Step 8 (Optional): To prevent all ADBs, Compute, and DB Systems of a specific Compartment to be stopped, add the TAG to the Compartment itself. Some Compartments like ManagedCompartmentForPaaS cannot be edited. In this case add the Compartment OCID ot the whitelist.txt file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.