Fix: controlled interrupt exit for subprograms

- Openvpn and Unbound do not receive OS signals
- Openvpn and Unbound run in a different process group than the entrypoint
- Openvpn and Unbound are gracefully shutdown by the entrypoint
- Update golibs with a modified command package
- Update dns to v1.9.0 where Unbound is luanched in its own group
This commit is contained in:
Quentin McGaw (desktop)
2021-07-16 20:04:17 +00:00
parent c2d527bbd3
commit 7c44188130
5 changed files with 24 additions and 11 deletions

4
go.mod
View File

@@ -5,8 +5,8 @@ go 1.16
require (
github.com/fatih/color v1.12.0
github.com/golang/mock v1.6.0
github.com/qdm12/dns v1.8.0
github.com/qdm12/golibs v0.0.0-20210603202746-e5494e9c2ebb
github.com/qdm12/dns v1.9.0
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80
github.com/qdm12/goshutdown v0.1.0
github.com/qdm12/ss-server v0.2.0
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e

7
go.sum
View File

@@ -63,10 +63,11 @@ github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee/go.mod h1:3uODdxMg
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qdm12/dns v1.8.0 h1:GZ40kptmfDHOMNxBKWSA4zrbNyGm41BA57zv2MaDtCI=
github.com/qdm12/dns v1.8.0/go.mod h1:P2mm63NDYZdx2NAd5CVLM0FBnNdi1ZgVjsRSnX+96vg=
github.com/qdm12/golibs v0.0.0-20210603202746-e5494e9c2ebb h1:5WkOssTWl6Tv2H7VFb2jwB08A7BxxNCebkkpvz1PzrY=
github.com/qdm12/dns v1.9.0 h1:p4g/BfbpQ+gJRpQdklDAnybkjds+OuenF0wEGoZ8/AI=
github.com/qdm12/dns v1.9.0/go.mod h1:fqZoDf3VzddnKBMNI/OzZUp5H4dO0VBw1fp4qPkolOg=
github.com/qdm12/golibs v0.0.0-20210603202746-e5494e9c2ebb/go.mod h1:15RBzkun0i8XB7ADIoLJWp9ITRgsz3LroEI2FiOXLRg=
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80 h1:rvH2MSs8RXEfuXivzoYCim6tRNPzdqjBzqJq8w4Tc0k=
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80/go.mod h1:15RBzkun0i8XB7ADIoLJWp9ITRgsz3LroEI2FiOXLRg=
github.com/qdm12/goshutdown v0.1.0 h1:lmwnygdXtnr2pa6VqfR/bm8077/BnBef1+7CP96B7Sw=
github.com/qdm12/goshutdown v0.1.0/go.mod h1:/LP3MWLqI+wGH/ijfaUG+RHzBbKXIiVKnrg5vXOCf6Q=
github.com/qdm12/ss-server v0.2.0 h1:+togLzeeLAJ68MD1JqOWvYi9rl9t/fx1Qh7wKzZhY1g=

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os/exec"
"strings"
"github.com/qdm12/golibs/command"
@@ -15,7 +16,8 @@ var (
)
func ip6tablesSupported(ctx context.Context, commander command.Commander) (supported bool) {
if _, err := commander.Run(ctx, "ip6tables", "-L"); err != nil {
cmd := exec.CommandContext(ctx, "ip6tables", "-L")
if _, err := commander.Run(cmd); err != nil {
return false
}
return true
@@ -40,7 +42,8 @@ func (c *configurator) runIP6tablesInstruction(ctx context.Context, instruction
fmt.Println("ip6tables " + instruction)
}
flags := strings.Fields(instruction)
if output, err := c.commander.Run(ctx, "ip6tables", flags...); err != nil {
cmd := exec.CommandContext(ctx, "ip6tables", flags...)
if output, err := c.commander.Run(cmd); err != nil {
return fmt.Errorf("%w: \"ip6tables %s\": %s: %s", ErrIP6Tables, instruction, output, err)
}
return nil

View File

@@ -7,6 +7,7 @@ import (
"io"
"net"
"os"
"os/exec"
"strings"
"github.com/qdm12/gluetun/internal/models"
@@ -46,7 +47,8 @@ func flipRule(rule string) string {
// Version obtains the version of the installed iptables.
func (c *configurator) Version(ctx context.Context) (string, error) {
output, err := c.commander.Run(ctx, "iptables", "--version")
cmd := exec.CommandContext(ctx, "iptables", "--version")
output, err := c.commander.Run(cmd)
if err != nil {
return "", err
}
@@ -74,7 +76,8 @@ func (c *configurator) runIptablesInstruction(ctx context.Context, instruction s
fmt.Printf("iptables %s\n", instruction)
}
flags := strings.Fields(instruction)
if output, err := c.commander.Run(ctx, "iptables", flags...); err != nil {
cmd := exec.CommandContext(ctx, "iptables", flags...)
if output, err := c.commander.Run(cmd); err != nil {
return fmt.Errorf("%w \"iptables %s\": %s: %s", ErrIPTables, instruction, output, err)
}
return nil

View File

@@ -4,7 +4,9 @@ import (
"context"
"errors"
"fmt"
"os/exec"
"strings"
"syscall"
"github.com/qdm12/gluetun/internal/constants"
)
@@ -30,7 +32,10 @@ func (c *configurator) Start(ctx context.Context, version string) (
c.logger.Info("starting OpenVPN " + version)
return c.commander.Start(ctx, bin, "--config", constants.OpenVPNConf)
cmd := exec.CommandContext(ctx, bin, "--config", constants.OpenVPNConf)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
return c.commander.Start(cmd)
}
func (c *configurator) Version24(ctx context.Context) (version string, err error) {
@@ -44,7 +49,8 @@ func (c *configurator) Version25(ctx context.Context) (version string, err error
var ErrVersionTooShort = errors.New("version output is too short")
func (c *configurator) version(ctx context.Context, binName string) (version string, err error) {
output, err := c.commander.Run(ctx, binName, "--version")
cmd := exec.CommandContext(ctx, binName, "--version")
output, err := c.commander.Run(cmd)
if err != nil && err.Error() != "exit status 1" {
return "", err
}