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 }
func restartProcesses(t, v *process.Process, c *config.Config, ctx context.Context) error { var ( notify = func(e error, t time.Duration) { logger.Errorf("Failed to restart processes (retry in %v): %v", t, e) } operation = func() error { t.Stop() v.Stop() return startProcesses(t, v, c, ctx) } b = backoff.NewExponentialBackOff() ) b.MaxElapsedTime = 30 * time.Minute b.MaxInterval = 10 * time.Second return backoff.RetryNotify(operation, b, notify) }