@@ -30,6 +30,10 @@ const (
3030
3131 // LogFile is where supervisor logs are written.
3232 LogFile = "/var/log/spin-supervisor.log"
33+
34+ // OverlayRootEnvVar is the environment variable name used to pass
35+ // the overlay filesystem root path to the supervisor.
36+ OverlayRootEnvVar = "SPINBOX_OVERLAY_ROOT"
3337)
3438
3539// findBinary searches for the supervisor binary.
@@ -82,6 +86,29 @@ func findBinary(ctx context.Context) string {
8286//
8387// Returns nil immediately if supervisor binary is not found.
8488func RunWithMonitoring (ctx context.Context ) error {
89+ return runWithEnv (ctx , nil )
90+ }
91+
92+ // StartWithOverlayRoot starts the supervisor agent with the overlay root path
93+ // passed via environment variable. This should be called after the container's
94+ // rootfs is mounted so the supervisor can access files in the overlay.
95+ //
96+ // The overlayRoot parameter is the path to the container's mounted rootfs,
97+ // which will be passed to the supervisor via SPINBOX_OVERLAY_ROOT env var.
98+ //
99+ // This function runs in a goroutine and does not block.
100+ func StartWithOverlayRoot (ctx context.Context , overlayRoot string ) {
101+ env := []string {OverlayRootEnvVar + "=" + overlayRoot }
102+
103+ log .G (ctx ).WithField ("overlay_root" , overlayRoot ).Info ("starting supervisor with overlay root" )
104+
105+ if err := runWithEnv (ctx , env ); err != nil {
106+ log .G (ctx ).WithError (err ).Error ("supervisor monitor exited with error" )
107+ }
108+ }
109+
110+ // runWithEnv starts the supervisor with optional additional environment variables.
111+ func runWithEnv (ctx context.Context , extraEnv []string ) error {
85112 binaryPath := findBinary (ctx )
86113 if binaryPath == "" {
87114 log .G (ctx ).Info ("supervisor binary not found, skipping" )
@@ -90,5 +117,6 @@ func RunWithMonitoring(ctx context.Context) error {
90117
91118 log .G (ctx ).WithField ("path" , binaryPath ).Info ("starting supervisor with monitoring" )
92119 monitor := NewMonitor (binaryPath )
120+ monitor .SetExtraEnv (extraEnv )
93121 return monitor .Run (ctx )
94122}
0 commit comments