Interview Prep/Linux/Scheduling, automation and scripting

You must run a job only on the primary node of a two-node cluster, but both nodes have the same cron. How?

AdvancedScenarioScheduling, automation and scripting
Answer

Situation read → Make the job check leadership before acting.

What I'd do →

  1. If there's a floating VIP (keepalived/Pacemaker), check it:
ip -o addr show | grep -q '10.0.0.100/' || exit 0
  1. Or take a distributed lock (Consul consul lock, etcd lease, a DB advisory lock SELECT pg_try_advisory_lock(42)).
  2. Better: make it a cluster resource in Pacemaker, or a Kubernetes CronJob with concurrencyPolicy: Forbid.

Why → Duplicated runs cause double emails, double billing and similar issues.

Interview tip → Mention making jobs idempotent so a double run is harmless anyway.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting