fix: release deploy locks on exit and honor apps:lock

A deploy that exited before releasing its lock, such as after a failed build, left `.deploy.lock` behind, so `apps:locked` reported a lock nothing held and the build record stayed running. The lock is now released and the record finalized whenever the deploy exits. `apps:lock` never actually blocked deploys, as it only created the file deploys lock. It now creates its own lock that git pushes, `ps:rebuild`, `git:sync`, and the `git:from-*` commands refuse to deploy past, and `apps:locked` only reports a lock when the app was locked via `apps:lock` or a deploy is in progress. Locks created by `apps:lock` in older versions are migrated on install.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-10-24 13:58:47 -04:00
1 parent 57ae817dab
commit c4b164a270
17 files changed
+535 -69

No files matched your search

+24 -7
View File
@@ -319,15 +319,12 @@ func CommandCancel(appName string) error {
if err := WriteBuild(b); err != nil {
return err
}
_ = os.Remove(lockPath)
removeLockForBuild(lockPath, buildID)
return nil
}
common.LogInfo1("Killing app deploy")
if err := killProcessGroup(b.PID); err != nil {
common.LogWarn(fmt.Sprintf("Failed to signal process group %d: %s", b.PID, err))
}
// the record is finalized before the signal is sent so that a deploy
// finalizing itself on exit leaves it as canceled
current, err := ReadBuild(appName, buildID)
if err == nil && current.Status == BuildStatusRunning {
now := time.Now().UTC()
@@ -340,10 +337,30 @@ func CommandCancel(appName string) error {
}
}
_ = os.Remove(lockPath)
common.LogInfo1("Killing app deploy")
if err := killProcessGroup(b.PID); err != nil {
common.LogWarn(fmt.Sprintf("Failed to signal process group %d: %s", b.PID, err))
}
removeLockForBuild(lockPath, buildID)
return nil
}
// removeLockForBuild removes the deploy lock file if it still holds the given
// build id, leaving a lock taken by a newer deploy in place
func removeLockForBuild(lockPath string, buildID string) {
body, err := os.ReadFile(lockPath)
if err != nil {
return
}
if strings.TrimSpace(string(body)) != buildID {
return
}
_ = os.Remove(lockPath)
}
func killProcessGroup(pid int) error {
pgid, err := syscall.Getpgid(pid)
if err != nil {