From 556fd85b27ae3f0c8771f41970abf252f473301c Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Fri, 14 Nov 2014 09:40:46 +0000 Subject: [PATCH] tweaks --- main.go | 9 +++++++-- server/server.go | 14 ++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index bf62953..cb01696 100644 --- a/main.go +++ b/main.go @@ -1,20 +1,23 @@ package main import "github.com/hlandau/degoutils/config" - //import "github.com/hlandau/degoutils/log" //import "github.com/hlandau/degoutils/daemon" import "github.com/hlandau/degoutils/service" import "github.com/hlandau/ncdns/server" +import "path/filepath" func main() { cfg := server.ServerConfig{} config := config.Configurator{ ProgramName: "ncdns", - ConfigFilePaths: []string{"etc/ncdns.conf", "/etc/ncdns/ncdns.conf"}, + ConfigFilePaths: []string{"$BIN/../etc/ncdns.conf", "/etc/ncdns/ncdns.conf"}, } config.ParseFatal(&cfg) + // We use the configPath to resolve paths relative to the config file. + cfg.ConfigDir = filepath.Dir(config.ConfigFilePath()) + service.Main(&service.Info{ Name: "ncdns", Description: "Namecoin to DNS Daemon", @@ -30,6 +33,8 @@ func main() { } smgr.SetStarted() + smgr.SetStatus("ncdns: running ok") + <-smgr.StopChan() return nil diff --git a/server/server.go b/server/server.go index 5dfdc41..51be540 100644 --- a/server/server.go +++ b/server/server.go @@ -8,6 +8,7 @@ import "os" import "fmt" import "os/signal" import "syscall" +import "path/filepath" const version = "1.0" @@ -31,13 +32,15 @@ type ServerConfig struct { NamecoinRPCUsername string `default:"" usage:"Namecoin RPC username"` NamecoinRPCPassword string `default:"" usage:"Namecoin RPC password"` NamecoinRPCAddress string `default:"localhost:8336" usage:"Namecoin RPC server address"` - CacheMaxEntries int `default:"1000" usage:"Maximum name cache entries"` + CacheMaxEntries int `default:"100" usage:"Maximum name cache entries"` SelfName string `default:"" usage:"Canonical name for this nameserver (default: autogenerated psuedo-hostname resolving to SelfIP; SelfIP is not used if this is set)"` SelfIP string `default:"127.127.127.127" usage:"The canonical IP address for this service"` - //Daemonize bool `default:"false" usage:"Daemonize (doesn't fork)"` - //UID int `default:"0" usage:"UID to drop privileges to if run as root"` - //GID int `default:"0" usage:"GID to drop privileges to if run as root"` + ConfigDir string // path to interpret filenames relative to +} + +func (cfg *ServerConfig) cpath(s string) string { + return filepath.Join(cfg.ConfigDir, s) } func NewServer(cfg *ServerConfig) (s *Server, err error) { @@ -98,6 +101,9 @@ func NewServer(cfg *ServerConfig) (s *Server, err error) { } func (s *Server) loadKey(fn, privateFn string) (k *dns.DNSKEY, privatek dns.PrivateKey, err error) { + fn = s.cfg.cpath(fn) + privateFn = s.cfg.cpath(privateFn) + f, err := os.Open(fn) if err != nil { return