Beispiel #1
0
func main() {
	flag.Usage = usage

	help := flag.Bool("help", false, "show this message")
	version := flag.Bool("version", false, "show version")
	resume := flag.String("resume", "", "resume path")

	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(0)
	}

	if *version {
		fmt.Fprintf(os.Stderr, "%s version %s, Copyright (c) 2013 Uwe Hoffmann. All rights reserved.\n", os.Args[0], versionStr)
		os.Exit(0)
	}

	config := new(Config)
	err := gcfg.ReadFileInto(config, "depot.ini")
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading depot.ini failed: %v\n", err)
		os.Exit(1)
	}

	for i := 0; i < len(config.Depot.MaxSize); i++ {
		config.Depot.MaxSize[i] *= int64(archive.GB)
	}

	depot, err := archive.NewDepot(config.Depot.Root, config.Depot.MaxSize, new(db.NoOpDB), 8)
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating depot failed: %v\n", err)
		os.Exit(1)
	}

	resumeLoggerFile, err := os.Create("archive-resume.log")
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating archive-resume.log failed: %v\n", err)
		os.Exit(1)
	}
	defer resumeLoggerFile.Close()

	archiveLoggerFile, err := os.Create("archive-work.log")
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating archive-work.log failed: %v\n", err)
		os.Exit(1)
	}
	defer archiveLoggerFile.Close()

	err = depot.Archive(flag.Args(), *resume, log.New(resumeLoggerFile, "", 0), log.New(archiveLoggerFile, "", 0))

	if err != nil {
		fmt.Fprintf(os.Stderr, "archiving failed: %v\n", err)
		os.Exit(1)
	}
}
Beispiel #2
0
func main() {
	config := new(Config)

	err := gcfg.ReadFileInto(config, "romba.ini")
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}

	for i := 0; i < len(config.Depot.MaxSize); i++ {
		config.Depot.MaxSize[i] *= int64(archive.GB)
	}

	runtime.GOMAXPROCS(config.General.Workers)

	flag.Set("log_dir", config.General.LogDir)
	flag.Set("alsologtostderr", "true")

	romDB, err := db.New(config.Index.Db)
	if err != nil {
		fmt.Fprintf(os.Stderr, "opening db failed: %v\n", err)
		os.Exit(1)
	}

	depot, err := archive.NewDepot(config.Depot.Root, config.Depot.MaxSize, romDB)
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating depot failed: %v\n", err)
		os.Exit(1)
	}

	go signalCatcher(romDB)

	rs := service.NewRombaService(romDB, depot, config.Index.Dats, config.General.Workers, config.General.LogDir)

	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCustomCodec(&rpc.CompressionSelector{}), "application/json")
	s.RegisterService(rs, "")
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("./web"))))
	http.Handle("/jsonrpc/", s)
	http.Handle("/progress", websocket.Handler(rs.SendProgress))

	fmt.Printf("starting romba server at localhost:%d/romba.html\n", config.Server.Port)

	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Server.Port), nil))
}
Beispiel #3
0
func archiveRoms(cmd *commander.Command, args []string) {
	if len(args) == 0 {
		return
	}

	logPath := filepath.Join(config.General.LogDir, fmt.Sprintf("archive-%s.log", time.Now().Format("2006-01-02-15_04_05")))

	logfile, err := os.Create(logPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create log file %s: %v\n", logPath, err)
		os.Exit(1)
	}
	defer logfile.Close()

	buflog := bufio.NewWriter(logfile)
	defer buflog.Flush()

	depot, err := archive.NewDepot(config.Depot.Root, config.Depot.MaxSize, romDB, 8)
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating depot failed: %v\n", err)
		os.Exit(1)
	}

	resumeLogPath := filepath.Join(config.General.LogDir, fmt.Sprintf("archive-resume-%s.log", time.Now().Format("2006-01-02-15_04_05")))
	resumeLogFile, err := os.Create(resumeLogPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create log file %s: %v\n", resumeLogPath, err)
		os.Exit(1)
	}
	defer resumeLogFile.Close()

	bufresumelog := bufio.NewWriter(resumeLogFile)
	defer bufresumelog.Flush()

	resume := cmd.Flag.Lookup("resume").Value.Get().(string)

	err = depot.Archive(args, "", log.New(bufresumelog, resume, 0), log.New(buflog, "", 0))

	if err != nil {
		fmt.Fprintf(os.Stderr, "archiving failed: %v\n", err)
		os.Exit(1)
	}
}
Beispiel #4
0
func main() {
	cfg := new(config.Config)

	iniPath, err := findINI()
	if err != nil {
		fmt.Fprintf(os.Stderr, "finding romba ini failed: %v\n", err)
		os.Exit(1)
	}

	err = gcfg.ReadFileInto(cfg, iniPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini from %s failed: %v\n", iniPath, err)
		os.Exit(1)
	}

	for i := 0; i < len(cfg.Depot.MaxSize); i++ {
		cfg.Depot.MaxSize[i] *= int64(archive.GB)
	}

	cfg.General.LogDir, err = filepath.Abs(cfg.General.LogDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.General.TmpDir, err = filepath.Abs(cfg.General.TmpDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	for i, pv := range cfg.Depot.Root {
		cfg.Depot.Root[i], err = filepath.Abs(pv)
		if err != nil {
			fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
			os.Exit(1)
		}
	}
	cfg.Index.Dats, err = filepath.Abs(cfg.Index.Dats)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.Index.Db, err = filepath.Abs(cfg.Index.Db)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.General.WebDir, err = filepath.Abs(cfg.General.WebDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.General.BadDir, err = filepath.Abs(cfg.General.BadDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}

	config.GlobalConfig = cfg

	runtime.GOMAXPROCS(cfg.General.Cores)

	flag.Set("log_dir", cfg.General.LogDir)
	flag.Set("alsologtostderr", "true")
	flag.Set("v", strconv.Itoa(cfg.General.Verbosity))

	flag.Parse()

	romDB, err := db.New(cfg.Index.Db)
	if err != nil {
		fmt.Fprintf(os.Stderr, "opening db failed: %v\n", err)
		os.Exit(1)
	}

	depot, err := archive.NewDepot(cfg.Depot.Root, cfg.Depot.MaxSize, romDB)
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating depot failed: %v\n", err)
		os.Exit(1)
	}

	rs := service.NewRombaService(romDB, depot, cfg)

	go signalCatcher(rs)

	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCustomCodec(&rpc.CompressionSelector{}), "application/json")
	s.RegisterService(rs, "")
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(cfg.General.WebDir))))
	http.Handle("/jsonrpc/", s)
	http.Handle("/progress", websocket.Handler(rs.SendProgress))

	fmt.Printf("starting romba server version %s at localhost:%d/romba.html\n", service.Version, cfg.Server.Port)

	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Server.Port), nil))
}