Esempio n. 1
0
func (this *Sheep) Restart() (err error) {
	if err = this.Stop(); err == nil {
		err = this.Start()
	} else {
		log.Log("stop err:", err.Error())
	}
	return err
}
Esempio n. 2
0
func (this *electServer) InitRaftCluster(leader string) (err error) {
	if leader != "" {
		if !this.raftServer.IsLogEmpty() {
			log.Log("cannot join with exist log")
			return
		}
		if err = this.JoinLeader(leader); err != nil {
			return
		}
	} else if this.raftServer.IsLogEmpty() {
		if err = this.JoinSelf(); err != nil {
			return
		}
	} else {
		log.Notice("recovered from log")
	}
	return
}
Esempio n. 3
0
func (this *Sheep) Stop() (err error) {
	if this.cmd.Process == nil {
		return errors.New(fmt.Sprintf("%s not started.", this.Name))
	}

	if this.cmd.ProcessState == nil {
		log.Log("process state unvailable")
	} else if this.cmd.ProcessState.Exited() {
		return errors.New(fmt.Sprintf("%s has stoped.", this.Name))
	}

	this.Status = constant.STATUS_STOPING
	log.Logf("signal:%d", this.StopSignal)
	if err = this.cmd.Process.Signal(syscall.Signal(this.StopSignal)); err == nil {
		this.Status = constant.STATUS_STOPPED
	} else {
		log.Error("stop faild:", err.Error())
	}
	return err
}