There are many scenarios where you want to run custom initialization logic when a Databricks cluster starts up. Installing OS libraries, deploying security agents, setting environment variables, launching monitoring tools — init scripts are an essential mechanism for customizing the cluster environment. This article organizes everything from init script types, storage locations, execution order, and constraints to troubleshooting.
Init scripts are divided into the following three types based on their scope and configuration method.
| Type | Scope | Configuration Method | Status |
|---|---|---|---|
| Cluster-scoped Init Script | Specific cluster only | Specified in the cluster settings Advanced options | Recommended (current standard) |
| Global Init Script | All clusters within the workspace | Registered via Admin Settings → Global Init Scripts | Recommended (for administrators) |
| Legacy Global Init Script (DBFS) | All clusters within the workspace | Placed at a specific DBFS path (/databricks/init/) | Deprecated; being phased out |
Use Cluster-scoped Init Scripts when you want to apply a custom environment to a specific cluster, and use Global Init Scripts for logic you want to run uniformly across all clusters, such as security agents.
| Location | Example Path | Unity Catalog Managed | Recommendation |
|---|---|---|---|
| Unity Catalog Volumes | /Volumes/catalog/schema/volume/init.sh | Supported (permissions and audit logs integrated) | Most recommended |
| Workspace Files | /Workspace/Shared/init-scripts/init.sh | Managed via Workspace ACLs | Recommended |
| DBFS (dbfs:/) | dbfs:/init-scripts/init.sh | Not supported | Not recommended |
| Direct cloud storage | s3://bucket/init-scripts/init.sh | Not supported | Legacy environments only |
In Unity Catalog environments, placing scripts in Volumes is the best practice. When you place scripts in Volumes, access is managed by the Unity Catalog permission model, and you get audit logs showing who changed the script and when.
When multiple init scripts exist at cluster startup, they execute in the following order.
Because Global Init Scripts run first, a common design pattern is to handle baseline configuration shared across all clusters (security, monitoring) in Global scripts, and to handle cluster-specific customization (such as installing particular libraries) in Cluster-scoped scripts.
Within each script, shell commands run from top to bottom. If a non-zero exit code such as exit 1 is returned partway through, the cluster startup fails.
#!/bin/bash
# Set environment variables
echo "export ENVIRONMENT=production" >> /etc/environment
# Install OS-level packages
apt-get update -y && apt-get install -y libgeos-dev
# Install additional Python libraries
/databricks/python/bin/pip install geopy==2.4.1
# Launch monitoring agent
if [ -f /opt/monitoring/agent.sh ]; then
/opt/monitoring/agent.sh start
fiIt is important to write scripts to be idempotent (producing the same result no matter how many times they run). Init scripts re-execute every time a cluster restarts or resizes, so make sure that reinstalling already-installed packages causes no problems.
On Shared Access Mode clusters (clusters shared by multiple users), there are important constraints on init scripts.
On Single User Access Mode clusters, Cluster-scoped Init Scripts can be used. This distinction is a frequent exam topic.
The results of init script execution are saved to logs on the cluster's driver node.
| Log Location | Contents | How to Inspect |
|---|---|---|
| Event Log in the cluster UI | Summary of init script success/failure | Cluster details screen → Event Log |
| Driver logs (/databricks/init_scripts/) | stdout and stderr for each script | Cluster details screen → Driver Logs → Init Scripts |
| Cluster log delivery destination | Logs delivered to S3/ADLS/GCS, etc. | The destination configured in Log Delivery settings |
Init scripts cannot run on Serverless Compute (SQL Warehouse Serverless / Serverless Notebooks). Because the Serverless environment is fully managed by Databricks, OS-level customization by users is not permitted.
To add libraries in a Serverless environment, use the following approaches.
%pip install within a notebook%pip install /Volumes/...set -ex at the top of the script to enable debug output-y flag is set--timeout or --retry optionsif [ ! -f /opt/already_installed ]; then ...)Data Engineer Professional
問題 1
A security team wants to automatically install a monitoring agent on every cluster in the workspace. Clusters exist in both Shared Access Mode and Single User Access Mode. Which approach is best?
正解: B
Shared Access Mode clusters cannot use Cluster-scoped Init Scripts, so option A would not work on some clusters. Global Init Scripts run on every cluster regardless of access mode, making them ideal for uniform agent distribution. Manual execution from a notebook depends on each user and is not reliable, and Cluster Policy is not a feature that controls the contents of init scripts.
Why can't init scripts be used with Serverless Compute?
Serverless Compute is a fully managed environment that does not allow users to perform OS-level operations. Because init scripts run in the cluster node's shell, they are fundamentally incompatible with the Serverless security model. To add libraries in a Serverless environment, use %pip install or the Workspace Libraries feature.
What happens to a cluster when an init script fails?
An init script failure causes the cluster startup to fail. The cluster event log records INIT_SCRIPT_FAILURE, and stdout/stderr are saved under init_scripts/ in the driver logs. There is no setting to ignore failures and continue startup, so script idempotency and robust error handling are critical.
Is placing init scripts in DBFS deprecated?
Yes. Init scripts on DBFS (including Legacy Global Init Scripts) are being phased out. Placement in Unity Catalog Volumes or Workspace Files is recommended. Placing scripts in Volumes gives you the benefits of Unity Catalog's permission management and version control.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Databricks Certifications: All 7 Exams, Difficulty & Study Plan (2026)
Complete guide to all 7 Databricks certifications — Data Eng...
Databricks Exam Difficulty Ranking: All 7 Certs Compared (2026)
Every Databricks certification ranked by difficulty, with st...
Databricks Study Guide: Fastest Pass Route & Time Estimates (2026)
How to pass Databricks certifications efficiently. Official ...
Databricks Data Engineer Associate: Complete Guide (2026)
Domain-by-domain breakdown of the Databricks Certified Data ...
Databricks Data Engineer Professional: Complete Guide (2026)
Tactics for the Databricks Certified Data Engineer Professio...