Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cmd/headscale/headscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"log"
"os"
"path/filepath"
"strings"
"time"

"github.com/hako/durafmt"
Expand Down Expand Up @@ -280,16 +282,28 @@ func main() {

}

func absPath(path string) string {
// If a relative path is provided, prefix it with the the directory where
// the config file was found.
if !strings.HasPrefix(path, "/") {
dir, _ := filepath.Split(viper.ConfigFileUsed())
if dir != "" {
path = dir + "/" + path
}
}
return path
}

func getHeadscaleApp() (*headscale.Headscale, error) {
derpMap, err := loadDerpMap(viper.GetString("derp_map_path"))
derpMap, err := loadDerpMap(absPath(viper.GetString("derp_map_path")))
if err != nil {
log.Printf("Could not load DERP servers map file: %s", err)
}

cfg := headscale.Config{
ServerURL: viper.GetString("server_url"),
Addr: viper.GetString("listen_addr"),
PrivateKeyPath: viper.GetString("private_key_path"),
PrivateKeyPath: absPath(viper.GetString("private_key_path")),
DerpMap: derpMap,

DBhost: viper.GetString("db_host"),
Expand Down
4 changes: 2 additions & 2 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"server_url": "http://192.168.1.12:8000",
"listen_addr": "0.0.0.0:8000",
"private_key_path": "private.key",
"derp_map_path": "./derp.yaml",
"derp_map_path": "derp.yaml",
"db_host": "localhost",
"db_port": 5432,
"db_name": "headscale",
"db_user": "foo",
"db_pass": "bar"
}
}