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 (
"XProxy/cmd/common"
log "github.com/sirupsen/logrus"
"time"
)
@ -16,11 +17,13 @@ type Config struct {
var run = common.RunCommand
func Load(dns []string, ipv4 Config, ipv6 Config) {
var delay time.Duration = 1
loadDns(dns) // init dns server
flushNetwork() // clear network settings
loadV4Network(ipv4)
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())
loadV6TProxy(ipv6, getV6Cidr())
}

52
cmd/xproxy.go

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