parent
7e1ba5dd4d
commit
5ab924f5ad
24
godoor.go
24
godoor.go
@ -134,7 +134,7 @@ func main() {
|
|||||||
godoorBuildInfo.WithLabelValues(Version, Commit).Set(1)
|
godoorBuildInfo.WithLabelValues(Version, Commit).Set(1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
setup()
|
setup(ctx)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
@ -188,7 +188,7 @@ func loadConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup() {
|
func setup(ctx context.Context) {
|
||||||
log.Println("Started Setup")
|
log.Println("Started Setup")
|
||||||
|
|
||||||
if config.mock {
|
if config.mock {
|
||||||
@ -239,6 +239,8 @@ func setup() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
go listenSig1(ctx, wiegand)
|
||||||
|
|
||||||
log.Println("Initialized longpoll event loop")
|
log.Println("Initialized longpoll event loop")
|
||||||
|
|
||||||
go cardRunner(wiegand)
|
go cardRunner(wiegand)
|
||||||
@ -246,6 +248,24 @@ func setup() {
|
|||||||
log.Println("Setup completed")
|
log.Println("Setup completed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listenSig1(ctx context.Context, wiegand Wiegand) {
|
||||||
|
usrSig := make(chan os.Signal)
|
||||||
|
signal.Notify(usrSig, syscall.SIGUSR1)
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-usrSig:
|
||||||
|
err := OpenAndCloseDoor(wiegand)
|
||||||
|
log.Printf("Emergecy opening door as prompted by SIGUSR1")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("opening door: %v", err)
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runHttpServer() {
|
func runHttpServer() {
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
log.Printf("Running prometheus metrics on http://%s/metrics", config.prometheusMetricsBind)
|
log.Printf("Running prometheus metrics on http://%s/metrics", config.prometheusMetricsBind)
|
||||||
|
Loading…
Reference in New Issue
Block a user