carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package host
4
5import (
6 "context"
7 "net"
8 "os/exec"
9
10 "golang.org/x/sys/unix"
11)
12
13func dialDBReadWorker(ctx context.Context) (net.Conn, error) {
14 var d net.Dialer
15 return d.DialContext(ctx, "unix", dbReadSocketPath)
16}
17
18// dbReadUnits lists carlos-dbread@ units, readable without privilege.
19func dbReadUnits(ctx context.Context) (int, error) {
20 out, err := exec.CommandContext(ctx, "systemctl", "list-units", "--all", "--plain", "--no-legend", "--no-pager", "carlos-dbread@*.service").Output()
21 if err != nil {
22 return 0, err
23 }
24 return countDBReadUnits(string(out)), nil
25}
26
27// varTmpFree is the filesystem holding /var/tmp, where every worker's
28// private /var/tmp lives.
29func varTmpFree() (uint64, uint64, error) {
30 var st unix.Statfs_t
31 if err := unix.Statfs("/var/tmp", &st); err != nil {
32 return 0, 0, err
33 }
34 return st.Bavail * uint64(st.Bsize), st.Blocks * uint64(st.Bsize), nil
35}
36