예제 #1
0
파일: service.go 프로젝트: taik0/rexray
func Status() {
	if !util.FileExists(util.PidFile()) {
		fmt.Println("REX-Ray is stopped")
		return
	}
	pid, _ := util.ReadPidFile()
	fmt.Printf("REX-Ray is running at pid %d\n", pid)
}
예제 #2
0
파일: service.go 프로젝트: taik0/rexray
func Restart() {
	checkOpPerms("restarted")

	if util.FileExists(util.PidFile()) {
		Stop()
	}

	Start()
}
예제 #3
0
파일: service.go 프로젝트: taik0/rexray
func Stop() {
	checkOpPerms("stopped")

	if !util.FileExists(util.PidFile()) {
		fmt.Println("REX-Ray is already stopped")
		panic(1)
	}

	fmt.Print("Shutting down REX-Ray...")

	pid, pidErr := util.ReadPidFile()
	failOnError(pidErr)

	proc, procErr := os.FindProcess(pid)
	failOnError(procErr)

	killErr := proc.Signal(syscall.SIGHUP)
	failOnError(killErr)

	fmt.Println("SUCCESS!")
}
예제 #4
0
파일: service.go 프로젝트: taik0/rexray
func Start() {
	checkOpPerms("started")

	log.WithField("os.Args", os.Args).Debug("invoking service start")

	pidFile := util.PidFile()

	if util.FileExists(pidFile) {
		pid, pidErr := util.ReadPidFile()
		if pidErr != nil {
			fmt.Printf("Error reading REX-Ray PID file at %s\n", pidFile)
		} else {
			fmt.Printf("REX-Ray already running at PID %d\n", pid)
		}
		panic(1)
	}

	if fg || client != "" {
		startDaemon()
	} else {
		tryToStartDaemon()
	}
}
예제 #5
0
파일: service.go 프로젝트: taik0/rexray
func startDaemon() {

	fmt.Printf("%s\n", RexRayLogoAscii)

	var success []byte
	var failure []byte
	var conn net.Conn

	if !fg {

		success = []byte{0}
		failure = []byte{1}

		var dialErr error

		log.Printf("Dialing %s\n", client)
		conn, dialErr = net.Dial("unix", client)
		if dialErr != nil {
			panic(dialErr)
		}
	}

	writePidErr := util.WritePidFile(-1)
	if writePidErr != nil {
		if conn != nil {
			conn.Write(failure)
		}
		panic(writePidErr)
	}

	defer func() {
		r := recover()
		os.Remove(util.PidFile())
		if r != nil {
			panic(r)
		}
	}()

	log.Printf("Created pid file, pid=%d\n", os.Getpid())

	init := make(chan error)
	sigc := make(chan os.Signal, 1)
	stop := make(chan os.Signal)

	signal.Notify(sigc,
		syscall.SIGKILL,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)

	go func() {
		rrdaemon.Start(c.Host, init, stop)
	}()

	initErrors := make([]error, 0)

	for initErr := range init {
		initErrors = append(initErrors, initErr)
		log.Println(initErr)
	}

	if conn != nil {
		if len(initErrors) == 0 {
			conn.Write(success)
		} else {
			conn.Write(failure)
		}

		conn.Close()
	}

	if len(initErrors) > 0 {
		return
	}

	sigv := <-sigc
	log.Printf("Received shutdown signal %v\n", sigv)
	stop <- sigv
}