func start(isWorker bool, z *config.ZookeeperConfig, i *config.InstallConfig, s *config.SparkConfig) { // If this is a worker, create a lock file in its working directory if isWorker { if _, err := lockfile.Create("lock"); err != nil { fmt.Fprintf(os.Stderr, "Worker cannot obtain lock (%s)\n", err) os.Exit(1) } } // Connect to Zookeeper for anchor file system aconn := zanchorfs.Dial(z.Workers) anchorfs.Bind(zanchorfs.New(aconn, z.AnchorDir())) // Connect to Zookeeper for durable file system dconn := zdurablefs.Dial(z.Workers) durablefs.Bind(zdurablefs.New(dconn, z.DurableDir())) // Connect to Zookeeper for issue file system iconn := zissuefs.Dial(z.Workers) issuefs.Bind(zissuefs.New(iconn, z.IssueDir())) // Initialize the networking module worker.Bind(workerBackend.New(i.LibPath, path.Join(i.BinDir(), i.Worker), i.JailDir())) // Initialize transport module t := transport.New(s.ID, s.BindAddr, s.Host) // Initialize language runtime circuit.Bind(lang.New(t)) // Create anchors for _, a := range s.Anchor { a = strings.TrimSpace(a) if err := anchorfs.CreateFile(a, t.Addr()); err != nil { fmt.Fprintf(os.Stderr, "Problem creating anchor '%s' (%s)\n", a, err) os.Exit(1) } } if isWorker { // A worker sends back its PID and runtime port to its invoker (the daemonizer) backpipe := os.NewFile(3, "backpipe") if _, err := backpipe.WriteString(strconv.Itoa(os.Getpid()) + "\n"); err != nil { panic(err) } if _, err := backpipe.WriteString(strconv.Itoa(t.Port()) + "\n"); err != nil { panic(err) } if err := backpipe.Close(); err != nil { panic(err) } // Hang forever is done in the auto-generated, by 4build, worker main method } }
func main() { if len(os.Args) != 2 { println("Usage:", os.Args[0], "JailDir") os.Exit(1) } jailDir := os.Args[1] jail, err := os.Open(jailDir) if err != nil { fmt.Fprintf(os.Stderr, "Cannot open jail directory (%s)\n", err) os.Exit(1) } defer jail.Close() fifi, err := jail.Readdir(0) if err != nil { fmt.Fprintf(os.Stderr, "Cannot read jail directory (%s)\n", err) os.Exit(1) } for _, fi := range fifi { if !fi.IsDir() { continue } if _, err := circuit.ParseWorkerID(fi.Name()); err != nil { continue } workerJail := path.Join(jailDir, fi.Name()) println("Clearing", workerJail) l, err := lockfile.Create(path.Join(workerJail, "lock")) if err != nil { // This worker is alive; still holding lock; move on println(err.Error()) continue } l.Release() if err := os.RemoveAll(workerJail); err != nil { fmt.Fprintf(os.Stderr, "Cannot remove worker jail %s (%s)\n", workerJail, err) os.Exit(1) } } }