forked from phsm/cameraleech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (50 loc) · 1.45 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
package main
import (
"net/http"
"os"
"os/signal"
"runtime"
"sync"
"syscall"
log "github.com/sirupsen/logrus"
)
var (
cond *sync.Cond
commit string // value is provided in compilation phase (see Makefile)
builtat string // value is provided in compilation phase (see Makefile)
programIsStopping bool // if the main program is stopping, it should be set to true
httpServer *http.Server
)
func main() {
parseFlags()
log.Infof("Cameraleech commit %s, built at %s, %s started", commit, builtat, runtime.Version())
// subscribing on SIGINT, SIGTERM - graceful shutdown of ffmpegs
// Also SIGHUP for reload
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
go signalWatcher(signalChan)
if err := readConfig(configPath); err != nil {
log.Fatalf("Can not read config: %s", err)
}
// print hints
hints()
err := launchLeeches()
if err != nil {
log.Errorf("Couldn't launch camera leeches: %v", err)
}
log.Info("Camera leeches are launched")
httpRouter := newRouter()
http.Handle("/", httpRouter)
httpServer := &http.Server{Addr: config.httpListenAddress, Handler: httpRouter}
go func() {
if err := httpServer.ListenAndServe(); err != nil {
log.Fatalf("Error listening http stats server: %v", err)
}
}()
cond = &sync.Cond{L: &sync.Mutex{}}
cond.L.Lock()
for !programIsStopping || len(leeches) > 0 {
cond.Wait()
}
cond.L.Unlock()
}