FatalOnError fixes
This commit is contained in:
@@ -57,8 +57,8 @@ func _main(background context.Context, args []string) int {
|
|||||||
ctx, cancel := context.WithCancel(background)
|
ctx, cancel := context.WithCancel(background)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
logger := createLogger()
|
logger := createLogger()
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
fatalOnError := makeFatalOnError(logger, cancel, wg)
|
fatalOnError := makeFatalOnError(logger, cancel)
|
||||||
|
|
||||||
client := network.NewClient(15 * time.Second)
|
client := network.NewClient(15 * time.Second)
|
||||||
// Create configurators
|
// Create configurators
|
||||||
@@ -143,6 +143,8 @@ func _main(background context.Context, args []string) int {
|
|||||||
fatalOnError(err)
|
fatalOnError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
openvpnLooper := openvpn.NewLooper(allSettings.VPNSP, allSettings.OpenVPN, uid, gid,
|
openvpnLooper := openvpn.NewLooper(allSettings.VPNSP, allSettings.OpenVPN, uid, gid,
|
||||||
ovpnConf, firewallConf, logger, client, fileManager, streamMerger, fatalOnError)
|
ovpnConf, firewallConf, logger, client, fileManager, streamMerger, fatalOnError)
|
||||||
restartOpenvpn := openvpnLooper.Restart
|
restartOpenvpn := openvpnLooper.Restart
|
||||||
@@ -249,18 +251,11 @@ func _main(background context.Context, args []string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFatalOnError(logger logging.Logger, cancel context.CancelFunc, wg *sync.WaitGroup) func(err error) {
|
func makeFatalOnError(logger logging.Logger, cancel context.CancelFunc) func(err error) {
|
||||||
return func(err error) {
|
return func(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
cancel()
|
cancel()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
|
||||||
cancel()
|
|
||||||
}()
|
|
||||||
<-ctx.Done() // either timeout or wait group completed
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,10 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
|||||||
settings := l.GetSettings()
|
settings := l.GetSettings()
|
||||||
providerConf := provider.New(l.provider)
|
providerConf := provider.New(l.provider)
|
||||||
connections, err := providerConf.GetOpenVPNConnections(settings.Provider.ServerSelection)
|
connections, err := providerConf.GetOpenVPNConnections(settings.Provider.ServerSelection)
|
||||||
|
if err != nil {
|
||||||
l.fatalOnError(err)
|
l.fatalOnError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
lines := providerConf.BuildConf(
|
lines := providerConf.BuildConf(
|
||||||
connections,
|
connections,
|
||||||
settings.Verbosity,
|
settings.Verbosity,
|
||||||
@@ -112,14 +115,19 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
|||||||
settings.Auth,
|
settings.Auth,
|
||||||
settings.Provider.ExtraConfigOptions,
|
settings.Provider.ExtraConfigOptions,
|
||||||
)
|
)
|
||||||
err = l.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(l.uid, l.gid), files.Permissions(0400))
|
if err := l.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(l.uid, l.gid), files.Permissions(0400)); err != nil {
|
||||||
l.fatalOnError(err)
|
l.fatalOnError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err = l.conf.WriteAuthFile(settings.User, settings.Password, l.uid, l.gid)
|
if err := l.conf.WriteAuthFile(settings.User, settings.Password, l.uid, l.gid); err != nil {
|
||||||
l.fatalOnError(err)
|
l.fatalOnError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := l.fw.SetVPNConnections(ctx, connections); err != nil {
|
if err := l.fw.SetVPNConnections(ctx, connections); err != nil {
|
||||||
l.fatalOnError(err)
|
l.fatalOnError(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
||||||
|
|||||||
Reference in New Issue
Block a user