1
0
forked from ALHP/ALHP.GO

prevent repo-remove from getting SIGKILLed because main process exited

This commit is contained in:
2021-07-09 14:12:43 +02:00
parent a2819587f1
commit 51bf7b7924

26
main.go
View File

@@ -60,6 +60,7 @@ type BuildManager struct {
exit bool exit bool
buildWG sync.WaitGroup buildWG sync.WaitGroup
parseWG sync.WaitGroup parseWG sync.WaitGroup
repoWG sync.WaitGroup
failedMutex sync.RWMutex failedMutex sync.RWMutex
buildProcesses []*os.Process buildProcesses []*os.Process
buildProcMutex sync.RWMutex buildProcMutex sync.RWMutex
@@ -295,7 +296,7 @@ func (b *BuildManager) buildWorker(id int) {
log.Warningf("[%s/%s] Build failed, exit code %d", pkg.FullRepo, pkg.Pkgbase, cmd.ProcessState.ExitCode()) log.Warningf("[%s/%s] Build failed, exit code %d", pkg.FullRepo, pkg.Pkgbase, cmd.ProcessState.ExitCode())
b.failedMutex.Lock() b.failedMutex.Lock()
f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm) f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, os.ModePerm)
check(err) check(err)
if pkg.Srcinfo.Epoch != "" { if pkg.Srcinfo.Epoch != "" {
@@ -538,8 +539,8 @@ func (b *BuildManager) repoWorker() {
cmd := exec.Command("repo-add", args...) cmd := exec.Command("repo-add", args...)
res, err := cmd.CombinedOutput() res, err := cmd.CombinedOutput()
log.Debug(string(res)) log.Debug(string(res))
if err != nil { if err != nil && cmd.ProcessState.ExitCode() != 1 {
log.Panicf("%v while repo-add: %s", err, string(res)) log.Panicf("%s while repo-add: %v", string(res), err)
} }
cmd = exec.Command("paccache", cmd = exec.Command("paccache",
@@ -562,6 +563,7 @@ func (b *BuildManager) repoWorker() {
realPkgs = append(realPkgs, realPkg.Pkgname) realPkgs = append(realPkgs, realPkg.Pkgname)
} }
b.repoWG.Add(1)
args := []string{"-s", "-v", filepath.Join(conf.Basedir.Repo, pkg.FullRepo, "os", conf.Arch, pkg.FullRepo) + ".db.tar.xz"} args := []string{"-s", "-v", filepath.Join(conf.Basedir.Repo, pkg.FullRepo, "os", conf.Arch, pkg.FullRepo) + ".db.tar.xz"}
args = append(args, realPkgs...) args = append(args, realPkgs...)
cmd := exec.Command("repo-remove", args...) cmd := exec.Command("repo-remove", args...)
@@ -576,6 +578,7 @@ func (b *BuildManager) repoWorker() {
check(os.Remove(file)) check(os.Remove(file))
check(os.Remove(file + ".sig")) check(os.Remove(file + ".sig"))
} }
b.repoWG.Done()
} }
} }
} }
@@ -689,17 +692,11 @@ func main() {
check(err) check(err)
buildManager = BuildManager{ buildManager = BuildManager{
toBuild: make(chan *BuildPackage, 10000), toBuild: make(chan *BuildPackage, 10000),
toParse: make(chan *BuildPackage, 10000), toParse: make(chan *BuildPackage, 10000),
toPurge: make(chan *BuildPackage, conf.Build.Worker), toPurge: make(chan *BuildPackage, conf.Build.Worker),
toRepoAdd: make(chan *BuildPackage, conf.Build.Worker), toRepoAdd: make(chan *BuildPackage, conf.Build.Worker),
exit: false, exit: false,
buildWG: sync.WaitGroup{},
failedMutex: sync.RWMutex{},
stats: struct {
fullyBuild int
eligible int
}{fullyBuild: 0, eligible: 0},
} }
setupChroot() setupChroot()
@@ -720,4 +717,5 @@ func main() {
} }
buildManager.buildProcMutex.RUnlock() buildManager.buildProcMutex.RUnlock()
buildManager.buildWG.Wait() buildManager.buildWG.Wait()
buildManager.repoWG.Wait()
} }