本文整理匯總了Golang中github.com/emccode/rexray/util.ReadPidFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadPidFile函數的具體用法?Golang ReadPidFile怎麽用?Golang ReadPidFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ReadPidFile函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: status
func status() {
if !util.FileExists(util.PidFilePath()) {
fmt.Println("REX-Ray is stopped")
return
}
pid, _ := util.ReadPidFile()
fmt.Printf("REX-Ray is running at pid %d\n", pid)
}
示例2: tryToStartDaemon
func tryToStartDaemon() {
_, _, thisAbsPath := util.GetThisPathParts()
fmt.Print("Starting REX-Ray...")
signal := make(chan byte)
client := fmt.Sprintf("%s/%s.sock", os.TempDir(), util.RandomString(32))
log.WithField("client", client).Debug("trying to start service")
l, lErr := net.Listen("unix", client)
failOnError(lErr)
go func() {
conn, acceptErr := l.Accept()
if acceptErr != nil {
fmt.Printf("FAILED!\n %v\n", acceptErr)
panic(acceptErr)
}
defer conn.Close()
defer os.Remove(client)
log.Debug("accepted connection")
buff := make([]byte, 1)
conn.Read(buff)
log.Debug("received data")
signal <- buff[0]
}()
cmdArgs := []string{
"start",
fmt.Sprintf("--client=%s", client),
fmt.Sprintf("--logLevel=%v", r.Config.LogLevel)}
if r.Config.Host != "" {
cmdArgs = append(cmdArgs, fmt.Sprintf("--host=%s", r.Config.Host))
}
cmd := exec.Command(thisAbsPath, cmdArgs...)
cmd.Stderr = os.Stderr
cmdErr := cmd.Start()
failOnError(cmdErr)
sigVal := <-signal
if sigVal != 0 {
fmt.Println("FAILED!")
panic(1)
}
pid, _ := util.ReadPidFile()
fmt.Printf("SUCESS!\n\n")
fmt.Printf(" The REX-Ray daemon is now running at PID %d. To\n", pid)
fmt.Printf(" shutdown the daemon execute the following command:\n\n")
fmt.Printf(" sudo %s stop\n\n", thisAbsPath)
}
示例3: stop
func stop() {
checkOpPerms("stopped")
if !util.FileExists(util.PidFilePath()) {
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: start
func start() {
checkOpPerms("started")
log.WithField("os.Args", os.Args).Debug("invoking service start")
pidFile := util.PidFilePath()
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: start
func (c *CLI) start() {
checkOpPerms("started")
log.WithField("os.Args", os.Args).Debug("invoking service start")
pidFile := util.PidFilePath()
if gotil.FileExists(pidFile) {
pid, pidErr := util.ReadPidFile()
if pidErr != nil {
fmt.Printf("Error reading REX-Ray PID file at %s\n", pidFile)
panic(1)
}
rrproc, err := findProcess(pid)
if err != nil {
fmt.Printf("Error finding process for PID %d", pid)
panic(1)
}
if rrproc != nil {
fmt.Printf("REX-Ray already running at PID %d\n", pid)
panic(1)
}
if err := os.RemoveAll(pidFile); err != nil {
fmt.Println("Error removing REX-Ray PID file")
panic(1)
}
}
if c.fg || c.client != "" {
c.startDaemon()
} else {
c.tryToStartDaemon()
}
}