Integration of osbuild composer with systemd
osbuild-composer now uses socket activation instead of hardcoded paths in the code. osbuild-worker is an http client therefore it uses only service unit. osbuild-worker must be started after the socket is created. osbuild-composer service requires osbuild-worker to run, because without it no jobs can be started. osbuild-composer is executed as a regular user (newly created _osbuild-composer user) as opposed to the worker which must run as root in order to execute osbuild itself
This commit is contained in:
parent
d23d57bc31
commit
ed185b41ce
11 changed files with 88 additions and 34 deletions
12
Makefile
Normal file
12
Makefile
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
build:
|
||||
go build -o osbuild-composer ./cmd/osbuild-composer/
|
||||
go build -o osbuild-worker ./cmd/osbuild-worker/
|
||||
|
||||
install:
|
||||
- mkdir -p /usr/lib/osbuild-composer
|
||||
cp osbuild-composer /usr/lib/osbuild-composer/
|
||||
cp osbuild-worker /usr/lib/osbuild-composer/
|
||||
cp dnf-json /usr/lib/osbuild-composer/
|
||||
|
||||
run-socket:
|
||||
systemd-socket-activate -l /run/weldr/api.socket -l /run/osbuild-composer/job.socket ./osbuild-composer
|
||||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
|
@ -12,6 +11,8 @@ import (
|
|||
"osbuild-composer/internal/jobqueue"
|
||||
"osbuild-composer/internal/rpmmd"
|
||||
"osbuild-composer/internal/weldr"
|
||||
|
||||
"github.com/coreos/go-systemd/activation"
|
||||
)
|
||||
|
||||
const StateFile = "/var/lib/osbuild-composer/weldr-state.json"
|
||||
|
|
@ -21,35 +22,17 @@ func main() {
|
|||
flag.BoolVar(&verbose, "v", false, "Print access log")
|
||||
flag.Parse()
|
||||
|
||||
err := os.Remove("/run/weldr/api.socket")
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.Mkdir("/run/weldr", 0755)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
weldrListener, err := net.Listen("unix", "/run/weldr/api.socket")
|
||||
listeners, err := activation.Listeners()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.Remove("/run/osbuild-composer/job.socket")
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
panic(err)
|
||||
if len(listeners) != 2 {
|
||||
panic("Unexpected number of sockets. Composer require 2 of them.")
|
||||
}
|
||||
|
||||
err = os.Mkdir("/run/osbuild-composer", 0755)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
jobListener, err := net.Listen("unix", "/run/osbuild-composer/job.socket")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
weldrListener := listeners[0]
|
||||
jobListener := listeners[1]
|
||||
|
||||
repo := rpmmd.RepoConfig{
|
||||
Id: "fedora-30",
|
||||
|
|
|
|||
23
distribution/Makefile
Normal file
23
distribution/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
sd-install:
|
||||
cp *.service /etc/systemd/system/
|
||||
cp *.socket /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
|
||||
sd-start:
|
||||
systemctl start osbuild-composer.socket
|
||||
systemctl start osbuild-worker.service
|
||||
|
||||
sd-enable:
|
||||
systemctl enable osbuild-composer.socket
|
||||
systemctl enable osbuild-worker.service
|
||||
|
||||
sd-stop:
|
||||
systemctl disable osbuild-composer.socket
|
||||
systemctl stop osbuild-composer.socket
|
||||
systemctl stop osbuild-composer.service
|
||||
systemctl disable osbuild-worker.service
|
||||
systemctl stop osbuild-worker.service
|
||||
|
||||
user-install:
|
||||
- mkdir -p /etc/sysusers.d/
|
||||
cp osbuild-composer.conf /etc/sysusers.d/
|
||||
1
distribution/osbuild-composer.conf
Normal file
1
distribution/osbuild-composer.conf
Normal file
|
|
@ -0,0 +1 @@
|
|||
u _osbuild-composer - "OSBuild Composer user"
|
||||
16
distribution/osbuild-composer.service
Normal file
16
distribution/osbuild-composer.service
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[Unit]
|
||||
Description=OSBuild Composer
|
||||
After=multi-user.target
|
||||
Requires=osbuild-composer.socket
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/lib/osbuild-composer/osbuild-composer
|
||||
RuntimeDirectory=osbuild-composer weldr
|
||||
StateDirectory=osbuild-composer
|
||||
WorkingDirectory=/usr/lib/osbuild-composer/
|
||||
User=_osbuild-composer
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
9
distribution/osbuild-composer.socket
Normal file
9
distribution/osbuild-composer.socket
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
PartOf=osbuild-composer.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/weldr/api.socket
|
||||
ListenStream=/run/osbuild-composer/job.socket
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
15
distribution/osbuild-worker.service
Normal file
15
distribution/osbuild-worker.service
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[Unit]
|
||||
Description=OSBuild Composer Worker (%i)
|
||||
After=multi-user.target osbuild-composer.socket
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
PrivateTmp=true
|
||||
ExecStart=/usr/lib/osbuild-composer/osbuild-worker -C /var/lib/osbuild
|
||||
CacheDirectory=osbuild-composer
|
||||
Restart=on-failure
|
||||
RestartSec=10s
|
||||
|
||||
[Install]
|
||||
DefaultInstance=1
|
||||
WantedBy=multi-user.target
|
||||
1
go.mod
1
go.mod
|
|
@ -3,6 +3,7 @@ module osbuild-composer
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/julienschmidt/httprouter v1.2.0
|
||||
)
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -1,3 +1,5 @@
|
|||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c=
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
[Unit]
|
||||
Description=OSBuild Composer Worker (%i)
|
||||
|
||||
[Service]
|
||||
PrivateTmp=true
|
||||
ExecStart=/usr/local/lib/osbuild-composer/osbuild-composer-worker -C /var/lib/osbuild
|
||||
|
||||
[Install]
|
||||
DefaultInstance=1
|
||||
WantedBy=default.target
|
||||
|
|
@ -2,6 +2,7 @@ package rpmmd
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"time"
|
||||
|
|
@ -44,6 +45,7 @@ func runDNF(command string, arguments []string, result interface{}) error {
|
|||
cmd := exec.Command("python3", argv...)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not execute dnf-json")
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue