-
Notifications
You must be signed in to change notification settings - Fork 29
/
daemon.go
55 lines (44 loc) · 996 Bytes
/
daemon.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
package daemon
import (
"log"
"math/rand"
"os"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"
"gopkg.in/natefinch/lumberjack.v2"
)
var mutex sync.Mutex
var shouldCache bool
var memCache bool
func InlineStart(shouldCacheArg bool, memCacheArg bool) {
shouldCache = shouldCacheArg
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
logDir := filepath.Join(home, ".envkey", "logs")
err = os.MkdirAll(logDir, os.ModePerm)
if err != nil {
panic(err)
}
log.SetOutput(&lumberjack.Logger{
Filename: filepath.Join(logDir, "envkey-source-daemon.log"),
MaxSize: 25, // megabytes
MaxBackups: 3,
MaxAge: 30, //days
Compress: false,
})
// seed rand for WS backoff and fetch jitter
rand.Seed(time.Now().UTC().UnixNano())
go startTcpServer()
go startHttpServer()
go startSuspendedWatcher()
// stop an interrupt of the client process from killing the daemon
signal.Ignore(syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
select {}
}