My role
Design, implementation and rollout (Tech Lead, Unix team)
Period
2026
Scale
SAP landscapes across Dev, QA and Prod on RHEL
Stack
Bash, sapcontrol, RHEL, systemd, Ansible
7ordered, health-gated steps per reboot
1 commandreplaces a manual, multi-team runbook
0steps that continue past a failed check

Context

Monthly OS patching on our RHEL estate included servers running SAP. The SAP subject-matter experts (SMEs) had a firm requirement: SAP layers must be stopped top-down — application servers, then central services, then the database — and started again bottom-up, with each layer confirmed healthy before the next one is touched.

In practice this meant a Unix engineer and an SAP engineer on a bridge call, stepping through a document, typing commands by hand on several hosts, and eyeballing output. It worked, but it was slow, depended on who was on shift, and the riskiest moment — starting application servers before the database was really ready — relied on human judgement at 2 a.m.

The problem, stated precisely

Design

Diagram of the seven-step ordered SAP stop and start around an OS reboot
The stop phase walks down the stack, the OS is patched, and the start phase walks back up. Every arrow is gated by a health check.

I wrote a Bash orchestrator with three principles:

  1. Declarative order, imperative execution. A small per-landscape config lists instances in stop order. Start order is simply the reverse — so there is only one list to keep correct.
  2. Every action is followed by a wait-and-verify. I used sapcontrol’s own exit codes rather than parsing text: GetProcessList returns 3 when all processes are running (GREEN) and 4 when all are stopped.
  3. Fail closed. Any unexpected state exits non-zero with a clear message, leaves the system where it is, and is picked up by the patching job as a failure for on-call to review.

A simplified, sanitised version of the core loop:

#!/usr/bin/env bash
# Ordered SAP stop — simplified extract. Real script adds logging, locking and a dry-run mode.
set -Eeuo pipefail

TIMEOUT=900   # seconds to wait for a layer to reach the target state
POLL=10

# Instances in STOP order: app servers -> central services -> database
# format: <host>:<instance_nr>:<label>
INSTANCES=(
  "app02:01:AAS"
  "app01:00:PAS"
  "cs01:10:ASCS"
  "db01:02:DB"
)

state_of() {  # echo 3 = all GREEN, 4 = all stopped, other = mixed/unknown
  local host=$1 nr=$2 rc=0
  ssh -o BatchMode=yes "$host" "sapcontrol -nr $nr -function GetProcessList" >/dev/null 2>&1 || rc=$?
  echo "$rc"
}

wait_for() {  # wait_for <host> <nr> <expected_rc>
  local host=$1 nr=$2 want=$3 waited=0
  until [[ "$(state_of "$host" "$nr")" == "$want" ]]; do
    (( waited >= TIMEOUT )) && { echo "FAIL: $host/$nr did not reach state $want in ${TIMEOUT}s" >&2; return 1; }
    sleep "$POLL"; (( waited += POLL ))
  done
}

for entry in "${INSTANCES[@]}"; do
  IFS=: read -r host nr label <<<"$entry"
  echo "Stopping $label on $host (nr $nr)"
  ssh -o BatchMode=yes "$host" "sapcontrol -nr $nr -function Stop" >/dev/null
  wait_for "$host" "$nr" 4      # gate: do not touch the next layer until this one is fully down
done
echo "All SAP layers stopped cleanly — safe to patch and reboot."

The start path walks the same array in reverse and waits for state 3 (all GREEN) at each step.

Alternatives I considered

Option Why not (for this estate)
sapcontrol -function StopSystem ALL from ASCS Handles ordering within one system, but didn’t cover the database layer or the SMEs’ requirement for explicit per-layer confirmation across hosts.
Pacemaker / HA cluster resource ordering Correct tool for HA-clustered SAP, but these systems were not clustered; introducing a cluster just for patching was out of proportion.
Ansible playbook only Ansible runs the script across hosts during patching, but the wait-and-verify logic is clearer and easier for SAP engineers to review as one readable script.

Rollout

What I learned