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:
parent
0ac554c139
commit
dc1b84fcfe
6 changed files with 39 additions and 15 deletions
|
|
@ -79,7 +79,7 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string, logger *
|
||||||
return &c, nil
|
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()
|
archName := common.CurrentArch()
|
||||||
|
|
||||||
hostDistro, beta, err := c.distros.FromHost()
|
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.weldr = weldr.New(c.rpm, arch, hostDistro, repos[archName], c.logger, store, c.workers, compatOutputDir)
|
||||||
|
|
||||||
c.weldrListener = weldrListener
|
c.weldrListener = weldrListener
|
||||||
c.localWorkerListener = localWorkerListener
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -133,6 +132,10 @@ func (c *Composer) InitAPI(cert, key string, l net.Listener) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Composer) InitLocalWorker(l net.Listener) {
|
||||||
|
c.localWorkerListener = l
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Composer) InitRemoteWorkers(cert, key string, l net.Listener) error {
|
func (c *Composer) InitRemoteWorkers(cert, key string, l net.Listener) error {
|
||||||
tlsConfig, err := createTLSConfig(&connectionConfig{
|
tlsConfig, err := createTLSConfig(&connectionConfig{
|
||||||
CACertFile: c.config.Worker.CA,
|
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.
|
// Running without the weldr API is currently not supported.
|
||||||
func (c *Composer) Start() error {
|
func (c *Composer) Start() error {
|
||||||
if c.weldr == nil {
|
|
||||||
return errors.New("weldr was not initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.localWorkerListener != nil {
|
if c.localWorkerListener != nil {
|
||||||
go func() {
|
go func() {
|
||||||
err := c.workers.Serve(c.localWorkerListener)
|
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) {
|
func (c *Composer) ensureStateDirectory(name string, perm os.FileMode) (string, error) {
|
||||||
|
|
|
||||||
|
|
@ -65,16 +65,22 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if l, exists := listeners["osbuild-composer.socket"]; exists {
|
if l, exists := listeners["osbuild-composer.socket"]; exists {
|
||||||
if len(l) != 2 {
|
if len(l) != 1 {
|
||||||
log.Fatalf("Expected two listeners in osbuild-composer.socket, but found %d", len(l))
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Error initializing weldr API: %v", err)
|
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 {
|
if l, exists := listeners["osbuild-composer-api.socket"]; exists {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ Description=OSBuild Composer Weldr API socket
|
||||||
|
|
||||||
[Socket]
|
[Socket]
|
||||||
ListenStream=/run/weldr/api.socket
|
ListenStream=/run/weldr/api.socket
|
||||||
ListenStream=/run/osbuild-composer/job.socket
|
|
||||||
SocketGroup=weldr
|
SocketGroup=weldr
|
||||||
SocketMode=660
|
SocketMode=660
|
||||||
|
|
||||||
|
|
|
||||||
9
distribution/osbuild-local-worker.socket
Normal file
9
distribution/osbuild-local-worker.socket
Normal 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
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=OSBuild Composer Worker (%i)
|
Description=OSBuild Composer Worker (%i)
|
||||||
Requires=osbuild-composer.socket
|
Requires=osbuild-local-worker.socket
|
||||||
After=multi-user.target osbuild-composer.socket
|
After=multi-user.target osbuild-local-worker.socket
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,7 @@ cd $PWD/_build/src/%{goipath}
|
||||||
%{_unitdir}/osbuild-composer.service
|
%{_unitdir}/osbuild-composer.service
|
||||||
%{_unitdir}/osbuild-composer.socket
|
%{_unitdir}/osbuild-composer.socket
|
||||||
%{_unitdir}/osbuild-composer-api.socket
|
%{_unitdir}/osbuild-composer-api.socket
|
||||||
|
%{_unitdir}/osbuild-local-worker.socket
|
||||||
%{_unitdir}/osbuild-remote-worker.socket
|
%{_unitdir}/osbuild-remote-worker.socket
|
||||||
%{_sysusersdir}/osbuild-composer.conf
|
%{_sysusersdir}/osbuild-composer.conf
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue