Skip to content

Commit

Permalink
[APP-7364] [APP-7366] [RSDK-9684] [APP-7154] Add more logging, reduce…
Browse files Browse the repository at this point in the history
… monitoring loop time, misc small fixes. (#56)
  • Loading branch information
Otterverse authored Jan 22, 2025
1 parent 4b78b6a commit 90b7f59
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions cmd/viam-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func main() {
// If the local /etc/viam.json config is corrupted, invalid, or missing (due to a new install), we can get stuck here.
// Rename the file (if it exists) and wait to provision a new one.
if !errors.Is(err, fs.ErrNotExist) {
globalLogger.Error(errors.Wrapf(err, "reading %s", absConfigPath))
globalLogger.Warn("renaming %s to %s.old", absConfigPath, absConfigPath)
if err := os.Rename(absConfigPath, absConfigPath+".old"); err != nil {
// if we can't rename the file, we're up a creek, and it's fatal
globalLogger.Error(errors.Wrapf(err, "removing invalid config file %s", absConfigPath))
Expand Down
2 changes: 1 addition & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

const (
minimalCheckInterval = time.Second * 60
minimalCheckInterval = time.Second * 5
defaultNetworkTimeout = time.Second * 15
// stopAllTimeout must be lower than systemd subsystems/viamagent/viam-agent.service timeout of 4mins
// and higher than subsystems/viamserver/viamserver.go timeout of 2mins.
Expand Down
6 changes: 3 additions & 3 deletions subsystems/provisioning/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2>Smart Machine Setup</h2>
<div class="form-group">
<label for="network">Network</label>
{{if eq (len .VisibleSSIDs) 0}}
<input type="text" name="ssid" placeholder="Enter Wifi SSID" id="network" required>
<input type="text" name="ssid" placeholder="Enter Wifi SSID" id="network" required autocorrect="off" autocapitalize="off">
{{else}}
<div class="select-border">
<select name="ssid" id="network" required>
Expand All @@ -52,14 +52,14 @@ <h2>Smart Machine Setup</h2>

<div class="form-group">
<label for="password">Password</label>
<input type="text" name="password" id="password" placeholder="Password">
<input type="text" name="password" id="password" placeholder="Password" autocorrect="off" autocapitalize="off">
</div>
{{end}}

{{if not .IsConfigured}}
<div class="form-group">
<label for="viamconfig">Device Config</label>
<textarea type="textarea" name="viamconfig" id="viamconfig" required placeholder="No config found on device. Paste your viam.json file here."></textarea>
<textarea type="textarea" name="viamconfig" id="viamconfig" required placeholder="No config found on device. Paste your viam.json file here." autocorrect="off" autocapitalize="off"></textarea>
</div>
{{end}}

Expand Down
34 changes: 19 additions & 15 deletions subsystems/viamagent/viamagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ func Install(logger logging.Logger) error {
return errw.Wrap(err, "getting service file path")
}

//nolint:gosec
if err := os.MkdirAll(filepath.Dir(serviceFilePath), 0o755); err != nil {
return errw.Wrapf(err, "creating directory %s", filepath.Dir(serviceFilePath))
}
// use this later to avoid re-enabling an existing agent service a user might have disabled
_, err = os.Stat(serviceFilePath)
newInstall := err != nil

logger.Infof("writing systemd service file to %s", serviceFilePath)
//nolint:gosec
if err := os.WriteFile(serviceFilePath, serviceFileContents, 0o644); err != nil {

newFile, err := agent.WriteFileIfNew(serviceFilePath, serviceFileContents)
if err != nil {
return errw.Wrapf(err, "writing systemd service file %s", serviceFilePath)
}

Expand All @@ -143,17 +143,21 @@ func Install(logger logging.Logger) error {
}
}

logger.Infof("enabling systemd viam-agent service")
cmd = exec.Command("systemctl", "daemon-reload")
output, err = cmd.CombinedOutput()
if err != nil {
return errw.Wrapf(err, "running 'systemctl daemon-reload' output: %s", output)
if newFile {
cmd = exec.Command("systemctl", "daemon-reload")
output, err = cmd.CombinedOutput()
if err != nil {
return errw.Wrapf(err, "running 'systemctl daemon-reload' output: %s", output)
}
}

cmd = exec.Command("systemctl", "enable", "viam-agent")
output, err = cmd.CombinedOutput()
if err != nil {
return errw.Wrapf(err, "running 'systemctl enable viam-agent' output: %s", output)
if newInstall {
logger.Infof("enabling systemd viam-agent service")
cmd = exec.Command("systemctl", "enable", "viam-agent")
output, err = cmd.CombinedOutput()
if err != nil {
return errw.Wrapf(err, "running 'systemctl enable viam-agent' output: %s", output)
}
}

_, err = os.Stat("/etc/viam.json")
Expand Down
3 changes: 3 additions & 0 deletions subsystems/viamserver/viamserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func (s *viamServer) Start(ctx context.Context) error {
s.logger.Errorw("non-zero exit code", "exit code", s.lastExit)
}
}
if s.shouldRun {
s.logger.Infof("%s exited unexpectedly and will be restarted shortly", SubsysName)
}
close(s.exitChan)
}()

Expand Down

0 comments on commit 90b7f59

Please sign in to comment.