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")