Change: do not exit on Openvpn config error
This commit is contained in:
@@ -123,8 +123,6 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
return fmt.Errorf("command %q is unknown", args[1])
|
return fmt.Errorf("command %q is unknown", args[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
const clientTimeout = 15 * time.Second
|
const clientTimeout = 15 * time.Second
|
||||||
httpClient := &http.Client{Timeout: clientTimeout}
|
httpClient := &http.Client{Timeout: clientTimeout}
|
||||||
@@ -261,7 +259,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
healthy := make(chan bool)
|
healthy := make(chan bool)
|
||||||
|
|
||||||
openvpnLooper := openvpn.NewLooper(allSettings.OpenVPN, nonRootUsername, puid, pgid, allServers,
|
openvpnLooper := openvpn.NewLooper(allSettings.OpenVPN, nonRootUsername, puid, pgid, allServers,
|
||||||
ovpnConf, firewallConf, routingConf, logger, httpClient, os.OpenFile, tunnelReadyCh, healthy, cancel)
|
ovpnConf, firewallConf, routingConf, logger, httpClient, os.OpenFile, tunnelReadyCh, healthy)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
// wait for restartOpenvpn
|
// wait for restartOpenvpn
|
||||||
go openvpnLooper.Run(ctx, wg)
|
go openvpnLooper.Run(ctx, wg)
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ type looper struct {
|
|||||||
openFile os.OpenFileFunc
|
openFile os.OpenFileFunc
|
||||||
tunnelReady chan<- struct{}
|
tunnelReady chan<- struct{}
|
||||||
healthy <-chan bool
|
healthy <-chan bool
|
||||||
cancel context.CancelFunc
|
|
||||||
// Internal channels and locks
|
// Internal channels and locks
|
||||||
loopLock sync.Mutex
|
loopLock sync.Mutex
|
||||||
running chan models.LoopStatus
|
running chan models.LoopStatus
|
||||||
@@ -67,7 +66,7 @@ func NewLooper(settings configuration.OpenVPN,
|
|||||||
username string, puid, pgid int, allServers models.AllServers,
|
username string, puid, pgid int, allServers models.AllServers,
|
||||||
conf Configurator, fw firewall.Configurator, routing routing.Routing,
|
conf Configurator, fw firewall.Configurator, routing routing.Routing,
|
||||||
logger logging.Logger, client *http.Client, openFile os.OpenFileFunc,
|
logger logging.Logger, client *http.Client, openFile os.OpenFileFunc,
|
||||||
tunnelReady chan<- struct{}, healthy <-chan bool, cancel context.CancelFunc) Looper {
|
tunnelReady chan<- struct{}, healthy <-chan bool) Looper {
|
||||||
return &looper{
|
return &looper{
|
||||||
state: state{
|
state: state{
|
||||||
status: constants.Stopped,
|
status: constants.Stopped,
|
||||||
@@ -86,7 +85,6 @@ func NewLooper(settings configuration.OpenVPN,
|
|||||||
openFile: openFile,
|
openFile: openFile,
|
||||||
tunnelReady: tunnelReady,
|
tunnelReady: tunnelReady,
|
||||||
healthy: healthy,
|
healthy: healthy,
|
||||||
cancel: cancel,
|
|
||||||
start: make(chan struct{}),
|
start: make(chan struct{}),
|
||||||
running: make(chan models.LoopStatus),
|
running: make(chan models.LoopStatus),
|
||||||
stop: make(chan struct{}),
|
stop: make(chan struct{}),
|
||||||
@@ -126,10 +124,9 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) { //nolint:gocogni
|
|||||||
if len(settings.Config) == 0 {
|
if len(settings.Config) == 0 {
|
||||||
connection, err = providerConf.GetOpenVPNConnection(settings.Provider.ServerSelection)
|
connection, err = providerConf.GetOpenVPNConnection(settings.Provider.ServerSelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.logger.Error(err)
|
|
||||||
l.signalCrashedStatus()
|
l.signalCrashedStatus()
|
||||||
l.cancel()
|
l.logAndWait(ctx, err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
lines = providerConf.BuildConf(connection, l.username, settings)
|
lines = providerConf.BuildConf(connection, l.username, settings)
|
||||||
} else {
|
} else {
|
||||||
@@ -142,24 +139,21 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) { //nolint:gocogni
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := writeOpenvpnConf(lines, l.openFile); err != nil {
|
if err := writeOpenvpnConf(lines, l.openFile); err != nil {
|
||||||
l.logger.Error(err)
|
|
||||||
l.signalCrashedStatus()
|
l.signalCrashedStatus()
|
||||||
l.cancel()
|
l.logAndWait(ctx, err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := l.conf.WriteAuthFile(settings.User, settings.Password, l.puid, l.pgid); err != nil {
|
if err := l.conf.WriteAuthFile(settings.User, settings.Password, l.puid, l.pgid); err != nil {
|
||||||
l.logger.Error(err)
|
|
||||||
l.signalCrashedStatus()
|
l.signalCrashedStatus()
|
||||||
l.cancel()
|
l.logAndWait(ctx, err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := l.fw.SetVPNConnection(ctx, connection); err != nil {
|
if err := l.fw.SetVPNConnection(ctx, connection); err != nil {
|
||||||
l.logger.Error(err)
|
|
||||||
l.signalCrashedStatus()
|
l.signalCrashedStatus()
|
||||||
l.cancel()
|
l.logAndWait(ctx, err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
||||||
|
|||||||
Reference in New Issue
Block a user