Browse Source

update: daemon of xray

v1.x.x
dnomd343 2 years ago
parent
commit
f2f7c5f20d
  1. 5
      cmd/network/main.go
  2. 52
      cmd/xproxy.go
  3. 21
      src/main.go
  4. 24
      src/process.go

5
cmd/network/main.go

@ -2,6 +2,7 @@ package network
import ( import (
"XProxy/cmd/common" "XProxy/cmd/common"
log "github.com/sirupsen/logrus"
"time" "time"
) )
@ -16,11 +17,13 @@ type Config struct {
var run = common.RunCommand var run = common.RunCommand
func Load(dns []string, ipv4 Config, ipv6 Config) { func Load(dns []string, ipv4 Config, ipv6 Config) {
var delay time.Duration = 1
loadDns(dns) // init dns server loadDns(dns) // init dns server
flushNetwork() // clear network settings flushNetwork() // clear network settings
loadV4Network(ipv4) loadV4Network(ipv4)
loadV6Network(ipv6) loadV6Network(ipv6)
time.Sleep(time.Second) // wait 1s for ipv6 (ND protocol) log.Infof("Wait %ds for IPv6 setting up", delay)
time.Sleep(delay * time.Second) // wait for ipv6 setting up (ND protocol)
loadV4TProxy(ipv4, getV4Cidr()) loadV4TProxy(ipv4, getV4Cidr())
loadV6TProxy(ipv6, getV6Cidr()) loadV6TProxy(ipv6, getV6Cidr())
} }

52
cmd/xproxy.go

@ -1,10 +1,13 @@
package main package main
import ( import (
"XProxy/cmd/config"
"XProxy/cmd/process" "XProxy/cmd/process"
"fmt" "fmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"time" "os"
"os/signal"
"syscall"
) )
var version = "dev" var version = "dev"
@ -20,29 +23,38 @@ var assetFile = "/assets.tar.xz"
var assetDir = exposeDir + "/assets" var assetDir = exposeDir + "/assets"
var configFile = exposeDir + "/config.yml" var configFile = exposeDir + "/config.yml"
func main() { var subProcess []*process.Process
log.SetLevel(log.DebugLevel)
fmt.Println("XProxy start -> version =", version)
//settings := config.Load(configFile) func runProxy() {
//loadNetwork(&settings) proxy := process.New("xray", "-confdir", configDir)
//loadProxy(&settings) proxy.Run(true)
//loadAsset(&settings) proxy.Daemon()
//runScript(&settings) subProcess = append(subProcess, proxy)
}
xray := process.New("xray", "-confdir", configDir)
xray.Run(true)
xray.Daemon()
sleep := process.New("sleep", "1001") func blockWait() {
sleep.Run(true) sigExit := make(chan os.Signal, 1)
sleep.Daemon() signal.Notify(sigExit, syscall.SIGINT, syscall.SIGTERM) // wait until get exit signal
<-sigExit
}
empty := process.New("empty") func main() {
empty.Daemon() defer func() {
if err := recover(); err != nil {
log.Errorf("Unknown error -> %v", err)
}
}()
time.Sleep(5 * time.Second) log.SetLevel(log.DebugLevel)
fmt.Println("XProxy start -> version =", version)
process.Exit(xray, sleep, empty) settings := config.Load(configFile)
loadNetwork(&settings)
loadProxy(&settings)
loadAsset(&settings)
runScript(&settings)
runProxy()
blockWait()
process.Exit(subProcess...)
} }

21
src/main.go

@ -1,21 +0,0 @@
package main
import (
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
)
func main() {
defer func() {
if err := recover(); err != nil {
log.Errorf("Unknown error -> %v", err)
}
}()
sigExit := make(chan os.Signal, 1)
signal.Notify(sigExit, syscall.SIGINT, syscall.SIGTERM)
<-sigExit
exit()
}

24
src/process.go

@ -1,24 +0,0 @@
package main
import (
"os/exec"
)
var subProcess []*Process
func killSub(sub *Process) {
defer func() {
recover()
}()
}
func waitSub(sub *exec.Cmd) {
defer func() {
recover()
}()
}
func exit() {
}
Loading…
Cancel
Save