Skip to content

Commit

Permalink
expose kamailio rpc host as flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulexus committed Sep 2, 2018
1 parent 6f33738 commit d381a39
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

var outputFilename string
var rpcPort string
var rpcHost string
var kubeCfg string

var maxShortDeaths = 10
Expand All @@ -32,6 +33,7 @@ var minRuntime = time.Minute
func init() {
flag.Var(&setDefinitions, "set", "Dispatcher sets of the form [namespace:]name=index[:port], where index is a number and port is the port number on which SIP is to be signaled to the dispatchers. May be passed multiple times for multiple sets.")
flag.StringVar(&outputFilename, "o", "/data/kamailio/dispatcher.list", "Output file for dispatcher list")
flag.StringVar(&rpcHost, "h", "128.0.0.1", "Host for kamailio's RPC service")
flag.StringVar(&rpcPort, "p", "9998", "Port for kamailio's RPC service")
flag.StringVar(&kubeCfg, "kubecfg", "", "Location of kubecfg file (if not running inside k8s)")
}
Expand Down Expand Up @@ -135,6 +137,7 @@ func (s *SetDefinition) Set(raw string) (err error) {
type dispatcherSets struct {
kc *k8s.Client
outputFilename string
rpcHost string
rpcPort string

sets map[int]sets.DispatcherSet
Expand Down Expand Up @@ -205,6 +208,10 @@ func (s *dispatcherSets) maintain(ctx context.Context) error {

for ctx.Err() == nil {
err := <-changes
if err == io.EOF {
log.Println("kubernetes API connection terminated:", err)
return nil
}
if err != nil {
return errors.Wrap(err, "error maintaining sets")
}
Expand All @@ -223,7 +230,7 @@ func (s *dispatcherSets) maintain(ctx context.Context) error {

// notify signals to kamailio to reload its dispatcher list
func (s *dispatcherSets) notify() error {
return kamailio.InvokeMethod("dispatcher.reload", "127.0.0.1", s.rpcPort)
return kamailio.InvokeMethod("dispatcher.reload", s.rpcHost, s.rpcPort)
}

func main() {
Expand Down Expand Up @@ -261,6 +268,7 @@ func run() error {
var s = &dispatcherSets{
kc: kc,
outputFilename: outputFilename,
rpcHost: rpcHost,
rpcPort: rpcPort,
}

Expand All @@ -280,9 +288,6 @@ func run() error {
}

if err = s.maintain(ctx); err != nil {
if err == io.EOF {
return nil
}
return errors.Wrap(err, "failed to maintain dispatcher sets")
}

Expand Down

0 comments on commit d381a39

Please sign in to comment.