-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuptimed.go
More file actions
66 lines (51 loc) Β· 1.11 KB
/
Copy pathuptimed.go
File metadata and controls
66 lines (51 loc) Β· 1.11 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
package main
import (
"flag"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
func AppCleanup() {
log.Println("CLEANUP APP BEFORE EXIT!!!")
}
var (
url = flag.String(
"url",
os.Getenv("UPTIMED_URL"),
"Set the UPTIMED_URL env var or pass the url of the request that uptimed should do occasionally",
)
interval = flag.Int("interval", 30, "Set the polling interval")
)
func main() {
flag.Parse()
sleepDuration := time.Duration(*interval)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGQUIT)
signal.Notify(sigs, syscall.SIGINT)
go func() {
s := <-sigs
s.Signal()
log.Printf("RECEIVED SIGNAL: %s", s)
AppCleanup()
os.Exit(1)
}()
for {
req, err := http.NewRequest("GET", *url, nil)
if err != nil {
log.Println("Not reachable, sleeping...")
time.Sleep(sleepDuration * time.Second)
panic("Bailing out")
}
log.Println("Reached mothership.")
_, err = http.DefaultClient.Do(req)
if err != nil {
log.Println("Not reachable, sleeping...")
time.Sleep(sleepDuration * time.Second)
panic("Bailing out")
}
time.Sleep(sleepDuration * time.Second)
}
}