You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于从Azure存储账户获取Bash脚本并在Linux VMSS中安装,以及新版本脚本可用时从Azure VMSS调用该脚本的可行性咨询

Absolutely, this is totally achievable with Azure’s native tools! Let’s walk through how to tackle both your requirements clearly.

1. Deploying a Bash Script from Azure Storage to Linux VMSS

To get your script installed on all instances in your Linux VMSS, the Custom Script Extension is your go-to tool—it’s designed exactly for this kind of post-deployment configuration. Here’s how to set it up:

  • First, ensure VMSS can access your storage account
    You have two solid options here:

    • Use a SAS token: Generate a SAS URL for your script blob with read permissions (make sure it’s valid long enough for your deployment).
    • Use a managed identity: Assign either a system-assigned or user-assigned managed identity to your VMSS, then grant that identity the Storage Blob Data Reader role on your storage account. This avoids exposing credentials directly.
  • Apply the Custom Script Extension
    Use Azure CLI to push the extension to your VMSS—this will download and execute your script on every instance. Here’s a sample command:

    az vmss extension set \
      --resource-group your-resource-group-name \
      --vmss-name your-vmss-name \
      --name CustomScript \
      --publisher Microsoft.Azure.Extensions \
      --settings '{"fileUris": ["https://yourstorageaccount.blob.core.windows.net/container/your-script.sh?<your-sas-token>"], "commandToExecute": "./your-script.sh"}'
    

    If you’re using a managed identity, you can omit the SAS token and just use the blob’s direct URI (the extension will authenticate automatically via the identity).

2. Triggering VMSS to Run the Updated Script When a New Version is Released

Yes, you can absolutely automate this! Here are three reliable approaches depending on your workflow:

  • Option 1: Reapply the Custom Script Extension manually/automatically
    When you update your script in storage, re-run the same az vmss extension set command (or update your ARM/Terraform template and redeploy). If your VMSS uses an Automatic or Rolling upgrade policy, Azure will apply the update across instances in batches (no downtime if configured properly).

  • Option 2: Automate with Event Grid + Azure Automation
    Set up a fully automated pipeline:

    1. Configure your storage account to send a BlobUpdated event to Azure Event Grid when your script is modified.
    2. Set Event Grid to trigger an Azure Automation Runbook.
    3. The Runbook runs the az vmss extension set command to reapply the script to your VMSS.
      This way, the update happens automatically as soon as you upload a new script version.
  • Option 3: Poll for updates from VMSS instances
    If you prefer a self-contained approach without external triggers, set up a cron job on each VMSS instance to check for script updates periodically:

    1. Create a small check script (save it as /opt/check-script-update.sh):
      #!/bin/bash
      REMOTE_SCRIPT_URI="https://yourstorageaccount.blob.core.windows.net/container/your-script.sh"
      LOCAL_SCRIPT="/opt/your-script.sh"
      # Get remote last modified timestamp
      REMOTE_TIMESTAMP=$(curl -sI "$REMOTE_SCRIPT_URI" | grep -i "last-modified" | awk '{sub("\r$", "", $0); print $2, $3, $4, $5, $6}')
      # Get local last modified timestamp (or default to empty if file doesn't exist)
      LOCAL_TIMESTAMP=$(stat -c "%y" "$LOCAL_SCRIPT" 2>/dev/null | awk '{print $1, $2}' || echo "")
      
      if [ "$REMOTE_TIMESTAMP" != "$LOCAL_TIMESTAMP" ]; then
          echo "New script version detected—downloading..."
          curl -o "$LOCAL_SCRIPT" "$REMOTE_SCRIPT_URI"
          chmod +x "$LOCAL_SCRIPT"
          echo "Running updated script..."
          "$LOCAL_SCRIPT"
      fi
      
    2. Make the script executable: chmod +x /opt/check-script-update.sh
    3. Add it to cron to run every 6 hours (adjust as needed):
      crontab -e
      # Add this line:
      0 */6 * * * /opt/check-script-update.sh >> /var/log/script-update.log 2>&1
      

    This way, each instance checks for updates on its own and runs the new script when available.


内容的提问来源于stack exchange,提问作者user989865

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 18:34:07