Skip to content

Conversation

@aldenh-viam
Copy link
Contributor

The advanced_settings section of the config now supports viam_server_env to pass user-specified environment variables to viam-server and its children.

Example:

. . . 
"advanced_settings": {
    "viam_server_env": {
      "MODULE_DEBUG": "1",
      "BLUETOOTH": "FALSE",
    }
}
. . . 

Keys and values must both be strings. To unset, remove from the mapping.

Note all of the existing environment variables from Agent's current environment currently also gets passed to viam-server, e.g. HOME, PWD, TERM, PATH, etc.

@aldenh-viam aldenh-viam requested a review from cheukt May 20, 2025 13:37
@aldenh-viam aldenh-viam changed the title RSDK-10704: Config: new setting viam_server_env to pass environment variables to viam-server RSDK-10704, RSDK-10292: Config: new setting viam_server_env to pass environment variables to viam-server May 20, 2025
@cheukt cheukt requested review from benjirewis and jmatth and removed request for benjirewis May 20, 2025 14:31
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the viam-server restart if you update env vars on app.viam.com?

@aldenh-viam
Copy link
Contributor Author

aldenh-viam commented May 20, 2025

does the viam-server restart if you update env vars on app.viam.com?

I don't believe it does (for any config change). It gets downloaded, but only restarts if there's a new viam-server binary update.

EDIT: Discussed offline. Added in 0359a8a . It will only restart if it detects a change in the new "viam_server_env" section, but not if other options have changed.

2025-05-20T19:28:38.205Z INFO  viamserver/viamserver.go:109    Adding environment variables from config to viam-server startup map[test1:test1234 test2:testab4c]
2025-05-20T19:28:45.188Z DEBUG agent/manager.go:289            Checking cloud for update
2025-05-20T19:28:45.500Z INFO  agent/manager.go:222            Detected changed environment variables. Restarting viam-server at next opportunity.     {"current":null,"previous":{"test1":"test1234","test2":"testab4c"}}
2025-05-20T19:28:45.503Z INFO  viamserver/viamserver.go:411    will restart viam-server to run new version, as it has reported allowance of a restart
2025-05-20T19:28:45.503Z INFO  viamserver/viamserver.go:201    Stopping viam-server

2025-05-20T19:28:51.457Z INFO  viamserver/viamserver.go:95     Starting viam-server
2025-05-20T19:29:17.636Z DEBUG agent/manager.go:289            Checking cloud for update
2025-05-20T19:29:17.799Z INFO  agent/manager.go:222            Detected changed environment variables. Restarting viam-server at next opportunity.     {"current":{"test1":"test1234"},"previous":null}
2025-05-20T19:29:17.801Z INFO  viamserver/viamserver.go:411    will restart viam-server to run new version, as it has reported allowance of a restart
2025-05-20T19:29:17.801Z INFO  viamserver/viamserver.go:201    Stopping viam-server

2025-05-20T19:29:23.233Z INFO  viamserver/viamserver.go:95     Starting viam-server
2025-05-20T19:29:23.233Z INFO  viamserver/viamserver.go:109    Adding environment variables from config to viam-server startup map[test1:test1234]
2025-05-20T19:29:54.261Z DEBUG agent/manager.go:289            Checking cloud for update
2025-05-20T19:29:54.397Z INFO  agent/manager.go:222            Detected changed environment variables. Restarting viam-server at next opportunity.     {"current":{"test1":"test12345"},"previous":{"test1":"test1234"}}
2025-05-20T19:29:54.400Z INFO  viamserver/viamserver.go:411    will restart viam-server to run new version, as it has reported allowance of a restart
2025-05-20T19:29:54.400Z INFO  viamserver/viamserver.go:201    Stopping viam-server

2025-05-20T19:30:00.447Z INFO  viamserver/viamserver.go:95     Starting viam-server
2025-05-20T19:30:00.447Z INFO  viamserver/viamserver.go:109    Adding environment variables from config to viam-server startup map[test1:test12345]

@aldenh-viam
Copy link
Contributor Author

Added auto restart: #116 (comment)

@aldenh-viam aldenh-viam requested a review from cheukt May 20, 2025 19:41
Copy link
Member

@cheukt cheukt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@jmatth jmatth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor comments from me, optimistically LGTM.

DisableNetworkConfiguration: Tribool(0),
DisableSystemConfiguration: Tribool(0),
ViamServerStartTimeoutMinutes: Timeout(time.Minute * 10),
ViamServerExtraEnvVars: nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nil is the empty value for map in go, you don't need this line here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't NEED it, but you don't need a lot of the other zero-values in this block either. They're here to make code more understandable, and to guard against any accidental change of type(s) in the future. E.g. it's easier to look at a "complete" structure here than see only the non-zero fields.

tl;dr I'd prefer it stay.

defer s.mu.Unlock()
s.startTimeout = time.Duration(cfg.AdvancedSettings.ViamServerStartTimeoutMinutes)

if !reflect.DeepEqual(cfg.AdvancedSettings.ViamServerExtraEnvVars, s.extraEnvVars) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the new maps.Equal over reflect. It should accomplish the same thing with better performance in situations like this where we know all the types.

@aldenh-viam aldenh-viam merged commit 639dec8 into viamrobotics:main May 22, 2025
3 checks passed
@aldenh-viam aldenh-viam deleted the RSDK-10704 branch May 22, 2025 17:10
@atlassian
Copy link

atlassian bot commented Sep 22, 2025

🔗 Link your GitHub account to Atlassian

To enable Code Reviewer, please link your GitHub account to your Atlassian account.

Click here to connect your accounts

This is a one-time setup that takes less than a minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants