Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Launch and monitor ulogd daemon
Browse files Browse the repository at this point in the history
Exec the ulogd daemon on weave-npc startup, copying any log output to
our own logs. Exit if the ulogd process terminates for any reason.
  • Loading branch information
awh committed Oct 19, 2016
1 parent c80e54a commit d1710ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/weave-npc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/kubernetes/pkg/util/wait"

weavenpc "github.com/weaveworks/weave-npc/pkg/controller"
"github.com/weaveworks/weave-npc/pkg/ulogd"
"github.com/weaveworks/weave-npc/pkg/util/ipset"
)

Expand Down Expand Up @@ -101,6 +102,10 @@ func resetIPSets(ips ipset.Interface) error {
func main() {
log.Infof("Starting Weaveworks NPC %s", version)

if err := ulogd.Start(); err != nil {
log.Fatalf("Failed to start ulogd: %v", err)
}

client, err := unversioned.NewInCluster()
if err != nil {
log.Fatal(err)
Expand Down
29 changes: 29 additions & 0 deletions pkg/ulogd/ulogd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ulogd

import (
log "github.com/Sirupsen/logrus"
"io"
"os"
"os/exec"
)

func waitForExit(cmd *exec.Cmd) {
if err := cmd.Wait(); err != nil {
log.Fatalf("ulogd terminated: %v", err)
}
log.Fatal("ulogd terminated normally")
}

func Start() error {
cmd := exec.Command("/usr/sbin/ulogd", "-v")
stdout, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
go io.Copy(os.Stdout, stdout)
go waitForExit(cmd)
return nil
}

0 comments on commit d1710ad

Please sign in to comment.