mirror of https://github.com/OpenVidu/openvidu.git
Fixed restart execution in GCP
parent
4cf5c03994
commit
9fd195fde8
|
@ -147,6 +147,10 @@ locals {
|
||||||
METADATA_URL="http://metadata.google.internal/computeMetadata/v1"
|
METADATA_URL="http://metadata.google.internal/computeMetadata/v1"
|
||||||
get_meta() { curl -s -H "Metadata-Flavor: Google" "$${METADATA_URL}/$1"; }
|
get_meta() { curl -s -H "Metadata-Flavor: Google" "$${METADATA_URL}/$1"; }
|
||||||
|
|
||||||
|
# Create counter file for tracking script executions
|
||||||
|
touch /tmp/openvidu_install_counter.txt
|
||||||
|
|
||||||
|
|
||||||
# Create all the secrets
|
# Create all the secrets
|
||||||
gcloud secrets create OPENVIDU_URL --replication-policy=automatic || true
|
gcloud secrets create OPENVIDU_URL --replication-policy=automatic || true
|
||||||
gcloud secrets create MEET_INITIAL_ADMIN_USER --replication-policy=automatic || true
|
gcloud secrets create MEET_INITIAL_ADMIN_USER --replication-policy=automatic || true
|
||||||
|
@ -627,91 +631,94 @@ locals {
|
||||||
#!/bin/bash -x
|
#!/bin/bash -x
|
||||||
set -eu -o pipefail
|
set -eu -o pipefail
|
||||||
|
|
||||||
# install.sh
|
# Check if installation already completed
|
||||||
cat > /usr/local/bin/install.sh << 'INSTALL_EOF'
|
if [ ! -f /tmp/openvidu_install_counter.txt ]; then
|
||||||
${local.install_script}
|
# install.sh
|
||||||
INSTALL_EOF
|
cat > /usr/local/bin/install.sh << 'INSTALL_EOF'
|
||||||
chmod +x /usr/local/bin/install.sh
|
${local.install_script}
|
||||||
|
INSTALL_EOF
|
||||||
|
chmod +x /usr/local/bin/install.sh
|
||||||
|
|
||||||
# after_install.sh
|
# after_install.sh
|
||||||
cat > /usr/local/bin/after_install.sh << 'AFTER_INSTALL_EOF'
|
cat > /usr/local/bin/after_install.sh << 'AFTER_INSTALL_EOF'
|
||||||
${local.after_install_script}
|
${local.after_install_script}
|
||||||
AFTER_INSTALL_EOF
|
AFTER_INSTALL_EOF
|
||||||
chmod +x /usr/local/bin/after_install.sh
|
chmod +x /usr/local/bin/after_install.sh
|
||||||
|
|
||||||
# update_config_from_secret.sh
|
# update_config_from_secret.sh
|
||||||
cat > /usr/local/bin/update_config_from_secret.sh << 'UPDATE_CONFIG_EOF'
|
cat > /usr/local/bin/update_config_from_secret.sh << 'UPDATE_CONFIG_EOF'
|
||||||
${local.update_config_from_secret_script}
|
${local.update_config_from_secret_script}
|
||||||
UPDATE_CONFIG_EOF
|
UPDATE_CONFIG_EOF
|
||||||
chmod +x /usr/local/bin/update_config_from_secret.sh
|
chmod +x /usr/local/bin/update_config_from_secret.sh
|
||||||
|
|
||||||
# update_secret_from_config.sh
|
# update_secret_from_config.sh
|
||||||
cat > /usr/local/bin/update_secret_from_config.sh << 'UPDATE_SECRET_EOF'
|
cat > /usr/local/bin/update_secret_from_config.sh << 'UPDATE_SECRET_EOF'
|
||||||
${local.update_secret_from_config_script}
|
${local.update_secret_from_config_script}
|
||||||
UPDATE_SECRET_EOF
|
UPDATE_SECRET_EOF
|
||||||
chmod +x /usr/local/bin/update_secret_from_config.sh
|
chmod +x /usr/local/bin/update_secret_from_config.sh
|
||||||
|
|
||||||
# get_value_from_config.sh
|
# get_value_from_config.sh
|
||||||
cat > /usr/local/bin/get_value_from_config.sh << 'GET_VALUE_EOF'
|
cat > /usr/local/bin/get_value_from_config.sh << 'GET_VALUE_EOF'
|
||||||
${local.get_value_from_config_script}
|
${local.get_value_from_config_script}
|
||||||
GET_VALUE_EOF
|
GET_VALUE_EOF
|
||||||
chmod +x /usr/local/bin/get_value_from_config.sh
|
chmod +x /usr/local/bin/get_value_from_config.sh
|
||||||
|
|
||||||
# store_secret.sh
|
# store_secret.sh
|
||||||
cat > /usr/local/bin/store_secret.sh << 'STORE_SECRET_EOF'
|
cat > /usr/local/bin/store_secret.sh << 'STORE_SECRET_EOF'
|
||||||
${local.store_secret_script}
|
${local.store_secret_script}
|
||||||
STORE_SECRET_EOF
|
STORE_SECRET_EOF
|
||||||
chmod +x /usr/local/bin/store_secret.sh
|
chmod +x /usr/local/bin/store_secret.sh
|
||||||
|
|
||||||
# check_app_ready.sh
|
# check_app_ready.sh
|
||||||
cat > /usr/local/bin/check_app_ready.sh << 'CHECK_APP_EOF'
|
cat > /usr/local/bin/check_app_ready.sh << 'CHECK_APP_EOF'
|
||||||
${local.check_app_ready_script}
|
${local.check_app_ready_script}
|
||||||
CHECK_APP_EOF
|
CHECK_APP_EOF
|
||||||
chmod +x /usr/local/bin/check_app_ready.sh
|
chmod +x /usr/local/bin/check_app_ready.sh
|
||||||
|
|
||||||
# restart.sh
|
# restart.sh
|
||||||
cat > /usr/local/bin/restart.sh << 'RESTART_EOF'
|
cat > /usr/local/bin/restart.sh << 'RESTART_EOF'
|
||||||
${local.restart_script}
|
${local.restart_script}
|
||||||
RESTART_EOF
|
RESTART_EOF
|
||||||
chmod +x /usr/local/bin/restart.sh
|
chmod +x /usr/local/bin/restart.sh
|
||||||
|
|
||||||
# config_s3.sh
|
# config_s3.sh
|
||||||
cat > /usr/local/bin/config_s3.sh << 'CONFIG_S3_EOF'
|
cat > /usr/local/bin/config_s3.sh << 'CONFIG_S3_EOF'
|
||||||
${local.config_s3_script}
|
${local.config_s3_script}
|
||||||
CONFIG_S3_EOF
|
CONFIG_S3_EOF
|
||||||
chmod +x /usr/local/bin/config_s3.sh
|
chmod +x /usr/local/bin/config_s3.sh
|
||||||
|
|
||||||
apt-get update && apt-get install -y
|
apt-get update && apt-get install -y
|
||||||
|
|
||||||
# Install google cli
|
# Install google cli
|
||||||
if ! command -v gcloud >/dev/null 2>&1; then
|
if ! command -v gcloud >/dev/null 2>&1; then
|
||||||
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
|
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
|
||||||
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
|
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
|
||||||
apt-get update && apt-get install -y google-cloud-cli
|
apt-get update && apt-get install -y google-cloud-cli
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Authenticate with gcloud using instance service account
|
||||||
|
gcloud auth activate-service-account --key-file=/dev/null 2>/dev/null || true
|
||||||
|
gcloud config set account $(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email" -H "Metadata-Flavor: Google")
|
||||||
|
gcloud config set project $(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
|
||||||
|
|
||||||
|
export HOME="/root"
|
||||||
|
|
||||||
|
# Install OpenVidu
|
||||||
|
/usr/local/bin/install.sh || { echo "[OpenVidu] error installing OpenVidu"; exit 1; }
|
||||||
|
|
||||||
|
# Config S3 bucket
|
||||||
|
/usr/local/bin/config_s3.sh || { echo "[OpenVidu] error configuring S3 bucket"; exit 1; }
|
||||||
|
|
||||||
|
# Start OpenVidu
|
||||||
|
systemctl start openvidu || { echo "[OpenVidu] error starting OpenVidu"; exit 1; }
|
||||||
|
|
||||||
|
# Update shared secret
|
||||||
|
/usr/local/bin/after_install.sh || { echo "[OpenVidu] error updating shared secret"; exit 1; }
|
||||||
|
else
|
||||||
|
# Launch on reboot
|
||||||
|
/usr/local/bin/restart.sh || { echo "[OpenVidu] error restarting OpenVidu"; exit 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Authenticate with gcloud using instance service account
|
|
||||||
gcloud auth activate-service-account --key-file=/dev/null 2>/dev/null || true
|
|
||||||
gcloud config set account $(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email" -H "Metadata-Flavor: Google")
|
|
||||||
gcloud config set project $(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
|
|
||||||
|
|
||||||
export HOME="/root"
|
|
||||||
|
|
||||||
# Install OpenVidu
|
|
||||||
/usr/local/bin/install.sh || { echo "[OpenVidu] error installing OpenVidu"; exit 1; }
|
|
||||||
|
|
||||||
# Config S3 bucket
|
|
||||||
/usr/local/bin/config_s3.sh || { echo "[OpenVidu] error configuring S3 bucket"; exit 1; }
|
|
||||||
|
|
||||||
# Start OpenVidu
|
|
||||||
systemctl start openvidu || { echo "[OpenVidu] error starting OpenVidu"; exit 1; }
|
|
||||||
|
|
||||||
# Update shared secret
|
|
||||||
/usr/local/bin/after_install.sh || { echo "[OpenVidu] error updating shared secret"; exit 1; }
|
|
||||||
|
|
||||||
# Launch on reboot
|
|
||||||
echo "@reboot /usr/local/bin/restart.sh >> /var/log/openvidu-restart.log" 2>&1 | crontab
|
|
||||||
|
|
||||||
# Wait for the app
|
# Wait for the app
|
||||||
/usr/local/bin/check_app_ready.sh
|
/usr/local/bin/check_app_ready.sh
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Reference in New Issue