worker: don't hard code path to unix domain socket

Introduce a mandatory argument `address`, which is interpreted as a path
to a unix socket when `-unix` is given or a network address otherwise.

Move the default path to the service file.

Add a more useful usage message when passing `-help` or no arguments.
This commit is contained in:
Lars Karlitski 2020-03-25 08:45:30 +01:00 committed by Tom Gundersen
parent b5432e78b9
commit f8982f4a1a
3 changed files with 20 additions and 7 deletions

View file

@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
@ -67,12 +68,26 @@ func handleJob(client *jobqueue.Client) error {
}
func main() {
var address string
flag.StringVar(&address, "remote", "", "Connect to a remote composer using the specified address")
var unix bool
flag.BoolVar(&unix, "unix", false, "Interpret 'address' as a path to a unix domain socket instead of a network address")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [-unix] address\n", os.Args[0])
flag.PrintDefaults()
os.Exit(0)
}
flag.Parse()
address := flag.Arg(0)
if address == "" {
flag.Usage()
}
var client *jobqueue.Client
if address != "" {
if unix {
client = jobqueue.NewClientUnix(address)
} else {
address = fmt.Sprintf("%s:%d", address, RemoteWorkerPort)
conf, err := createTLSConfig(&connectionConfig{
@ -85,8 +100,6 @@ func main() {
}
client = jobqueue.NewClient(address, conf)
} else {
client = jobqueue.NewClientUnix(address)
}
for {

View file

@ -5,7 +5,7 @@ After=multi-user.target
[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker --remote %i
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker %i
CacheDirectory=osbuild-composer
Restart=on-failure
RestartSec=10s

View file

@ -6,7 +6,7 @@ After=multi-user.target osbuild-composer.socket
[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker -unix /run/osbuild-composer/job.socket
Restart=on-failure
RestartSec=10s
CPUSchedulingPolicy=batch