composer: split out the local worker socket

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 <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2020-11-16 11:48:46 +01:00 committed by Tom Gundersen
parent 0ac554c139
commit dc1b84fcfe
6 changed files with 39 additions and 15 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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