Skip to content

Commit 99e382b

Browse files
committed
chore: extra debug logging around env var replacement
1 parent 2fee900 commit 99e382b

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

src/internal/mount_manager/helpers.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
"rclone-manager/internal/config"
1313
"rclone-manager/internal/constants"
14+
"rclone-manager/internal/environment"
1415
"reflect"
1516
"strconv"
1617
"strings"
@@ -42,7 +43,7 @@ func createMountCommand(instance *MountedEndpoint, logger zerolog.Logger) *exec.
4243
fsArg := fmt.Sprintf("%s%s:", constants.Fs, instance.BackendName)
4344
mountPointArg := fmt.Sprintf("%s%s", constants.MountPoint, instance.MountPoint)
4445

45-
payloads, err := constructPayloadsFromCombinedEnvVars(currentRCDEnv, instance.EnvVars, logger)
46+
payloads, err := constructPayloadsFromCombinedEnvVars(currentRCDEnv, instance.Environment, logger)
4647
if err != nil {
4748
logger.Error().AnErr(constants.LogError, err).Str(constants.LogBackend, instance.BackendName).
4849
Msg("Failed to construct mount payloads")
@@ -57,6 +58,8 @@ func createMountCommand(instance *MountedEndpoint, logger zerolog.Logger) *exec.
5758
cmd.Stderr = os.Stderr
5859
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
5960

61+
cmd.Env = environment.PrepareEnvironment(instance.Environment)
62+
6063
return cmd
6164
}
6265

@@ -74,12 +77,17 @@ func constructPayloadsFromCombinedEnvVars(options map[string]interface{}, envVar
7477
mountTags := extractConfigTags(&mountlib.Options{}, logger)
7578
vfsTags := extractConfigTags(&vfscommon.Options{}, logger)
7679

80+
logger.Debug().Interface("envVars", envVars).Msg("Augmenting options with environment variables")
81+
82+
vfsEnvs := envVars
83+
mountEnvs := envVars
84+
7785
// Update options using extracted config tags
78-
updateOptionsWithEnv(vfsOptions, envVars, "vfs", vfsTags, logger)
79-
updateOptionsWithEnv(mountOptions, envVars, "mount", mountTags, logger)
86+
updateOptionsWithEnv(vfsOptions, vfsEnvs, "vfs", vfsTags, logger)
87+
logger.Debug().Interface("vfsOptions", vfsOptions).Msg("Updated VFS Options")
8088

89+
updateOptionsWithEnv(mountOptions, mountEnvs, "mount", mountTags, logger)
8190
logger.Debug().Interface("mountOptions", mountOptions).Msg("Updated Mount Options")
82-
logger.Debug().Interface("vfsOptions", vfsOptions).Msg("Updated VFS Options")
8391

8492
vfsPayloadJson, err := json.Marshal(vfsOptions)
8593
if err != nil {
@@ -116,6 +124,8 @@ func extractConfigTags(opt interface{}, logger zerolog.Logger) map[string]string
116124
}
117125

118126
func updateOptionsWithEnv(options map[string]interface{}, envVars map[string]string, section string, configTags map[string]string, logger zerolog.Logger) {
127+
logger.Debug().Str("section", section).Interface("options", options).Msg("Updating options from environment variables")
128+
119129
for key, value := range envVars {
120130
if strings.HasPrefix(key, fmt.Sprintf("RCLONE_%s_", strings.ToUpper(section))) {
121131
cleanKey := strings.TrimPrefix(key, fmt.Sprintf("RCLONE_%s_", strings.ToUpper(section)))
@@ -224,7 +234,7 @@ func setupMountsFromConfig(conf *config.Config, logger zerolog.Logger) {
224234
instance := &MountedEndpoint{
225235
BackendName: mount.BackendName,
226236
MountPoint: mount.MountPoint,
227-
EnvVars: mount.Environment,
237+
Environment: mount.Environment,
228238
}
229239
if existing, ok := getMountedEndpoint(mount.BackendName); ok {
230240
if existing.MountPoint != instance.MountPoint {

src/internal/mount_manager/mount.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
type MountedEndpoint struct {
1717
BackendName string
1818
MountPoint string
19-
EnvVars map[string]string
19+
Environment map[string]string
2020
}
2121

2222
func SetRCDEnv(env map[string]interface{}) {
@@ -37,7 +37,7 @@ func InitializeMounts(conf *config.Config, logger zerolog.Logger, processLock *s
3737
instance := &MountedEndpoint{
3838
BackendName: mount.BackendName,
3939
MountPoint: mount.MountPoint,
40-
EnvVars: mount.Environment,
40+
Environment: mount.Environment,
4141
}
4242
StartMountWithRetries(instance, logger)
4343
}

src/internal/serve_manager/helpers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func createServeCommand(instance *ServeProcess) *exec.Cmd {
2626
cmd.Stdout = os.Stdout
2727
cmd.Stderr = os.Stderr
2828

29-
cmd.Env = environment.PrepareEnvironment(instance.EnvVars)
29+
cmd.Env = environment.PrepareEnvironment(instance.Environment)
3030

3131
return cmd
3232
}
@@ -42,10 +42,10 @@ func untrackServe(instance *ServeProcess) {
4242
func setupServesFromConfig(conf *config.Config, logger zerolog.Logger) {
4343
for _, serve := range conf.Serves {
4444
instance := &ServeProcess{
45-
Backend: serve.BackendName,
46-
Protocol: serve.Protocol,
47-
Addr: serve.Addr,
48-
EnvVars: serve.Environment,
45+
Backend: serve.BackendName,
46+
Protocol: serve.Protocol,
47+
Addr: serve.Addr,
48+
Environment: serve.Environment,
4949
}
5050
if existing, ok := getServeInstance(serve.BackendName); ok {
5151
if existing.Protocol != serve.Protocol || existing.Addr != serve.Addr {

src/internal/serve_manager/monitor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func MonitorServeProcesses(logger zerolog.Logger) {
3939
Msgf("Process (PID: %d) died. Restarting...", serveProcess.PID)
4040

4141
newServe := &ServeProcess{
42-
Backend: serveProcess.Backend,
43-
Protocol: serveProcess.Protocol,
44-
Addr: serveProcess.Addr,
45-
EnvVars: serveProcess.EnvVars,
42+
Backend: serveProcess.Backend,
43+
Protocol: serveProcess.Protocol,
44+
Addr: serveProcess.Addr,
45+
Environment: serveProcess.Environment,
4646
}
4747

4848
newProcess := StartServeWithRetries(newServe, logger)

src/internal/serve_manager/serve.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ServeProcess struct {
1717
Addr string
1818
StartedAt time.Time
1919
GracePeriod time.Duration
20-
EnvVars map[string]string
20+
Environment map[string]string
2121
}
2222

2323
var (
@@ -41,10 +41,10 @@ func InitializeServeEndpoints(conf *config.Config, logger zerolog.Logger, proces
4141
logger.Info().Msg("Initializing all serve endpoints")
4242
for _, serve := range conf.Serves {
4343
instance := &ServeProcess{
44-
Backend: serve.BackendName,
45-
Protocol: serve.Protocol,
46-
Addr: serve.Addr,
47-
EnvVars: serve.Environment,
44+
Backend: serve.BackendName,
45+
Protocol: serve.Protocol,
46+
Addr: serve.Addr,
47+
Environment: serve.Environment,
4848
}
4949
StartServeWithRetries(instance, logger)
5050
}

0 commit comments

Comments
 (0)