# [OCI] Resource Scheduler

*If you prefer to read in Spanish* [***Spanish version***](https://dbaenlasombra.com/oci-resource-scheduler)*.*

[One of the mo](https://dbaenlasombra.com/23ai-shadow-tablespaces)st important aspects when we are an architect on OCI, it is goes hand in hand with the customer in order to save money when we have to define resources in the **tenancy**.

Since *May 2024*, OCI has released the service “**OCI resource scheduler**“ in order to make us this task easier for us. Before then, this task could be done using methods such as:

* **Crontab**. Nowadays, we always have an environment running every day without interruptions. This environment was ideal for setting up a shell script using cron under the **opc** user.
    
    Below, you can see an example using this configuration:
    

```bash
[opc ~]$ crontab -l
 30 7 * * 1,2,3,4,5 /home/opc/dbsystem/start_dbsystem.sh >> /home/opc/dbsystem/start_dbsystem.log
[opc ~]$ cat /home/opc/dbsystem/start_dbsystem.sh
#!/bin/bash
cd /home/opc/dbsystem 

NODE_SWITCH=<OCID>

. ./oci-curl.sh

oci-curl <END_POINT> POST ./empty.json /20160918/dbNodes/${NODE_SWITCH}?action=start
```

* **Auto Scaling** in OCI by **Richard Garsthagen.** He published a repository on github under the name **OCI-AutoScale** ([link repositorio](https://github.com/AnykeyNL/OCI-AutoScale)) in order to make these operations using **tags.**
    
    When you set up **OCI-AutoScale**, one of the step, it’s configurate the tag **Schedule:**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761066421080/8d6ff26f-6b78-4e54-b088-13fb3fa38783.png align="center")
    
    The next step would be to assign these tags to an instance:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761067383472/96de0ce7-76eb-4820-82d4-11b573cd26d2.png align="center")
    
    In this example, we have assigned several tags:
    
    * **Weekend**: Shut down all weekend.
        
    * **WeekDay**: Switch on some hours on weekdays. We can see the translation of “*0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0*” on the left slide.
        

### **OCI resource scheduler**

These are the steps that we’re going to follow in order to use the **Resource Scheduler**:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761387863048/ffd415f9-d68c-46cc-8f9a-07db0217a2a4.png align="center")

Before getting our hands dirty,we need to check as follows:

* Our user has the necessary permissions in order to create **schedules**.
    
    ```bash
    Allow any-user to manage resource-schedule-family in tenancy
    ```
    
* The **schedule** has the necessary permissions in order to manage resources within the tenancy:
    
    ```bash
    Allow any-user to manage all-resources 
     in compartment '<compartment>' where all{request.principal.type='resourceschedule'}
    ```
    
* We are going to create a new instance in order to check the new **schedule**:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761309231714/fa4001f0-9076-44fb-9128-e780c10f21a2.png align="center")
    

After doing all these steps, we are ready. So, let's get down to business!

Let’s go to the section “**Governance & Administration**” and **Schedules**:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761068526472/9929d499-5f66-4a50-acda-833868cecc06.png align="center")

Here, we can see the **Resource scheduler** section. Click on “**Create a schedule**”:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761309011547/f1b235c8-5c07-47e5-b497-8072938b0205.png align="center")

In the first section, we are going to provide the basic information such as **name** or **action**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761121076288/22ac80c3-37ba-49c2-b89a-a253255b91c8.png align="center")

In the second section, we are going to select the resource on which we want make the action:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761121425419/0d50bdf6-6c94-4f46-a2d8-d84085a17919.png align="center")

Here, we can see a filter with two options: **Static** or **Dynamic**.

The differences are as follows:

* **Static**: This is when we define a schedule for a single resource.
    
* **Dynamic:** This is when we define a schedule for a group of resources. Moreover, when using Dynamic method, the current set of resources that match the criteria is displayed for reference.
    
    * *Tag:* By selecting tag method, you can search for resources using it\*.\*
        
    * *Resource Type*: You can find resources such as *instance*, *instance pool*, *autonomous database*, *function or even DB system*.
        
    * *Compartment:* You can locate resources in one compartment or across all compartments\*.\*
        
    * *Status*: By selecting the status method, you can search for resources using their status. The states are available, running, stopped or all.
        

In this case, we select the **static** option and click on our instance:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761229546582/04090d6d-5cd1-492f-841c-535a9d6cfec7.png align="center")

In the next step, we will be able to add parameters to our resource,but in this case, it does not apply.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761229642165/3d8f9104-96b9-4a2d-940e-08fb1a3982d7.png align="center")

The next step is the most important, because we have to define the schedule in order to switch on the instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761168926242/91b09e8b-7e19-46b8-9176-0532bc4c6a56.png align="center")

First, we define the schedule using either the “**Form Interface”** or a “**Cron expression”**. In this case, since we define a couple of schedules, we will use both options.

Let’s click on “**Cron expression**” in order to switch on our instance:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761390901305/08410e3a-43ae-4c5f-8c59-c378edfcbd11.png align="center")

Here, we can see as follows:

* **Recurrence details**: A little description, it’s optional except in this case. Watch out! when we use **cron**, we should fill in this field with a **Cron expression**.
    
    If you don’t fill in this field, you will see the following error:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761171906611/e9bee26a-4174-4bcb-92ae-4b48db164b46.png align="left")
    
    Our **Cron expression** is: “*30 12 \* \* \**“ ***.***
    
* **Time**: UTC time in 24-hour format.
    
* **Start date**: Enter a date in order to specify the start date.
    
* **End date**: Enter a date in order to specify the end date, it’s optional.
    

The last window, it would be a summary our schedule.

Let’s define the **schedule** in order to switch off our instance. All steps will be the same as in the previous schedule, except when we define the schedule, because we use the option “**Form Interface**”.

Here’s our schedule:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761392305970/8afad909-ad45-4f2d-88cb-867c27c4d3b2.png align="center")

Ready! With all steps completed, we now have both schedules prepared in order to switch on/switch off our instance.

Moreover, if we go back to the beginning, you will see that both schedules are working.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761392915448/08e0f6c3-0336-4909-aa71-4fe3b1d07bf9.png align="center")

Looking forward to seeing you in the next article :)
