restart fix + slack commands
This commit is contained in:
1 parent
e90c9f324b
commit
25fcf85855
22 files changed
+1077
-119
No files matched your search
@@ -29,6 +29,9 @@ const (
|
||||
machinedName = "org.freedesktop.machine1"
|
||||
machinedPath = "/org/freedesktop/machine1"
|
||||
machinedMgr = "org.freedesktop.machine1.Manager"
|
||||
systemdName = "org.freedesktop.systemd1"
|
||||
systemdPath = "/org/freedesktop/systemd1"
|
||||
systemdMgr = "org.freedesktop.systemd1.Manager"
|
||||
sigPoweroff = 38 // SIGRTMIN+4, what `machinectl poweroff` sends
|
||||
|
||||
agentEnvInside = "/var/lib/slackerbot/agent.env"
|
||||
@@ -114,7 +117,7 @@ func (l *Local) Running(ctx context.Context) ([]node.RunningMachine, error) {
|
||||
if !model.IsOurs(x.Name) {
|
||||
continue
|
||||
}
|
||||
r := node.RunningMachine{Name: x.Name}
|
||||
r := node.RunningMachine{Name: x.Name, Outdated: l.outdated(x.Name)}
|
||||
if v, err := l.bus.Object(machinedName, x.Path).GetProperty("org.freedesktop.machine1.Machine.Timestamp"); err == nil {
|
||||
if us, ok := v.Value().(uint64); ok {
|
||||
r.Since = time.UnixMicro(int64(us))
|
||||
@@ -125,6 +128,40 @@ func (l *Local) Running(ctx context.Context) ([]node.RunningMachine, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// The unit's command ends with the init of the system the container booted.
|
||||
// When it can't be read, the container counts as up to date.
|
||||
func (l *Local) outdated(machine string) bool {
|
||||
args := l.execStart(unitName(machine))
|
||||
if len(args) == 0 {
|
||||
return false
|
||||
}
|
||||
init := args[len(args)-1]
|
||||
return filepath.Base(init) == "init" && filepath.Dir(init) != l.system
|
||||
}
|
||||
|
||||
func (l *Local) execStart(unit string) []string {
|
||||
var path dbus.ObjectPath
|
||||
if err := l.bus.Object(systemdName, systemdPath).Call(systemdMgr+".GetUnit", 0, unit).Store(&path); err != nil {
|
||||
return nil
|
||||
}
|
||||
v, err := l.bus.Object(systemdName, path).GetProperty(systemdName + ".Service.ExecStart")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var cmds []struct {
|
||||
Path string
|
||||
Args []string
|
||||
IgnoreErrors bool
|
||||
StartTime, StartTimeMono, ExitTime, ExitTimeMono uint64
|
||||
PID uint32
|
||||
Code, Status int32
|
||||
}
|
||||
if err := v.Store(&cmds); err != nil || len(cmds) == 0 {
|
||||
return nil
|
||||
}
|
||||
return cmds[0].Args
|
||||
}
|
||||
|
||||
func (l *Local) IsRunning(machine string) bool {
|
||||
var p dbus.ObjectPath
|
||||
return l.machined().Call(machinedMgr+".GetMachine", 0, machine).Store(&p) == nil
|
||||
@@ -201,16 +238,25 @@ func (l *Local) Start(ctx context.Context, spec node.StartSpec) error {
|
||||
"--bind-ro=" + envFile + ":" + agentEnvInside,
|
||||
"--bind=" + home + ":/root",
|
||||
}
|
||||
for _, b := range l.cfg.ROBinds {
|
||||
args = append(args, "--bind-ro="+strings.ReplaceAll(b, "{machine}", spec.Machine))
|
||||
}
|
||||
for _, b := range l.cfg.RWBinds {
|
||||
b = strings.ReplaceAll(b, "{machine}", spec.Machine)
|
||||
src, _, _ := strings.Cut(b, ":")
|
||||
if err := os.MkdirAll(src, 0o755); err != nil {
|
||||
return err
|
||||
binds := func(list []string, flag string) error {
|
||||
for _, b := range list {
|
||||
b = strings.ReplaceAll(b, "{machine}", spec.Machine)
|
||||
src, _, _ := strings.Cut(b, ":")
|
||||
// Missing sources make systemd-nspawn fail; existing ones may be files.
|
||||
if _, err := os.Stat(src); errors.Is(err, os.ErrNotExist) {
|
||||
if err := os.MkdirAll(src, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
args = append(args, flag+b)
|
||||
}
|
||||
args = append(args, "--bind="+b)
|
||||
return nil
|
||||
}
|
||||
if err := binds(l.cfg.ROBinds, "--bind-ro="); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binds(l.cfg.RWBinds, "--bind="); err != nil {
|
||||
return err
|
||||
}
|
||||
args = append(args, filepath.Join(l.system, "init"))
|
||||
|
||||
|
||||
Reference in new issue
Block a user