Stay organized with collections
Save and categorize content based on your preferences.
Create a startup script
This page describes how to create a startup script for the web service and then validate the script.
To ensure that bringing up the web service does not require manual intervention, you must create a startup script.The startup script does the following tasks:
Reads the virtual machine (VM) metadata and sets the environment variable for metadata with the CONNECTOR_ENV prefix. Any data required by consumers is taken during VM creation from Marketplace and is set as environment variables in docker. These environment variables can then be read and processed accordingly in the application.
Starts the docker container containing the web service with the appropriate environment variables.
The following code is a sample startup script:
#!/bin/bash# 1. Fetch Metadata Keysmetadata_keys_url="http://metadata.google.internal/computeMetadata/v1/instance/attributes/"metadata_keys=$(curl-H"Metadata-Flavor: Google""$metadata_keys_url")# 2. Set Environment Variables for CONNECTOR_ENV Keys (with error handling)forkeyin$metadata_keys;doif[[$key==CONNECTOR_ENV_*]];thenmetadata_value_url="http://metadata.google.internal/computeMetadata/v1/instance/attributes/$key"# Fetch value with error handlingvalue=$(curl-H"Metadata-Flavor: Google""$metadata_value_url"2>/dev/null)if[[-z"$value"]];thenecho"Warning: No value found for key '$key'. Skipping.">&2# Log the warning to stderrcontinue# Skip to the next iterationfiexport"$key=$value"fidone# 3. Run Docker with Environment Variables
sudodockerstopconnector-service||true
sudodockerrun\--nameconnector-service\$(env|grepCONNECTOR_ENV_|sed's/=/="/;s/$/"/'|sed's/^/-e /')\-d-p$CONNECTOR_ENV_PORT:$CONNECTOR_ENV_PORT\--restart=unless-stopped\connector-container
Validate the startup script
In the VM instance, add the metadata for the port and all other parameters which are required during VM creation.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[[["\u003cp\u003ePre-GA products and features, as described here, are subject to the "Pre-GA Offerings Terms" and are provided "as is" with potential limitations in support.\u003c/p\u003e\n"],["\u003cp\u003eA startup script is crucial for web services to eliminate manual intervention during startup, as the script automatically reads VM metadata and sets environment variables.\u003c/p\u003e\n"],["\u003cp\u003eThe provided sample startup script fetches metadata, sets environment variables prefixed with \u003ccode\u003eCONNECTOR_ENV\u003c/code\u003e, and starts a Docker container with these variables, ensuring the web service runs.\u003c/p\u003e\n"],["\u003cp\u003eTo validate the script, you need to add necessary metadata to the VM, add the startup script to the VM's configuration, and execute the script using the \u003ccode\u003egoogle_metadata_script_runner\u003c/code\u003e to verify docker is running.\u003c/p\u003e\n"],["\u003cp\u003eAfter testing the docker service should be removed from the vm.\u003c/p\u003e\n"]]],[],null,["# Create a startup script\n\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nCreate a startup script\n=======================\n\nThis page describes how to create a startup script for the web service and then validate the script.\n\nTo ensure that bringing up the web service does not require manual intervention, you must create a startup script.The startup script does the following tasks:\n\n- Reads the virtual machine (VM) metadata and sets the environment variable for metadata with the `CONNECTOR_ENV` prefix. Any data required by consumers is taken during VM creation from Marketplace and is set as environment variables in docker. These environment variables can then be read and processed accordingly in the application.\n- Starts the docker container containing the web service with the appropriate environment variables.\n\nThe following code is a sample startup script: \n\n```bash\n#!/bin/bash\n\n# 1. Fetch Metadata Keys\nmetadata_keys_url=\"http://metadata.google.internal/computeMetadata/v1/instance/attributes/\"\nmetadata_keys=$(curl -H \"Metadata-Flavor: Google\" \"$metadata_keys_url\")\n\n# 2. Set Environment Variables for CONNECTOR_ENV Keys (with error handling)\nfor key in $metadata_keys; do\n if [[ $key == CONNECTOR_ENV_* ]]; then\n metadata_value_url=\"http://metadata.google.internal/computeMetadata/v1/instance/attributes/$key\"\n\n # Fetch value with error handling\n value=$(curl -H \"Metadata-Flavor: Google\" \"$metadata_value_url\" 2\u003e/dev/null)\n if [[ -z \"$value\" ]]; then\n echo \"Warning: No value found for key '$key'. Skipping.\" \u003e&2 # Log the warning to stderr\n continue # Skip to the next iteration\n fi\n export \"$key=$value\"\n fi\ndone\n\n# 3. Run Docker with Environment Variables\nsudo docker stop connector-service || true\nsudo docker run \\\n --name connector-service \\\n $(env | grep CONNECTOR_ENV_ | sed 's/=/=\"/;s/$/\"/' | sed 's/^/-e /') \\\n -d -p $CONNECTOR_ENV_PORT:$CONNECTOR_ENV_PORT \\\n --restart=unless-stopped \\\n connector-container\n```\n\n### Validate the startup script\n\n1. In the VM instance, add the metadata for the port and all other parameters which are required during VM creation. \n\n ```bash\n gcloud compute instances add-metadata VM_NAME \\ \n --zone=VM_ZONE \\\n --project=PROJECT_NAME \\\n --metadata=CONNECTOR_ENV_PORT=8081\n ```\n2. Edit the VM from UI and add the startup script mentioned in the automation section.\n You can also use the following gcloud command:\n\n ```bash\n gcloud compute instances add-metadata VM_NAME \\ \n --zone=VM_ZONE \\\n --project=PROJECT_NAME \\\n --metadata-from-file startup-script=gcp-start.sh\n ```\n3. After adding the startup script, ssh to the VM and run the following command: \n\n ```bash\n sudo google_metadata_script_runner startup\n ```\n4. Run the following command to ensure that the docker container is running on the mentioned port. \n\n ```bash\n sudo docker ps\n ```\n5. Run the following command to stop and remove the docker service. After testing, the service must not be running on the VM. \n\n ```bash\n sudo docker rm -f connector-service\n ```\n\nWhat's next\n-----------\n\n - Learn how to [create a VM deployment script](/integration-connectors/docs/marketplace/create-vm-deploy-tf)."]]