misc, setup, util: Add a ulimit

I think this gives us the ability to open more files.
This commit is contained in:
James Shubin
2025-06-05 22:20:53 -04:00
parent 650e8392c5
commit 301ce03061
3 changed files with 8 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ Requires=systemd-networkd.service
ExecStart=/usr/bin/mgmt run empty $OPTS ExecStart=/usr/bin/mgmt run empty $OPTS
RestartSec=5s RestartSec=5s
Restart=always Restart=always
LimitNOFILE=16384
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@@ -135,6 +135,7 @@ func (obj *Svc) Run(ctx context.Context) error {
ExecStart: execStart, ExecStart: execStart,
RestartSec: "5s", RestartSec: "5s",
Restart: "always", Restart: "always",
LimitNOFILE: 16384,
WantedBy: []string{"multi-user.target"}, WantedBy: []string{"multi-user.target"},
} }
unitData, err := unit.Template() unitData, err := unit.Template()

View File

@@ -62,6 +62,9 @@ type UnitData struct {
// Restart is the restart policy. Usually you want "always". // Restart is the restart policy. Usually you want "always".
Restart string Restart string
// LimitNOFILE is the max number of files this process can open.
LimitNOFILE uint
// RemainAfterExit can be set to true to make it look like the service // RemainAfterExit can be set to true to make it look like the service
// is still active if it exits successfully. // is still active if it exits successfully.
RemainAfterExit bool RemainAfterExit bool
@@ -110,6 +113,9 @@ func (obj *UnitData) Template() (string, error) {
if obj.Restart != "" { if obj.Restart != "" {
data += fmt.Sprintf("Restart=%s\n", obj.Restart) data += fmt.Sprintf("Restart=%s\n", obj.Restart)
} }
if obj.LimitNOFILE > 0 {
data += fmt.Sprintf("LimitNOFILE=%d\n", obj.LimitNOFILE)
}
if obj.RemainAfterExit { if obj.RemainAfterExit {
data += "RemainAfterExit=yes\n" data += "RemainAfterExit=yes\n"