/
main.go
82 lines (64 loc) · 2.08 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"flag"
"os"
"os/signal"
"sync"
"syscall"
log "github.com/cihub/seelog"
dns "github.com/chrusty/dns-from-aws/dns"
hostinventory "github.com/chrusty/dns-from-aws/hostinventory"
types "github.com/chrusty/dns-from-aws/types"
)
var (
roleTag = flag.String("roletag", "role", "Instance tag to derive the 'role' from")
environmentTag = flag.String("environmenttag", "environment", "Instance tag to derive the 'environment' from")
dnsTTL = flag.Int("dnsttl", 300, "TTL for any DNS records created")
hostUpdateFreq = flag.Int("hostupdate", 60, "How many seconds to sleep between updating the list of hosts from AWS")
dnsUpdateFreq = flag.Int("dnsupdate", 60, "How many seconds to sleep between updating DNS records from the host-list")
dnsDomainName = flag.String("domainname", "domain.com.", "The DNS domain to use (including trailing '.')")
awsRegion = flag.String("awsregion", "eu-west-1", "The AWS region to connect to")
)
func init() {
// Parse the command-line arguments:
flag.Parse()
}
func main() {
// Make sure we flush the log before quitting:
defer log.Flush()
var hostInventoryMutex sync.Mutex
var hostInventory types.HostInventory
// Configuration object for the HostInventoryUpdater:
config := types.Config{
HostUpdateFrequency: *hostUpdateFreq,
DNSUpdateFrequency: *dnsUpdateFreq,
RoleTag: *roleTag,
EnvironmentTag: *environmentTag,
DNSDomainName: *dnsDomainName,
AWSRegion: *awsRegion,
DNSTTL: *dnsTTL,
HostInventory: hostInventory,
HostInventoryMutex: hostInventoryMutex,
}
// Run the host-inventory-updater:
go hostinventory.Updater(&config)
// Run the dns-updater:
go dns.Updater(&config)
// Run until we get a kill-signal:
runUntilKillSignal()
}
// Wait for a signal from the OS:
func runUntilKillSignal() {
// Intercept quit signals:
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
// Handle stop / quit events:
for {
select {
case <-sigChan:
log.Infof("Bye!")
log.Flush()
os.Exit(0)
}
}
}