-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
84 lines (67 loc) · 2.87 KB
/
main.go
File metadata and controls
84 lines (67 loc) · 2.87 KB
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
83
84
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/edvakf/go-pploy/models/datadog"
"github.com/edvakf/go-pploy/models/hook"
"github.com/edvakf/go-pploy/models/ldapusers"
"github.com/edvakf/go-pploy/models/locks"
"github.com/edvakf/go-pploy/models/workdir"
"github.com/edvakf/go-pploy/web"
"github.com/facebookarchive/pidfile"
)
var GitCommit string
func main() {
web.Server()
}
func init() {
// commit hash is passed at build time with -ldflags
fmt.Printf("commit: %s\n", GitCommit)
var lockDuration time.Duration
var workDir string
var sc hook.SlackConfig
var dc datadog.DatadogConfig
var lc ldapusers.Config
flag.DurationVar(&lockDuration, "lock", 10*time.Minute, "Duration (ex. 10m) for lock gain")
flag.StringVar(&workDir, "workdir", "", "Working directory")
flag.IntVar(&workdir.LogMax, "logmax", 20, "Max number of log files to keep")
flag.StringVar(&web.PathPrefix, "prefix", "/", "Path prefix of the app (eg. /pploy/), useful for proxied apps")
flag.IntVar(&web.Port, "port", 9000, "HTTP port")
flag.StringVar(&sc.WebHookURL, "webhook", "", "Incoming web hook URL for slack notification")
flag.StringVar(&sc.LockGainedMessage, "lockgained", "", "Message template for when lock is gained")
flag.StringVar(&sc.LockReleasedMessage, "lockreleased", "", "Message template for when lock is released")
flag.StringVar(&sc.LockExtendedMessage, "lockextended", "", "Message template for when lock is extended")
flag.StringVar(&sc.DeployedMessage, "deployed", "", "Message template for when deploy is ended")
flag.StringVar(&dc.APIKey, "ddapikey", "", "Datadog API key")
flag.StringVar(&dc.APPKey, "ddappkey", "", "Datadog APP key")
flag.StringVar(&dc.LockGainedMessage, "ddlockgained", "", "Message template for Datadog when lock is gained")
flag.StringVar(&dc.LockReleasedMessage, "ddlockreleased", "", "Message template for Datadog when lock is released")
flag.StringVar(&dc.LockExtendedMessage, "ddlockextended", "", "Message template for Datadog when lock is extended")
flag.StringVar(&dc.DeployedMessage, "dddeployed", "", "Message template for Datadog when deploy is ended")
flag.StringVar(&lc.Host, "ldaphost", "", "LDAP host (leave empty if ldap is not needed)")
flag.IntVar(&lc.Port, "ldapport", 389, "LDAP port")
flag.StringVar(&lc.BaseDN, "ldapdn", "", "LDAP base DN of user list")
flag.DurationVar(&lc.CacheTTL, "ldapttl", 10*time.Minute, "LDAP cache TTL")
flag.Parse()
if workDir == "" {
log.Fatalf("Please set workdir flag")
}
if pidfile.GetPidfilePath() != "" {
err := pidfile.Write()
if err != nil {
log.Fatalf("failed to create pid file:%s", err.Error())
}
pidValue, err := pidfile.Read()
fmt.Printf("pid:%d\n", pidValue)
if err != nil {
log.Fatalf("failed to read pid file:%s", err.Error())
}
}
locks.SetDuration(lockDuration)
workdir.Init(workDir)
hook.SetSlackConfig(sc)
datadog.SetDatadogConfig(dc)
ldapusers.SetConfig(lc)
}