From 82ae32b9fe0865192faaeb8d1a96151a96b2f969 Mon Sep 17 00:00:00 2001 From: Piwccle Date: Thu, 4 Jun 2026 12:30:33 +0200 Subject: [PATCH] openvidu-deployment: GCP - add lock mechanism to prevent more than one graceful shutdowns of OpenVidu Media Node --- .../pro/elastic/gcp/tf-gpc-openvidu-elastic.tf | 10 ++++++++++ openvidu-deployment/pro/ha/gcp/tf-gpc-openvidu-ha.tf | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/openvidu-deployment/pro/elastic/gcp/tf-gpc-openvidu-elastic.tf b/openvidu-deployment/pro/elastic/gcp/tf-gpc-openvidu-elastic.tf index 38d8c8f1f..37ae41d86 100644 --- a/openvidu-deployment/pro/elastic/gcp/tf-gpc-openvidu-elastic.tf +++ b/openvidu-deployment/pro/elastic/gcp/tf-gpc-openvidu-elastic.tf @@ -1242,6 +1242,16 @@ EOF #!/bin/bash -x set -e +# Prevent concurrent/repeated runs. The check-abandoned cron fires every minute and would +# otherwise launch this script again while a drain is already in progress, sending a second +# SIGQUIT to the media node. LiveKit interprets the second signal as a forced shutdown +# (force=true), which closes rooms and kicks out participants instead of waiting for them. +exec 9>/var/lock/openvidu_shutdown.lock +if ! flock -n 9; then + echo "Graceful shutdown already in progress, skipping..." + exit 0 +fi + echo "Starting graceful shutdown of OpenVidu Media Node..." INSTANCE_NAME=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/name" -H "Metadata-Flavor: Google") diff --git a/openvidu-deployment/pro/ha/gcp/tf-gpc-openvidu-ha.tf b/openvidu-deployment/pro/ha/gcp/tf-gpc-openvidu-ha.tf index cc61a562f..6604d6e7b 100644 --- a/openvidu-deployment/pro/ha/gcp/tf-gpc-openvidu-ha.tf +++ b/openvidu-deployment/pro/ha/gcp/tf-gpc-openvidu-ha.tf @@ -1609,6 +1609,16 @@ EOF #!/bin/bash -x set -e +# Prevent concurrent/repeated runs. The check-abandoned cron fires every minute and would +# otherwise launch this script again while a drain is already in progress, sending a second +# SIGQUIT to the media node. LiveKit interprets the second signal as a forced shutdown +# (force=true), which closes rooms and kicks out participants instead of waiting for them. +exec 9>/var/lock/openvidu_shutdown.lock +if ! flock -n 9; then + echo "Graceful shutdown already in progress, skipping..." + exit 0 +fi + echo "Starting graceful shutdown of OpenVidu Media Node..." INSTANCE_NAME=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/name" -H "Metadata-Flavor: Google")