Browse Source

update: env with asset folder

v1.x.x
dnomd343 2 years ago
parent
commit
e832536afc
  1. 3
      Dockerfile
  2. 12
      cmd/controller.go
  3. 2
      cmd/process/daemon.go
  4. 8
      cmd/process/main.go

3
Dockerfile

@ -53,8 +53,7 @@ COPY --from=radvd /tmp/radvd* /asset/usr/sbin/
COPY --from=proxy /tmp/*ray /asset/usr/bin/ COPY --from=proxy /tmp/*ray /asset/usr/bin/
FROM alpine:3.16 FROM alpine:3.16
ENV XRAY_LOCATION_ASSET=/xproxy/assets
RUN apk add --no-cache iptables ip6tables RUN apk add --no-cache iptables ip6tables
COPY --from=asset /asset/ / COPY --from=asset /asset/ /
WORKDIR /xproxy WORKDIR /xproxy
CMD ["xproxy"] ENTRYPOINT ["xproxy"]

12
cmd/controller.go

@ -17,9 +17,9 @@ import (
"time" "time"
) )
func runProcess(command ...string) { func runProcess(env []string, command ...string) {
sub := process.New(command...) sub := process.New(command...)
sub.Run(true) sub.Run(true, env)
sub.Daemon() sub.Daemon()
subProcess = append(subProcess, sub) subProcess = append(subProcess, sub)
} }
@ -62,11 +62,11 @@ func runScript(settings *config.Config) {
func runProxy(settings *config.Config) { func runProxy(settings *config.Config) {
if settings.Proxy.Core == "xray" { // xray-core if settings.Proxy.Core == "xray" { // xray-core
runProcess("xray", "-confdir", configDir) runProcess([]string{"XRAY_LOCATION_ASSET=" + assetDir}, "xray", "-confdir", configDir)
} else if settings.Proxy.Core == "v2ray" { // v2fly-core } else if settings.Proxy.Core == "v2ray" { // v2fly-core
runProcess("v2ray", "-confdir", configDir) runProcess([]string{"V2RAY_LOCATION_ASSET=" + assetDir}, "v2ray", "-confdir", configDir)
} else if settings.Proxy.Core == "sagray" { // sager-core } else if settings.Proxy.Core == "sagray" { // sager-core
runProcess("sagray", "run", "-confdir", configDir) runProcess([]string{"V2RAY_LOCATION_ASSET=" + assetDir}, "sagray", "run", "-confdir", configDir)
} else { } else {
log.Panicf("Unknown core type -> %s", settings.Proxy.Core) log.Panicf("Unknown core type -> %s", settings.Proxy.Core)
} }
@ -81,6 +81,6 @@ func runRadvd(settings *config.Config) {
radvdCmd = append(radvdCmd, "--debug", strconv.Itoa(settings.Radvd.Log)) radvdCmd = append(radvdCmd, "--debug", strconv.Itoa(settings.Radvd.Log))
time.Sleep(time.Second) // radvd will crash on first boot without delay (enable debug), why??? time.Sleep(time.Second) // radvd will crash on first boot without delay (enable debug), why???
} }
runProcess(radvdCmd...) runProcess(nil, radvdCmd...)
} }
} }

2
cmd/process/daemon.go

@ -12,7 +12,7 @@ func daemonSub(sub *Process) {
log.Warningf("Catch process %s exit", sub.name) log.Warningf("Catch process %s exit", sub.name)
time.Sleep(3 * time.Second) // delay 3s -> try to restart time.Sleep(3 * time.Second) // delay 3s -> try to restart
if !exitFlag { if !exitFlag {
sub.Run(true) sub.Run(true, sub.env)
log.Infof("Process %s restart success", sub.name) log.Infof("Process %s restart success", sub.name)
daemonSub(sub) daemonSub(sub)
} }

8
cmd/process/main.go

@ -9,6 +9,7 @@ import (
type Process struct { type Process struct {
name string name string
env []string
command []string command []string
process *exec.Cmd process *exec.Cmd
} }
@ -21,12 +22,17 @@ func New(command ...string) *Process {
return process return process
} }
func (p *Process) Run(isOutput bool) { func (p *Process) Run(isOutput bool, env []string) {
p.process = exec.Command(p.command[0], p.command[1:]...) p.process = exec.Command(p.command[0], p.command[1:]...)
if isOutput { if isOutput {
p.process.Stdout = os.Stdout p.process.Stdout = os.Stdout
p.process.Stderr = os.Stderr p.process.Stderr = os.Stderr
} }
p.env = env
if len(p.env) != 0 {
p.process.Env = p.env
log.Infof("Process %s with env -> %v", p.name, p.env)
}
err := p.process.Start() err := p.process.Start()
if err != nil { if err != nil {
log.Errorf("Failed to start %s -> %v", p.name, err) log.Errorf("Failed to start %s -> %v", p.name, err)

Loading…
Cancel
Save