From dc1b84fcfeb946a1a0553c7af9df0c448cacc21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Mon, 16 Nov 2020 11:48:46 +0100 Subject: [PATCH] composer: split out the local worker socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Everybody hates the local workers. The first step of getting rid of them is to split their socket out of osbuild-composer.socket - we need to keep this one to support the Weldr API but the local worker socket can live in its own file. The behaviour should be the same for now: osbuild-composer.service always starts the local worker socket. However, this split allows the osbuild-composer executable to be run without the Weldr API activated. The following commit explores this option more in depth. Note that the new socket can be used by root only because workers are always run as root. Signed-off-by: Ondřej Budai --- cmd/osbuild-composer/composer.go | 23 ++++++++++++++++------- cmd/osbuild-composer/main.go | 16 +++++++++++----- distribution/osbuild-composer.socket | 1 - distribution/osbuild-local-worker.socket | 9 +++++++++ distribution/osbuild-worker@.service | 4 ++-- osbuild-composer.spec | 1 + 6 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 distribution/osbuild-local-worker.socket diff --git a/cmd/osbuild-composer/composer.go b/cmd/osbuild-composer/composer.go index f82c13df7..580f3d926 100644 --- a/cmd/osbuild-composer/composer.go +++ b/cmd/osbuild-composer/composer.go @@ -79,7 +79,7 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string, logger * return &c, nil } -func (c *Composer) InitWeldr(repoPaths []string, weldrListener, localWorkerListener net.Listener) error { +func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener) error { archName := common.CurrentArch() hostDistro, beta, err := c.distros.FromHost() @@ -109,7 +109,6 @@ func (c *Composer) InitWeldr(repoPaths []string, weldrListener, localWorkerListe c.weldr = weldr.New(c.rpm, arch, hostDistro, repos[archName], c.logger, store, c.workers, compatOutputDir) c.weldrListener = weldrListener - c.localWorkerListener = localWorkerListener return nil } @@ -133,6 +132,10 @@ func (c *Composer) InitAPI(cert, key string, l net.Listener) error { return nil } +func (c *Composer) InitLocalWorker(l net.Listener) { + c.localWorkerListener = l +} + func (c *Composer) InitRemoteWorkers(cert, key string, l net.Listener) error { tlsConfig, err := createTLSConfig(&connectionConfig{ CACertFile: c.config.Worker.CA, @@ -153,10 +156,6 @@ func (c *Composer) InitRemoteWorkers(cert, key string, l net.Listener) error { // // Running without the weldr API is currently not supported. func (c *Composer) Start() error { - if c.weldr == nil { - return errors.New("weldr was not initialized") - } - if c.localWorkerListener != nil { go func() { err := c.workers.Serve(c.localWorkerListener) @@ -200,7 +199,17 @@ func (c *Composer) Start() error { }() } - return c.weldr.Serve(c.weldrListener) + if c.weldrListener != nil { + go func() { + err := c.weldr.Serve(c.weldrListener) + if err != nil { + panic(err) + } + }() + } + + // wait indefinitely + select {} } func (c *Composer) ensureStateDirectory(name string, perm os.FileMode) (string, error) { diff --git a/cmd/osbuild-composer/main.go b/cmd/osbuild-composer/main.go index a22b2943a..f10eaa821 100644 --- a/cmd/osbuild-composer/main.go +++ b/cmd/osbuild-composer/main.go @@ -65,16 +65,22 @@ func main() { } if l, exists := listeners["osbuild-composer.socket"]; exists { - if len(l) != 2 { - log.Fatalf("Expected two listeners in osbuild-composer.socket, but found %d", len(l)) + if len(l) != 1 { + log.Fatal("The osbuild-composer.socket unit is misconfigured. It should contain only one socket.") } - err = composer.InitWeldr(repositoryConfigs, l[0], l[1]) + err = composer.InitWeldr(repositoryConfigs, l[0]) if err != nil { log.Fatalf("Error initializing weldr API: %v", err) } - } else { - log.Fatalf("osbuild-composer.socket doesn't exist") + } + + if l, exists := listeners["osbuild-local-worker.socket"]; exists { + if len(l) != 1 { + log.Fatal("The osbuild-local-worker.socket unit is misconfigured. It should contain only one socket.") + } + + composer.InitLocalWorker(l[0]) } if l, exists := listeners["osbuild-composer-api.socket"]; exists { diff --git a/distribution/osbuild-composer.socket b/distribution/osbuild-composer.socket index 0c0620cf3..fe5dd229f 100644 --- a/distribution/osbuild-composer.socket +++ b/distribution/osbuild-composer.socket @@ -3,7 +3,6 @@ Description=OSBuild Composer Weldr API socket [Socket] ListenStream=/run/weldr/api.socket -ListenStream=/run/osbuild-composer/job.socket SocketGroup=weldr SocketMode=660 diff --git a/distribution/osbuild-local-worker.socket b/distribution/osbuild-local-worker.socket new file mode 100644 index 000000000..6cac2132a --- /dev/null +++ b/distribution/osbuild-local-worker.socket @@ -0,0 +1,9 @@ +[Unit] +Description=OSBuild local worker API socket + +[Socket] +Service=osbuild-composer.service +ListenStream=/run/osbuild-composer/job.socket + +[Install] +WantedBy=sockets.target diff --git a/distribution/osbuild-worker@.service b/distribution/osbuild-worker@.service index b06cdb87d..36d10f6da 100644 --- a/distribution/osbuild-worker@.service +++ b/distribution/osbuild-worker@.service @@ -1,7 +1,7 @@ [Unit] Description=OSBuild Composer Worker (%i) -Requires=osbuild-composer.socket -After=multi-user.target osbuild-composer.socket +Requires=osbuild-local-worker.socket +After=multi-user.target osbuild-local-worker.socket [Service] Type=simple diff --git a/osbuild-composer.spec b/osbuild-composer.spec index 4e352be70..dc7b34e10 100644 --- a/osbuild-composer.spec +++ b/osbuild-composer.spec @@ -245,6 +245,7 @@ cd $PWD/_build/src/%{goipath} %{_unitdir}/osbuild-composer.service %{_unitdir}/osbuild-composer.socket %{_unitdir}/osbuild-composer-api.socket +%{_unitdir}/osbuild-local-worker.socket %{_unitdir}/osbuild-remote-worker.socket %{_sysusersdir}/osbuild-composer.conf