-
Notifications
You must be signed in to change notification settings - Fork 31
/
machine.go
41 lines (33 loc) · 1.04 KB
/
machine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2019-2021, R.I. Pienaar and the Choria Project contributors
//
// SPDX-License-Identifier: Apache-2.0
package server
import (
"context"
"os"
"sync"
"github.com/choria-io/go-choria/aagent"
"github.com/choria-io/go-choria/internal/util"
)
// StartMachine starts the choria machine instances
func (srv *Instance) StartMachine(ctx context.Context, wg *sync.WaitGroup) (err error) {
if srv.fw.ProvisionMode() {
return
}
if srv.cfg.Choria.MachineSourceDir == "" {
srv.log.Info("Choria Autonomous Agent source directory not configured, skipping initialization")
return nil
}
if !util.FileIsDir(srv.cfg.Choria.MachineSourceDir) {
srv.log.Warnf("Choria Autonomous Agent source directory configured as %s but it does not exist, creating empty directory", srv.cfg.Choria.MachineSourceDir)
err := os.MkdirAll(srv.cfg.Choria.MachineSourceDir, 0700)
if err != nil {
return err
}
}
srv.machines, err = aagent.New(srv.cfg.Choria.MachineSourceDir, srv)
if err != nil {
return err
}
return srv.machines.ManageMachines(ctx, wg)
}