Esempio n. 1
0
func main() {
	port := flag.Int("port", 1230, "Where to listen for work requests.")
	webPassword := flag.String("web-password", "killkillkill", "password for authorizing worker kills.")
	secretFile := flag.String("secret", "secret.txt", "file containing password or SSH identity.")
	flag.Parse()
	log.SetPrefix("C")

	secret, err := ioutil.ReadFile(*secretFile)
	if err != nil {
		log.Fatal("ReadFile", err)
	}

	opts := termite.CoordinatorOptions{
		Secret:      secret,
		WebPassword: *webPassword,
	}
	c := termite.NewCoordinator(&opts)
	c.Mux.HandleFunc("/bin/worker", serveBin("worker"))
	c.Mux.HandleFunc("/bin/shell-wrapper", serveBin("shell-wrapper"))

	log.Println(termite.Version())
	go c.PeriodicCheck()
	c.ServeHTTP(*port)
}
Esempio n. 2
0
func main() {
	version := flag.Bool("version", false, "print version and exit.")
	mkbox := flag.String("mkbox_path", "termite-mkbox", "path to the termite-mkbox binary.")
	cachedir := flag.String("cachedir", "/var/tmp/_termite_cache_"+os.Getenv("USER"), "termite worker content cache")
	tmpdir := flag.String("tmpdir", "/var/tmp",
		"where to create FUSE mounts; should be on same partition as cachedir.")
	secretFile := flag.String("secret", "secret.txt", "file containing password or SSH key.")
	port := flag.Int("port", 1232, "Start of port to try.")
	portRetry := flag.Int("port-retry", 10, "How many other ports to try.")
	coordinator := flag.String("coordinator", "", "Where to register the worker.")
	jobs := flag.Int("jobs", 1, "Max number of jobs to run.")
	reapcount := flag.Int("reap-count", 1, "Number of jobs per filesystem.")
	userFlag := flag.String("user", "nobody", "Run as this user.")
	logfile := flag.String("logfile", "", "Output log file to use.")
	stderrFile := flag.String("stderr", "", "File to write stderr output to.")
	paranoia := flag.Bool("paranoia", false, "Check attribute cache.")
	cpus := flag.Int("cpus", 1, "Number of CPUs to use.")
	heap := flag.Int("heap-size", 0, "Maximum heap size in MB.")
	flag.Parse()

	if *version {
		log.Println(termite.Version())
		os.Exit(0)
	}

	secret, err := ioutil.ReadFile(*secretFile)
	if err != nil {
		log.Fatal("ReadFile", err)
	}

	if *logfile != "" {
		f := OpenUniqueLog(*logfile)
		log.Println("Log output to", *logfile)
		log.SetOutput(f)
	} else {
		log.SetPrefix("W")
	}

	if *stderrFile != "" {
		f := OpenUniqueLog(*stderrFile)
		err = syscall.Close(2)
		if err != nil {
			log.Fatalf("close stderr: %v", err)
		}
		_, err = syscall.Dup(int(f.Fd()))
		if err != nil {
			log.Fatalf("dup: %v", err)
		}
		f.Close()
	}

	if _, err := os.Lstat(*mkbox); err != nil {
		if path, err := exec.LookPath(*mkbox); err == nil {
			*mkbox = path
		} else {
			log.Fatalf("could not find %q", *mkbox)
		}
	}

	opts := termite.WorkerOptions{
		Mkbox:       *mkbox,
		Secret:      secret,
		TempDir:     *tmpdir,
		Jobs:        *jobs,
		Paranoia:    *paranoia,
		ReapCount:   *reapcount,
		LogFileName: *logfile,
		StoreOptions: cba.StoreOptions{
			Dir: *cachedir,
		},
		HeapLimit:   uint64(*heap) * (1 << 20),
		Coordinator: *coordinator,
		Port:        *port,
		PortRetry:   *portRetry,
	}
	if os.Geteuid() == 0 {
		nobody, err := user.Lookup(*userFlag)
		if err != nil {
			log.Fatalf("can't lookup %q: %v", *userFlag, err)
		}
		uid, err := strconv.ParseInt(nobody.Uid, 10, 64)
		gid, err := strconv.ParseInt(nobody.Gid, 10, 64)
		opts.User = &termite.User{
			Uid: int(uid),
			Gid: int(gid),
		}
	}

	daemon := termite.NewWorker(&opts)
	if *cpus > 0 {
		runtime.GOMAXPROCS(*cpus)
	}
	log.Printf("%s on %d CPUs", termite.Version(), runtime.GOMAXPROCS(0))
	go handleStop(daemon)
	daemon.RunWorkerServer()
}
Esempio n. 3
0
func main() {
	home := os.Getenv("HOME")
	cachedir := flag.String("cachedir", filepath.Join(home, ".cache", "termite-master"), "content cache")
	coordinator := flag.String("coordinator", "localhost:1230", "address of coordinator. Overrides -workers")
	exclude := flag.String("exclude", "usr/lib/locale/locale-archive,sys,proc,dev,selinux,cgroup", "prefixes to not export.")
	fetchAll := flag.Bool("fetch-all", true, "Fetch all files on startup.")
	houseHoldPeriod := flag.Float64("time.household", 60.0, "how often to do house hold tasks.")
	jobs := flag.Int("jobs", 1, "number of jobs to run")
	keepAlive := flag.Float64("time.keepalive", 60.0, "for how long to keep workers reserved.")
	logfile := flag.String("logfile", "", "where to send log output.")
	memcache := flag.Int("filecache", 256, "number of <128k files to cache in memory")
	paranoia := flag.Bool("paranoia", false, "Check attribute cache.")
	port := flag.Int("port", 1231, "http status port")
	retry := flag.Int("retry", 3, "how often to retry faulty jobs")
	secretFile := flag.String("secret", "secret.txt", "file containing password.")
	socket := flag.String("socket", ".termite-socket", "socket to listen for commands")
	srcRoot := flag.String("sourcedir", "", "root of corresponding source directory")
	xattr := flag.Bool("xattr", true, "cache hashes in filesystem attribute.")

	flag.Parse()

	if *logfile != "" {
		f, err := os.OpenFile(*logfile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
		if err != nil {
			log.Fatal("Could not open log file.", err)
		}
		log.Println("Log output to", *logfile)
		log.SetOutput(f)
	} else {
		log.SetPrefix("M")
	}

	secret, err := ioutil.ReadFile(*secretFile)
	if err != nil {
		log.Fatal("ReadFile", err)
	}

	excludeList := strings.Split(*exclude, ",")
	root, sock := absSocket(*socket)

	opts := termite.MasterOptions{
		Secret:       secret,
		MaxJobs:      *jobs,
		Excludes:     excludeList,
		Coordinator:  *coordinator,
		SourceRoot:   *srcRoot,
		WritableRoot: root,
		Paranoia:     *paranoia,
		Period:       time.Duration(*houseHoldPeriod * float64(time.Second)),
		KeepAlive:    time.Duration(*keepAlive * float64(time.Second)),
		FetchAll:     *fetchAll,
		StoreOptions: cba.StoreOptions{
			Dir:      *cachedir,
			MemCount: *memcache,
		},
		RetryCount: *retry,
		XAttrCache: *xattr,
		LogFile:    *logfile,
		Socket:     sock,
	}
	master := termite.NewMaster(&opts)

	log.Println(termite.Version())

	go master.ServeHTTP(*port)
	master.Start()
}