Download this file
| 1 | //go:build linux |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "net" |
| 8 | "os/exec" |
| 9 | |
| 10 | "golang.org/x/sys/unix" |
| 11 | ) |
| 12 | |
| 13 | func 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. |
| 19 | func 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. |
| 29 | func 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 | |