Permalink
Browse files

Never panic in the master process. Always shutdown gracefully

  • Loading branch information...
1 parent 6ad4459 commit e9b918e4ce8d329ec5cc21180d6e47b06b0da398 @burke committed Sep 18, 2012
Showing with 15 additions and 8 deletions.
  1. +1 −1 go/zeusmaster/clienthandler.go
  2. +6 −0 go/zeusmaster/errors.go
  3. +5 −4 go/zeusmaster/filemonitor.go
  4. +3 −3 go/zeusmaster/slavemonitor.go
View
2 go/zeusmaster/clienthandler.go
@@ -17,7 +17,7 @@ func StartClientHandler(tree *ProcessTree, quit chan bool) {
path, _ := filepath.Abs(zeusSockName)
addr, err := net.ResolveUnixAddr("unix", path)
if err != nil {
- panic("Can't open socket.")
+ Error("Can't open socket.")
}
listener, err := net.ListenUnix("unix", addr)
if err != nil {
View
6 go/zeusmaster/errors.go
@@ -6,6 +6,12 @@ import (
"os"
)
+func Error(msg string) {
+ if slog.Red(msg) {
+ ExitNow(1)
+ }
+}
+
func ErrorConfigCommandCouldntStart(output string) {
slog.Red("Failed to initialize application from {yellow}zeus.json{red}.")
if slog.Red("The json file is valid, but the {yellow}command{red} could not be started:") {
View
9 go/zeusmaster/filemonitor.go
@@ -51,20 +51,21 @@ func executablePath() string {
gemRoot := path.Dir(path.Dir(os.Args[0]))
return path.Join(gemRoot, "ext/inotify-wrapper/inotify-wrapper")
}
- panic("Unsupported OS")
+ Error("Unsupported OS")
+ return ""
}
func startWrapper() {
cmd := exec.Command(executablePath())
var err error
if watcherIn, err = cmd.StdinPipe(); err != nil {
- panic(err)
+ Error(err.Error())
}
if watcherOut, err = cmd.StdoutPipe(); err != nil {
- panic(err)
+ Error(err.Error())
}
if watcherErr, err = cmd.StderrPipe(); err != nil {
- panic(err)
+ Error(err.Error())
}
cmd.Start()
View
6 go/zeusmaster/slavemonitor.go
@@ -21,12 +21,12 @@ func StartSlaveMonitor(tree *ProcessTree, quit chan bool) {
localMasterFile, remoteMasterFile, err := unixsocket.Socketpair(syscall.SOCK_DGRAM)
if err != nil {
- panic(err)
+ Error("Couldn't create socketpair")
}
localMasterSocket, err := unixsocket.NewUsockFromFile(localMasterFile)
if err != nil {
- panic(err)
+ Error("Couldn't Open UNIXSocket")
}
// We just want this unix socket to be a channel so we can select on it...
@@ -149,7 +149,7 @@ func (mon *SlaveMonitor) slaveDidBeginRegistration(fd int) {
slaveNode := mon.tree.FindSlaveByName(identifier)
if slaveNode == nil {
- panic("slavemonitor.go:slaveDidBeginRegistration:Unknown identifier:" + identifier)
+ Error("slavemonitor.go:slaveDidBeginRegistration:Unknown identifier:" + identifier)
}
go slaveNode.Run(identifier, pid, slaveUsock)

0 comments on commit e9b918e

Please sign in to comment.