Challenge 6: SAP Start Stop Automation

May 13, 2021 ยท View on GitHub

< Previous Challenge - Home - Next Challenge >

Introduction

Contoso Inc is looking to optimize the cost of SAP landscape and exploring ways to do that. They're leaning towards getting Reserves Instances (RI) for all production systems and would like to save cost on non-production (sandboxes, project systems, etc.) systems by not operating those during non-business hours. This solution helps them achieve that either using automation tools or schedule based

Description

The goal of this solution is to facilitate a controlled shutdown & startup of SAP systems, which is a common mechanism to save costs for non Reserved Instances (RI) VMs in Azure.

Note: VMs must be deallocated for Azure charges to stop and that's facilitated by scripts

This flexible solution enables (using Azure automation, Azure Tags, Scripting, and PowerShell runbooks):

  • Start & Stop of your SAP application servers, central services, database, and corrosponding VMs
  • Optionally convert Premium Managed Disks to Standard during the stop procedure, and back to Premium during the start procedure, thus saving cost storage as well

SAP systems start and stop is done gracefully (using SAP native commands), allowing SAP users and batch jobs to finish (with timeout) minimizing downtime impact. For detailed information refer below Architecture.

Architecture of the Start/Stop solution

The solution is using Azure automation account PaaS solution to execute the SAP shutdown/startup jobs (as shown in the below diagram). Runbooks are written in PowerShell. There is also a PowerShell module SAPAzurePowerShellModules that is used by all runbooks. These runbooks and module are stored in PowerShell Gallery, and are easy to import.

image

Information about SAP landscape and instances are to be stored in VM Tags.

Secure assets in Azure Automation include credentials, certificates, connections, and encrypted variables. These assets are encrypted and stored in Azure Automation using a unique key that is generated for each Automation account. Azure Automation stores the key in the system-managed Key Vault. Before storing a secure asset, Automation loads the key from Key Vault and then uses it to encrypt the asset.

SAP system start / stop / monitoring and SAP Application server Start / stop is implemented using scripts (calling SAP sapcontrol executable) via the Azure VM agent.

SAP HANA start / stop / monitoring is implemented using scripts (calling SAP sapcontrol executable) via the Azure VM agent.

SQL Server start / stop / monitoring is implemented using scripts (calling SAP Host Agent executable) via the Azure VM agent.

Azure runbooks can either be executed manually or scheduled.

Success Criteria

  • Create Azure Automation account
  • Tag all the VMs for the SID in place
  • List the SID to ensure all the systems were tagged correctly
  • Execute runbook manually to stop systems
  • Schedule the runbook to start the systems
  • (Optional) Restrict access to runbooks to an individual user

Learning Resources

Import Az.Modules

SAP start / stop PowerShell (PS) runbooks use new Az PS module, so import following AZ modules:

  • Az.Account

  • Az.Compute

  • Az.Automation

  • Az.Resources

Import SAP PowerShell Module

Import SAPAzurePowerShellModules PowerShell module that will be used by SAP Runbooks.

NOTE: PowerShell module SAPAzurePowerShellModules is stored in PowerShell Gallery and is easy to import into Azure automation account.

Import SAP Runbooks

Navigate to Runbook Gallery and Import these runbooks:

  • Stop-SAPSystem

  • Start-SAPSystem

  • List-SAPSystemInstances

  • Stop-SAPHANA

  • Start-SAPHANA

  • List-SAPHANAInstance

  • Start-SAPApplicationServer

  • Stop-SAPApplicationServer

  • Tag-SAPSystemASCSInstanceLinux

  • Tag-SAPSystemDialogInstanceLinux

  • Tag-SAPSystemStandaloneHANA

NOTE: All SAP runbooks are stored in PowerShell Gallery and are easy to import into Azure automation account.

Tagging and executing Runbooks

Example Distributed SAP ABAP System with HANA โ€“ ALL Linux

Here is an example of a distributed SAP ABAP System TS1 with HANA DB. ALL VMs are Linux VMs. SAP HANA SID TS2 is different than SAP SID TS1.

image

HANA DB VM

DB has following properties.

Properties Value
VM Name ts2-db
Azure Resource Group Name gor-linux-eastus2
SAP System SID TS1

SAP HANA SID *

* in central SAP system HANA SID is can be different than SAP System SID

TS2
SAP HANA Instance Nr 0

VM [ts2-db] has to be tagged with following Tags:

TagValue
SAPSystemSIDTS1
SAPHANASIDTS2
SAPDBMSTypeHANA
SAPHANAINstanceNumber0

You can create these Tags manually. However, to simplify and automate Tagging process run this Azure runbook: Tag-SAPSystemStandaloneHANA

ParameterMandatoryValue
ResourceGroupNameYESgor-linux-eastus2
VMNameYESts2-db
SAPSIDYESTS1
SAPHANASIDYESTS2
SAPHANAINstanceNumberYES0

ASCS VM

ASCS has following properties.

PropertiesValue
Azure Resource Group Namegor-linux-eastus2
VM Namets2-ascs
SAP System SIDTS1
SAP ASCS Instance Nr0

VM [ts2-ascs] has to be tagged with following Tags:

TagValue
SAPSystemSIDTS1
SAPApplicationInstanceTypeSAP_ASCS
SAPApplicationInstanceNumber1

You can create these Tags manually. However, to simplify and automate Tagging process run this Azure runbook: Tag-SAPSystemASCSInstanceLinux

ParameterMandatoryValue
ResourceGroupNameYESgor-linux-eastus2
VMNameYESts2-ascs
SAPSIDYESTS1
SAPASCSInstanceNumberYES1

SAP Application Server VM #1

SAP application server 1 has following properties.

PropertiesValue
Azure Resource Group Namegor-linux-eastus2
VM Namets2-di0
SAP System SIDTS1
SAP Dialog Instance Nr1

VM [ts2-di0] has to be tagged with following Tags:

TagValue
SAPSystemSIDTS1
SAPApplicationInstanceTypeSAP_D
SAPApplicationInstanceNumber1

You can create these Tags manually. However, to simplify and automate Tagging process run this Azure runbook: Tag-SAPSystemDialogInstanceLinux

ParameterMandatoryValue
ResourceGroupNameYESgor-linux-eastus2
VMNameYESts2-ascs
SAPSIDYESTS1
SAPDialogInstanceNumberYES1

SAP Application Server VM #2

SAP application server 2 has following properties.

PropertiesValue
Azure Resource Group Namegor-linux-eastus2-2
VM Namets2-di1
SAP System SIDTS1
SAP Dialog Instance Nr2

VM [ts2-di0] has to be tagged with following Tags:

TagValue
SAPSystemSIDTS1
SAPApplicationInstanceTypeSAP_D
SAPApplicationInstanceNumber2

You can create these Tags manually. However, to simplify, avoid typos, and automate the tagging process use Azure runbook: Tag-SAPSystemDialogInstanceLinux

ParameterMandatoryValue
ResourceGroupNameYESgor-linux-eastus2-2
VMNameYESts2-di1
SAPSIDYESTS1
SAPDialogInstanceNumberYES2

Runbook Description

Listing SAP System <SID> VMs: List-SAPSystemInstances

ParameterMandatoryDefault valueComment
SAPSIDYES

Listing SAP HANA VM: List-SAPHANAInstance

ParameterMandatoryDefault valueComment
SAPSIDYES

Start SAP System: Start-SAPSystem

ParameterMandatoryDefault valueComment
SAPSIDYES
WaitForStartTimeInSecondsNo600Wait time to start SAP system
ConvertDisksToPremiumNo$FalseIf set to $True, all disk will be converted to Premium
PrintExecutionCommandNo$FalseIf set to $True, all OS commands will be printed

Runtime steps:

  • Convert disk to Premium, if desired
    ConvertDisksToPremium = $True

  • Start VMs in this order:

    • SAP ASCS or DVEBMS VM

    • SAP DBMS VM

    • SAP Dialog instances VMs

  • Show SAP DBMS Status

  • Start SAP DBMS

  • Show SAP DBMS Status

  • List SAP ABAP instances and show status.

  • Start SAP ABAP system and wait for WaitForStartTimeInSeconds seconds.

  • List SAP ABAP instances and show status.

  • Show summary.

Stop SAP System: Stop-SAPSystem

ParameterMandatoryDefault valueComment
SAPSIDYES
SoftShutdownTimeInSecondsNo600Soft Shutdown time for SAP system
ConvertDisksToStandardNo$FalseIf set to $True, all disk will be converted to standard
PrintExecutionCommandNo$FalseIf set to $True, all OS commands will be printed

Runtime steps:

  • List SAP ABAP instances and show status.

  • Stop SAP ABAP System with soft shutdown SoftShutdownTimeInSeconds

  • List SAP ABAP instances and show status.

  • Get SAP DBMS status

  • Stop SAP DBMS

  • Get DBMS status

  • Stop VMs in this order:

    • SAP Dialog instances VMs

    • SAP DBMS VM

    • SAP ASCS or DVEBMS VM

  • Convert disk to Standard, if desired
    ConvertDisksToStandard = $True

  • Show summary.

Start-SAPHANADB

This runbook will only start VM and standalone HANA DB.

ParameterMandatoryDefault value
SAPHANASIDYES
ConvertDisksToPremiumNo$False
PrintExecutionCommandNo$False

Runtime steps are:

  • Convert disk to Premium, if desired
    ConvertDisksToPremium = $True

  • Start VM.

  • Show SAP HANA Status

  • Start SAP HANA

  • Show SAP HANA Status

  • Show summary.

Stop-SAPHANADB

This runbook will stop standalone HANA DB, and VM.

ParameterMandatoryDefault value
SAPHANASIDYES
ConvertDisksToStandardNo$False
PrintExecutionCommandNo$False

Runtime steps:

  • Show SAP HANA Instance status

  • Stop SAP HANA

  • Show SAP HANA status

  • Stop VM.

  • Convert disk to Standard, if desired
    ConvertDisksToStandard = $True

  • Show summary.

Stop- SAPApplicationServer

This runbook will stop standalone SAP Application Server and VM.

ParameterMandatoryDefault value
ResourceGroupNameYES
VMNameYES
SAPApplicationServerWaitTimeNo300
ConvertDisksToStandardNo$False
PrintExecutionCommandNo$False

Runtime steps:

  • Stop SAP application server.

  • Stop VM.

  • Convert disk to Standard, if desired
    ConvertDisksToStandard = $True

  • Show summary.

Start- SAPApplicationServer

This runbook will start VM and standalone SAP Application Server.

ParameterMandatoryDefault value
ResourceGroupNameYES
VMNameYES
SAPApplicationServerWaitTimeNo300
ConvertDisksToPremiumNo$False
PrintExecutionCommandNo$False

Runtime steps:

  • Convert disk to Premium, if desired
    ConvertDisksToPremium = $True

  • Start VM.

  • Start SAP application server.

  • Show summary.