Configure Systemd Socket Activation

as new way for Poseidon to accept connections. This should reduce our issues caused by deployments.
This commit is contained in:
Maximilian Paß
2023-12-02 16:56:43 +01:00
parent eaa022282c
commit eaddc65989
11 changed files with 128 additions and 58 deletions

View File

@@ -1,15 +1,13 @@
package recovery
import (
"context"
"github.com/openHPI/poseidon/internal/api"
"github.com/openHPI/poseidon/pkg/dto"
"github.com/openHPI/poseidon/tests"
"github.com/openHPI/poseidon/tests/e2e"
"github.com/openHPI/poseidon/tests/helpers"
"github.com/shirou/gopsutil/v3/process"
"net/http"
"os"
"os/exec"
"time"
)
@@ -27,12 +25,8 @@ func (s *E2ERecoveryTestSuite) SetupTest() {
}
<-time.After(tests.ShortTimeout)
s.poseidonCancel()
killPoseidon()
<-time.After(tests.ShortTimeout)
ctx, cancelPoseidon := context.WithCancel(context.Background())
s.poseidonCancel = cancelPoseidon
startPoseidon(ctx, cancelPoseidon)
waitForPoseidon()
}
func TearDown() {
@@ -43,16 +37,6 @@ func TearDown() {
}
}
func startPoseidon(ctx context.Context, cancelPoseidon context.CancelFunc) {
poseidon := exec.CommandContext(ctx, *poseidonBinary) //nolint:gosec // We accept that another binary can be executed.
poseidon.Stdout = os.Stdout
poseidon.Stderr = os.Stderr
if err := poseidon.Start(); err != nil {
cancelPoseidon()
log.WithError(err).Fatal("Failed to start Poseidon")
}
}
func waitForPoseidon() {
done := false
for !done {
@@ -61,3 +45,24 @@ func waitForPoseidon() {
done = err == nil && resp.StatusCode == http.StatusNoContent
}
}
func killPoseidon() {
processes, err := process.Processes()
if err != nil {
log.WithError(err).Error("Error listing processes")
}
for _, p := range processes {
n, err := p.Name()
if err != nil {
continue
}
if n == "poseidon" {
err = p.Kill()
if err != nil {
log.WithError(err).Error("Error killing Poseidon")
} else {
log.Info("Killed Poseidon")
}
}
}
}