split webgui,main from server.go
[arvados.git] / services / boot / config.go
1 package main
2
3 import (
4         "context"
5         "fmt"
6         "os"
7 )
8
9 type Config struct {
10         // 5 alphanumeric chars. Must be either xx*, yy*, zz*, or
11         // globally unique.
12         SiteID string
13
14         // Hostnames or IP addresses of control hosts. Use at least 3
15         // in production. System functions only when a majority are
16         // alive.
17         ControlHosts []string
18         Ports        portsConfig
19         WebGUI       webguiConfig
20         DataDir      string
21         UsrDir       string
22         RunitSvDir   string
23 }
24
25 type portsConfig struct {
26         ConsulDNS     int
27         ConsulHTTP    int
28         ConsulHTTPS   int
29         ConsulRPC     int
30         ConsulSerfLAN int `json:"Serf_LAN"`
31         ConsulSerfWAN int `json:"Serf_WAN"`
32         ConsulServer  int
33 }
34
35 type webguiConfig struct {
36         // addr:port to serve web-based setup/monitoring
37         // application
38         Listen string
39 }
40
41 func (c *Config) Boot(ctx context.Context) error {
42         for _, path := range []string{c.DataDir, c.UsrDir, c.UsrDir + "/bin"} {
43                 if fi, err := os.Stat(path); err != nil {
44                         err = os.MkdirAll(path, 0755)
45                         if err != nil {
46                                 return err
47                         }
48                 } else if !fi.IsDir() {
49                         return fmt.Errorf("%s: is not a directory", path)
50                 }
51         }
52         return nil
53 }
54
55 func DefaultConfig() *Config {
56         return &Config{
57                 ControlHosts: []string{"127.0.0.1"},
58                 Ports: portsConfig{
59                         ConsulDNS:     18600,
60                         ConsulHTTP:    18500,
61                         ConsulHTTPS:   -1,
62                         ConsulRPC:     18400,
63                         ConsulSerfLAN: 18301,
64                         ConsulSerfWAN: 18302,
65                         ConsulServer:  18300,
66                 },
67                 DataDir:    "/var/lib/arvados",
68                 UsrDir:     "/usr/local/arvados",
69                 RunitSvDir: "/etc/sv",
70                 WebGUI: webguiConfig{
71                         Listen: "127.0.0.1:18000",
72                 },
73         }
74 }