示例#1
0
func startProcesses(t, v *process.Process, c *config.Config, ctx context.Context) error {
	t.SetUser(uint32(c.Transmission.UID), uint32(c.Transmission.GID))

	logger.Infof("Starting openvpn")
	go v.ExecuteAndRestart(ctx)

	ip, er := getIP(c.OpenVPN.Tun, c.Timeout.Duration, ctx)
	if er != nil {
		return er
	}
	logger.Infof("New bind ip: (%s) %s", c.OpenVPN.Tun, ip)

	port, er := getPort(ip, c.PIA.User, c.PIA.Pass, c.PIA.ClientID, c.Timeout.Duration, ctx)
	if er != nil {
		return er
	}
	logger.Infof("New peer port: %d", port)

	if er := transmission.UpdateSettings(c.Transmission.Config, ip, port); er != nil {
		return er
	}

	logger.Infof("Starting transmission")
	go t.ExecuteAndRestart(ctx)

	return nil
}
示例#2
0
func portCheck(t *process.Process, c *config.Config, ctx context.Context) error {
	if transmission.
		NewRawClient(c.Transmission.URL.String(), c.Transmission.User, c.Transmission.Pass).
		CheckPort() {
		return nil
	}

	logger.Infof("Transmission port not open, stopping transmission")
	t.Stop()

	ip, er := getIP(c.OpenVPN.Tun, c.Timeout.Duration, ctx)
	if er != nil {
		return er
	}
	logger.Infof("New bind ip: (%s) %s", c.OpenVPN.Tun, ip)

	port, er := getPort(ip, c.PIA.User, c.PIA.Pass, c.PIA.ClientID, c.Timeout.Duration, ctx)
	if er != nil {
		return er
	}
	logger.Infof("New peer port: %d", port)

	if er := transmission.UpdateSettings(c.Transmission.Config, ip, port); er != nil {
		return er
	}

	logger.Infof("Starting transmission")
	go t.ExecuteAndRestart(ctx)
	return nil
}