forked from kryptco/kr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_unix.go
37 lines (33 loc) · 841 Bytes
/
socket_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// +build !darwin
package kr
import (
"fmt"
"net"
"os"
"os/exec"
"time"
)
func DaemonDial(unixFile string) (conn net.Conn, err error) {
if !IsKrdRunning() {
os.Stderr.WriteString(Yellow("Krypton ▶ Restarting krd...\r\n"))
exec.Command("nohup", "krd").Start()
<-time.After(1 * time.Second)
}
conn, err = net.Dial("unix", unixFile)
if err != nil {
// restart then try again
os.Stderr.WriteString(Yellow("Krypton ▶ Restarting krd...\r\n"))
KillKrd()
exec.Command("nohup", "krd").Start()
<-time.After(1 * time.Second)
conn, err = net.Dial("unix", unixFile)
}
if err != nil {
err = fmt.Errorf("Failed to connect to Krypton daemon. Please make sure it is running by typing \"kr restart\".")
}
return
}
func KillKrd() {
exec.Command("pkill", "-U", User(), "-x", "krd").Run()
<-time.After(1*time.Second)
}