cmd/osbuild-composer: run RCM socket from a separate unit

Right now the implementation expects the RCM socket to live in the same
unit file as other osbuild-composer sockets. This would require a
solution where we ship the osbuild-composer.socket in two different
versions: one for regular usage, one for rcm. But that is very
inconvenient and it would probably require some weird scriptlets (and
scriptlets are bad!).

After this change, the RCM API socket lives in a separate file and only
if the socket unit is activated, the API runs. The unit file itself was
introduced in previous commits.
This commit is contained in:
Martin Sehnoutka 2020-02-21 14:26:28 +01:00 committed by Tom Gundersen
parent 6f5a2d9dcb
commit 5b67a5947c

View file

@ -4,6 +4,7 @@ import (
"crypto/tls"
"crypto/x509"
"flag"
"github.com/osbuild/osbuild-composer/internal/rcm"
"io/ioutil"
"log"
"os"
@ -11,7 +12,6 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
"github.com/osbuild/osbuild-composer/internal/rcm"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/store"
"github.com/osbuild/osbuild-composer/internal/weldr"
@ -108,10 +108,19 @@ func main() {
go jobAPI.Serve(jobListener)
// Optionally run RCM API as well as Weldr API
if len(listeners) == 3 {
rcmListener := composerListeners[2]
rcmAPI := rcm.New(logger, store, rpmmd.NewRPMMD())
go rcmAPI.Serve(rcmListener)
if rcmApiListeners, exists := listeners["osbuild-rcm.socket"]; exists {
if len(rcmApiListeners) != 1 {
// Use Fatal to call os.Exit with non-zero return value
log.Fatal("The RCM API socket unit is misconfigured. It should contain only one socket.")
}
rcmListener := rcmApiListeners[0]
rcmAPI := rcm.New(logger, store, rpm)
go func() {
err := rcmAPI.Serve(rcmListener)
// If the RCM API fails, take down the whole process, not just a single gorutine
log.Fatal("RCM API failed: ", err)
}()
}
if remoteWorkerListeners, exists := listeners["osbuild-remote-worker.socket"]; exists {