ping db in health check
This commit is contained in:
parent
e0b15c18ce
commit
c6aaa37f2d
3 changed files with 51 additions and 13 deletions
12
db.go
12
db.go
|
@ -1,6 +1,7 @@
|
|||
package headscale
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
@ -220,6 +221,17 @@ func (h *Headscale) setValue(key string, value string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *Headscale) pingDB() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
db, err := h.db.DB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return db.PingContext(ctx)
|
||||
}
|
||||
|
||||
// This is a "wrapper" type around tailscales
|
||||
// Hostinfo to allow us to add database "serialization"
|
||||
// methods. This allows us to use a typed values throughout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue