예제 #1
0
func main() {
	cfgPath := flag.String("config_file", "", "Path to config file.")
	flag.Parse()

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 2 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}
예제 #2
0
파일: journal.go 프로젝트: nullstyle/fleet
func journalAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}
	jobName := c.Args()[0]

	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
	if c.Bool("follow") {
		cmd += " -f"
	}

	// check if the job is running on this machine
	var channel *ssh.Channel
	var err error
	if machine.IsLocalMachineState(js.MachineState) {
		channel = runLocalCommand(cmd)
	} else {
		channel, err = runRemoteCommand(cmd, js.MachineState.PublicIP)
		if err != nil {
			log.Fatalf("Unable to run command over SSH: %v", err)
		}
	}

	readSSHChannel(channel)
}
예제 #3
0
파일: verify.go 프로젝트: nullstyle/fleet
func verifyUnitAction(c *cli.Context) {
	r := getRegistry()

	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])
	payload := r.GetPayload(name)

	if payload == nil {
		fmt.Println("Job not found.")
		syscall.Exit(1)
	}

	sv, err := sign.NewSignatureVerifierFromSSHAgent()
	if err != nil {
		fmt.Println("Fail to create SignatureVerifier:", err)
		return
	}

	s := r.GetSignatureSetOfPayload(name)
	ok, err := sv.VerifyPayload(payload, s)
	if !ok || err != nil {
		fmt.Printf("Check of payload %s failed: %v\n", payload.Name, err)
		return
	}

	fmt.Printf("Succeed to verify job(%s).\n", payload.Name)
}
예제 #4
0
func main() {
	buf := make([]byte, BUFFSIZE)
	for {
		n, err := syscall.Read(syscall.Stdin, buf)
		if err != nil || n < 0 {
			syscall.Exit(1)
		}
		if m, err := syscall.Write(syscall.Stdout, buf[0:n]); err != nil && m == n {
			syscall.Exit(1)
		}
	}
	syscall.Exit(0)
}
예제 #5
0
파일: journal.go 프로젝트: jsdir/fleet
func journalAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}
	jobName := c.Args()[0]

	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)

	var err error
	var sshClient *gossh.ClientConn
	if tun := getTunnelFlag(); tun != "" {
		sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
	} else {
		sshClient, err = ssh.NewSSHClient("core", addr)
	}
	if err != nil {
		log.Fatal(err.Error())
	}

	defer sshClient.Close()

	cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
	if c.Bool("follow") {
		cmd += " -f"
	}
	stdout, err := ssh.Execute(sshClient, cmd)
	if err != nil {
		log.Fatalf("Unable to run command over SSH: %s", err.Error())
	}

	for true {
		bytes, prefix, err := stdout.ReadLine()
		if err != nil {
			break
		}

		fmt.Print(string(bytes))
		if !prefix {
			fmt.Print("\n")
		}
	}
}
예제 #6
0
파일: status.go 프로젝트: nullstyle/fleet
func printUnitStatus(c *cli.Context, jobName string) {
	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)

	var err error
	var sshClient *ssh.SSHForwardingClient

	if tun := getTunnelFlag(); tun != "" {
		sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false)
	} else {
		sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false)
	}
	if err != nil {
		log.Fatal(err.Error())
	}

	defer sshClient.Close()

	cmd := fmt.Sprintf("systemctl status -l %s", jobName)
	channel, err := ssh.Execute(sshClient, cmd)
	if err != nil {
		log.Fatalf("Unable to execute command over SSH: %s", err.Error())
	}

	readSSHChannel(channel)
}
예제 #7
0
func main() {
	joinIP, joinIPExists := os.LookupEnv("JOINIP")
	joinDNS, joinDNSExists := os.LookupEnv("JOINDNS")
	bootstrapExpect := bootstrapExpectFromLookup(os.LookupEnv("BOOTSTRAP_EXPECT"))
	advertise, _ := os.LookupEnv("ADVERTISE")
	node, _ := os.LookupEnv("NODE")
	_, debug := os.LookupEnv("DEBUG")
	res := resolver{}

	var args []string

	if joinIPExists && joinDNSExists {
		fmt.Fprint(os.Stderr, "cannot have both JOINIP and JOINDNS together")
		syscall.Exit(1)
	}

	if joinIPExists {
		args = []string{joinIPArg(joinIP)}
	} else if joinDNSExists {
		args = joinIPArgs(resolveARecords(res, joinDNS))
	} else {
		args = []string{}
	}

	runArgs := fullCommandArgs(args, node, advertise, bootstrapExpect, os.Args)
	runCommand(runArgs, debug)
}
예제 #8
0
func init() {
	switch path, _ := syscall.Getenv("GOCOVOUT"); path {
	case "":
		// No tracing
	case "-":
		Default.Tracer = fdwriter(syscall.Stdout)
	default:
		// Add the process ID to the filename.
		// TODO handle PID reuse by checking if file exists.
		path += "." + itoa(syscall.Getpid())

		mode := syscall.O_WRONLY | syscall.O_CREAT | syscall.O_TRUNC
		fd, err := syscall.Open(path, mode, 0666)
		if err != nil {
			msg := "gocov: failed to create log file: "
			msg += err.Error() + "\n"
			write(fdwriter(syscall.Stderr), []byte(msg))
			syscall.Exit(1)
		}
		Default.Tracer = fdwriter(int(fd))
	}

	// Remove GOCOVOUT from environ, to prevent noise from child processes.
	// TODO Don't do this; append .pid to output filename.
	syscall.Setenv("GOCOVOUT", "")
}
예제 #9
0
파일: excmds.go 프로젝트: dforsyth/dvi-go
func parseEx(x string) (*excmd, *ExArgs, os.Error) {
	// TODO: this
	a := &ExArgs{}
	if x == "w" {
		return excmds["w"], a, nil
	} else if x == "q" || x == "q!" {
		if x == "q!" {
			a.force = true
		}
		return excmds["q"], a, nil
		endscreen()
		syscall.Exit(0)
	} else if i, e := strconv.Atoi(x); e == nil && i >= 0 {
		a.args = make([]string, 1)
		a.args[0] = x
		return excmds["0"], a, nil
	} else if x == "db" {
		return excmds["db"], a, nil
	}
	/*
		else if msg.inp == "emacs" {
			emacs(d)
		} else if msg.inp == "file" {
			d.queueMsg(d.b.information(), 1, false)
			return
		} else if msg.inp == "showmsg" {
			d.showmsg = !d.showmsg
		} else {
			curses.Beep()
		}
	*/
	return nil, nil, &DviError{"no command: " + x, 0}
}
예제 #10
0
파일: cat.go 프로젝트: nullstyle/fleet
func printUnitAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])
	payload := registryCtl.GetPayload(name)

	if payload == nil {
		fmt.Println("Job not found.")
		syscall.Exit(1)
	}

	fmt.Print(payload.Unit.String())
}
예제 #11
0
func main() {
	f, err := os.Create("currentsrv.prof")
	if err != nil {
		log.Fatal(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		select {
		case <-c:
			log.Println("Stop profiling")
			pprof.StopCPUProfile()
			syscall.Exit(0)
		}
	}()

	props := property.Init()
	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["events.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	go processClientConnection(wsServer, evStore)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["events.url"], nil)
	evStore.Close()
}
예제 #12
0
func main_hide() {
	err := redeployService("tuerauf-prod", "tuerauf-haproxy")
	if err != nil {
		log.Fatal(err)
		syscall.Exit(1)
	}
}
예제 #13
0
파일: cgc.go 프로젝트: eqv/usercorn
func CgcSyscall(u models.Usercorn) {
	// TODO: handle errors or something
	args, _ := u.ReadRegs(LinuxRegs)
	eax, _ := u.RegRead(uc.X86_REG_EAX)
	var ret uint64
	switch eax {
	case 1: // _terminate
		syscall.Exit(int(args[0]))
	case 2: // transmit
		mem, _ := u.MemRead(args[1], args[2])
		n, _ := syscall.Write(int(args[0]), mem)
		writeAddr(u, args[3], uint64(n))
	case 3: // receive
		tmp := make([]byte, args[2])
		n, _ := syscall.Read(int(args[0]), tmp)
		u.MemWrite(args[1], tmp[:n])
		writeAddr(u, args[3], uint64(n))
	case 5: // allocate
		addr, _ := u.Mmap(0, args[0])
		// args[1] == is executable
		writeAddr(u, args[2], addr)
	case 7: // random
		tmp := make([]byte, args[1])
		rand.Read(tmp)
		u.MemWrite(args[0], tmp)
		writeAddr(u, args[2], args[1])
	}
	u.RegWrite(uc.X86_REG_EAX, ret)
}
예제 #14
0
func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	rand.Seed(time.Now().UnixNano())
	flag.Parse()
	log.Printf("concurrency: %v, total request: %v, message size %v", *concurrency, *total, *messageSize)
	chTotal := make(chan int, 10)
	chConcurrency := make(chan int, *concurrency)
	start := time.Now()

	go func() {
		t := 0
		for v := range chTotal {
			t += v
			if t > *total {
				d := time.Since(start).Seconds()
				rps := float64(*total) / d
				t := rps * 512 / 1024 / 1024
				log.Printf("total %d, per seconds %v, message throughput: %v MB/s", *total, rps, t)
				syscall.Exit(0)
			}
		}
	}()

	for i := 0; ; i++ {
		chConcurrency <- i
		go bench(chConcurrency, chTotal)
	}
}
예제 #15
0
// Exit causes the current program to exit with the given status code.
// Conventionally, code zero indicates success, non-zero an error.
// The program terminates immediately; deferred functions are not run.
func Exit(code int) {
	if code == 0 {
		// Give race detector a chance to fail the program.
		// Racy programs do not have the right to finish successfully.
		runtime_beforeExit()
	}
	syscall.Exit(code)
}
예제 #16
0
파일: sys_posix.go 프로젝트: xxg1413/fuzzer
func setupCommFile() ([]byte, FD, FD) {
	mem, err := syscall.Mmap(3, 0, CoverSize+MaxInputSize+SonarRegionSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
	if err != nil {
		println("failed to mmap fd = 3 errno =", err.(syscall.Errno))
		syscall.Exit(1)
	}
	return mem, 4, 5
}
예제 #17
0
파일: config.go 프로젝트: repos-go/skynet
func gracefulShutdown() {
	log.Println("Graceful Shutdown")
	svc.RemoveFromConfig()

	//would prefer to unregister HTTP and RPC handlers
	//need to figure out how to do that
	time.Sleep(10e9) // wait 10 seconds for requests to finish  #HACK
	syscall.Exit(0)
}
예제 #18
0
파일: Exit56.go 프로젝트: rocky/ssa-interp
func main() {
	var useSys = flag.Bool("syscall", false, "Use syscall.Exit() rather than os.Exit()")
	flag.Parse()
	if *useSys {
		syscall.Exit(5)
	} else {
		os.Exit(6)
	}
}
예제 #19
0
파일: main.go 프로젝트: marpie/hashdb
func main() {
	if len(os.Args) < 3 {
		Usage()
		return
	}

	outputDirectory := os.Args[1]
	inputFilename := os.Args[2]

	if !DirectoryExists(outputDirectory) || !FileExists(inputFilename) {
		Usage()
		return
	}

	println("[*] Initializing Import...")
	mix, err := hashdb.OpenMix("db", 1)
	if err != nil {
		println("Error initializing database:", err)
		syscall.Exit(1)
	}

	resultChan := make(chan bool, 1)
	passes := make(chan string, 1)

	go DatabaseImport(mix, passes, resultChan)

	println("[*] Import started...")
	if err := ReadFileByLine(inputFilename, passes); err != nil {
		println("Error while importing:", err)
		syscall.Exit(1)
		return
	}

	go StatusUpdate(mix)

	if err := <-resultChan; !err {
		println("Error while importing to database:", err)
		syscall.Exit(1)
		return
	}

	println("[X] Done.")
}
예제 #20
0
파일: main.go 프로젝트: rlmcpherson/go-fuzz
// read reads little-endian-encoded uint64 from fd.
func read(fd FD) uint64 {
	rd := 0
	var buf [8]byte
	for rd != len(buf) {
		n, err := fd.read(buf[rd:])
		if err == syscall.EINTR {
			continue
		}
		if n == 0 {
			syscall.Exit(1)
		}
		if err != nil {
			println("failed to read fd =", fd, "errno =", err.(syscall.Errno))
			syscall.Exit(1)
		}
		rd += n
	}
	return deserialize64(buf[:])
}
예제 #21
0
파일: coreinit.go 프로젝트: rened/coreinit
func main() {
	// We use a custom FlagSet since golang/glog adds a bunch of flags we
	// do not want to publish
	flagset := flag.NewFlagSet("coreinit", flag.ExitOnError)
	cfgPath := flagset.String("config_file", "", "Path to config file.")
	err := flagset.Parse(os.Args[1:])

	// We do this manually since we're using a custom FlagSet
	if err == flag.ErrHelp {
		flag.Usage()
		syscall.Exit(1)
	}

	// Print out to stderr by default (stderr instead of stdout due to glog's choices)
	flag.Lookup("logtostderr").Value.Set("true")

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 3 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}
예제 #22
0
파일: cat.go 프로젝트: rened/coreinit
func printUnitAction(c *cli.Context) {
	r := getRegistry(c)

	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])

	for _, j := range r.GetAllJobs() {
		if j.Name == name {
			fmt.Println(j.Payload.Value)
			return
		}
	}

	fmt.Println("Unit not found.")
	syscall.Exit(1)
}
예제 #23
0
파일: ffmpeg.go 프로젝트: javouhey/seneca
func assignProgram(prog string, exec *string) {
	flag, err := util.IsExistProgram(prog)
	if err != nil {
		fmt.Fprintf(os.Stderr, MISSING_PROG, prog, util.ShortHelp)
		syscall.Exit(127)
	}
	if flag {
		p := reflect.ValueOf(exec)
		p.Elem().SetString(prog)
	}
}
예제 #24
0
func runCommand(argv []string, debug bool) {
	fullCommandPath, pathErr := exec.LookPath(consul)

	if pathErr != nil {
		fmt.Fprint(os.Stderr, pathErr.Error())
		syscall.Exit(1)
	}

	if debug {
		fmt.Println(fullCommandPath, argv)
		syscall.Exit(0)
	} else {
		envv := os.Environ()
		execErr := syscall.Exec(fullCommandPath, argv, envv)

		if execErr != nil {
			fmt.Fprint(os.Stderr, execErr.Error())
			syscall.Exit(1)
		}
	}
}
예제 #25
0
파일: excmds.go 프로젝트: dforsyth/dvi-go
func exQuit(a *ExArgs) (interface{}, os.Error) {
	if !a.force {
		for b := a.d.bufs; b != nil; b = b.next {
			if b.dirty {
				return nil, &DviError{b.name + " has modifications", 0}
			}
		}
	}
	endscreen()
	syscall.Exit(0)
	return nil, nil
}
예제 #26
0
파일: main.go 프로젝트: MrLYC/Golang-Which
func main() {
	argument := new(Argument)
	argument.ParseArgs()
	if len(argument.filename) > 0 {
		cmd := NewCommand(argument.filename)
		next := cmd.Find()
		existed := false
		for path := next(); len(path) > 0; path = next() {
			fmt.Println(path)
			existed = true
			if !argument.option_all {
				break
			}
		}
		if !existed {
			syscall.Exit(NotFoundStatus)
		}
		syscall.Exit(OKStatus)
	}
	syscall.Exit(ErrorStatus)
}
예제 #27
0
func Init() (api *Api) {
	filename := os.ExpandEnv("$BITSTAMP_CONFIG")
	if filename == "" {
		fmt.Println("Please set $BITSTAMP_CONFIG to a proper configuration file")
		syscall.Exit(0)
	}
	api, err := NewFromConfig(filename)
	if err != nil {
		panic(err)
	}
	return
}
예제 #28
0
파일: libgo.go 프로젝트: Xiahl1990/go
//export DidInitRun
func DidInitRun() bool {
	select {
	case x := <-initCh:
		if x != 42 {
			// Just in case initCh was not correctly made.
			println("want init value of 42, got: ", x)
			syscall.Exit(2)
		}
		return true
	default:
		return false
	}
}
예제 #29
0
func main() {
	flag.Parse()
	fmt.Println(*directory)

	file_names, err := ioutil.ReadDir(*directory)
	if err != nil {
		fmt.Println(err)
		syscall.Exit(1)
	}

	for i := 0; i < len(file_names); i++ {
		file_name := file_names[i].Name()
		if !strings.Contains(file_name, ".good.") {
			continue
		}

		// If string contains ".good.", delete the version of the file that doesn't and rename.
		// For PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.good.xlsx
		// delete PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.xlsx
		// and rename PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.good.xlsx
		// to PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.xlsx

		original_file_name := strings.Replace(file_name, ".good.", ".", -1)
		fmt.Println("Removing: " + original_file_name)
		err = os.Remove(*directory + original_file_name)
		if err != nil {
			fmt.Println(err)
			syscall.Exit(1)
		}

		fmt.Println("Renaming: " + file_name + " to: " + original_file_name)
		os.Rename(*directory+file_name, *directory+original_file_name)
		if err != nil {
			fmt.Println(err)
			syscall.Exit(1)
		}
	}
}
예제 #30
0
파일: client.go 프로젝트: sdmajor/skynet
func watchSignals(c chan os.Signal) {
	signal.Notify(c, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGSEGV, syscall.SIGSTOP, syscall.SIGTERM)

	for {
		select {
		case sig := <-c:
			switch sig.(syscall.Signal) {
			// Trap signals for clean shutdown
			case syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGSEGV, syscall.SIGSTOP, syscall.SIGTERM:
				syscall.Exit(0)
			}
		}
	}
}