-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (52 loc) · 1.25 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
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/BurntSushi/toml"
"github.com/gabrielperezs/sytoco/input/systemdJournald"
"github.com/gabrielperezs/sytoco/output/awsCloudwatchLogs"
)
var (
config *Config
configFile string
done = make(chan bool, 1)
)
type Config struct {
AwsCloudwatchLogs *awsCloudwatchLogs.Config
SystemdJournald *systemdJournald.Config
}
func main() {
flag.StringVar(&configFile, "config", "/usr/local/etc/systoco.conf", "Sytoco file config (toml format)")
flag.Parse()
config := &Config{
AwsCloudwatchLogs: &awsCloudwatchLogs.Config{},
}
if _, err := toml.DecodeFile(configFile, config); err != nil {
log.Panicf("Reading config file: %s", err)
}
signals()
logCli, err := awsCloudwatchLogs.New(config.AwsCloudwatchLogs)
if err != nil {
log.Panicf("Starting awsCloudwatchLogs: %s", err)
}
s := systemdJournald.New(config.SystemdJournald, logCli)
<-done
s.Exit()
logCli.Exit()
}
func signals() {
chSign := make(chan os.Signal, 10)
signal.Notify(chSign, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGINT, syscall.SIGKILL, os.Interrupt, syscall.SIGTERM)
go func() {
for {
switch <-chSign {
default:
log.Printf("Closing...")
done <- true
}
}
}()
}