Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
After=syslog.target network.target

[Service]
Type=simple
User=postgres
ExecStart=/usr/local/bin/patroni /var/lib/pgsql/18/storefront-n1-689qacsi/configs/patroni.yaml
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
TimeoutSec=30
CPUQuota=1400%
Restart=on-failure
Environment="PATH=/usr/pgsql-18/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin"
Environment="PGSERVICEFILE=/var/lib/pgsql/18/storefront-n1-689qacsi/configs/pg_service.conf"

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
After=syslog.target network.target

[Service]
Type=simple
User=postgres
ExecStart=/usr/local/bin/patroni /var/lib/pgsql/18/storefront-n1-689qacsi/configs/patroni.yaml
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
TimeoutSec=30
CPUQuota=50%
Restart=on-failure
Environment="PATH=/usr/pgsql-18/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin"
Environment="PGSERVICEFILE=/var/lib/pgsql/18/storefront-n1-689qacsi/configs/pg_service.conf"

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
After=syslog.target network.target

[Service]
Type=simple
User=postgres
ExecStart=/usr/local/bin/patroni /var/lib/pgsql/18/storefront-n1-689qacsi/configs/patroni.yaml
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
TimeoutSec=30
MemoryMax=8589934592
Restart=on-failure
Environment="PATH=/usr/pgsql-18/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin"
Environment="PGSERVICEFILE=/var/lib/pgsql/18/storefront-n1-689qacsi/configs/pg_service.conf"

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
After=syslog.target network.target

[Service]
Type=simple
User=postgres
ExecStart=/usr/local/bin/patroni /var/lib/pgsql/18/storefront-n1-689qacsi/configs/patroni.yaml
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
TimeoutSec=30
Restart=on-failure
Environment="PATH=/usr/pgsql-18/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin"
Environment="PGSERVICEFILE=/var/lib/pgsql/18/storefront-n1-689qacsi/configs/pg_service.conf"

[Install]
WantedBy=multi-user.target
16 changes: 16 additions & 0 deletions server/internal/orchestrator/systemd/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package systemd_test

import (
"flag"
"os"
"testing"
)

var update bool

func TestMain(m *testing.M) {
flag.BoolVar(&update, "update", false, "update golden test outputs")
flag.Parse()

os.Exit(m.Run())
}
2 changes: 1 addition & 1 deletion server/internal/orchestrator/systemd/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (o *Orchestrator) GenerateInstanceResources(spec *database.InstanceSpec) (*
DatabaseID: spec.DatabaseID,
HostID: spec.HostID,
Name: patroniServiceName(spec.InstanceID),
Options: patroniUnitOptions(paths, o.packageManager.BinDir(pgMajor)),
Options: PatroniUnitOptions(paths, o.packageManager.BinDir(pgMajor), spec.CPUs, spec.MemoryBytes),
ExtraDependencies: []resource.Identifier{
patroniConfig.Identifier(),
instanceDir.Identifier(),
Expand Down
92 changes: 32 additions & 60 deletions server/internal/orchestrator/systemd/patroni_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,43 @@ import (
"path/filepath"

"github.com/coreos/go-systemd/v22/unit"

"github.com/pgEdge/control-plane/server/internal/orchestrator/common"
)

func patroniUnitOptions(paths common.InstancePaths, pgBinPath string) []*unit.UnitOption {
pathEnv := "PATH=" + pgBinPath
func PatroniUnitOptions(
paths common.InstancePaths,
pgBinPath string,
cpus float64,
memoryBytes uint64,
) []*unit.UnitOption {
pathEnv := pgBinPath
if p := os.Getenv("PATH"); p != "" {
pathEnv += ":" + p
}
patroniCmd := fmt.Sprintf("%s %s", paths.PatroniPath, paths.Instance.PatroniConfig())
pgServiceFileEnv := filepath.Join(paths.Instance.Configs(), "pg_service.conf")

return []*unit.UnitOption{
{
Section: "Unit",
Name: "After",
Value: "syslog.target network.target",
},
{
Section: "Service",
Name: "Type",
Value: "simple",
},
{
Section: "Service",
Name: "User",
Value: "postgres",
},
{
Section: "Service",
Name: "ExecStart",
Value: fmt.Sprintf("%s %s", paths.PatroniPath, paths.Instance.PatroniConfig()),
},
{
Section: "Service",
Name: "ExecReload",
Value: "/bin/kill -s HUP $MAINPID",
},
{
Section: "Service",
Name: "KillMode",
Value: "process",
},
{
Section: "Service",
Name: "TimeoutSec",
Value: "30",
},
{
Section: "Service",
Name: "Restart",
Value: "on-failure",
},
{
Section: "Service",
Name: "Environment",
Value: pathEnv,
},
{
Section: "Service",
Name: "Environment",
Value: "PGSERVICEFILE=" + filepath.Join(paths.Instance.Configs(), "pg_service.conf"),
},
{
Section: "Install",
Name: "WantedBy",
Value: "multi-user.target",
},
}
return UnitFile{
Unit: UnitSection{
After: []string{"syslog.target", "network.target"},
},
Service: ServiceSection{
Type: ServiceTypeSimple,
User: "postgres",
ExecStart: patroniCmd,
ExecReload: "/bin/kill -s HUP $MAINPID",
KillMode: ServiceKillModeProcess,
TimeoutSec: 30,
CPUs: cpus,
MemoryBytes: memoryBytes,
Restart: ServiceRestartOnFailure,
Environment: map[string]string{
"PATH": pathEnv,
"PGSERVICEFILE": pgServiceFileEnv,
},
},
Install: InstallSection{
WantedBy: []string{"multi-user.target"},
},
}.Options()
}
Loading