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:
parent
b5432e78b9
commit
f8982f4a1a
3 changed files with 20 additions and 7 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||||
|
|
@ -67,12 +68,26 @@ func handleJob(client *jobqueue.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var address string
|
var unix bool
|
||||||
flag.StringVar(&address, "remote", "", "Connect to a remote composer using the specified address")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
address := flag.Arg(0)
|
||||||
|
if address == "" {
|
||||||
|
flag.Usage()
|
||||||
|
}
|
||||||
|
|
||||||
var client *jobqueue.Client
|
var client *jobqueue.Client
|
||||||
if address != "" {
|
if unix {
|
||||||
|
client = jobqueue.NewClientUnix(address)
|
||||||
|
} else {
|
||||||
address = fmt.Sprintf("%s:%d", address, RemoteWorkerPort)
|
address = fmt.Sprintf("%s:%d", address, RemoteWorkerPort)
|
||||||
|
|
||||||
conf, err := createTLSConfig(&connectionConfig{
|
conf, err := createTLSConfig(&connectionConfig{
|
||||||
|
|
@ -85,8 +100,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
client = jobqueue.NewClient(address, conf)
|
client = jobqueue.NewClient(address, conf)
|
||||||
} else {
|
|
||||||
client = jobqueue.NewClientUnix(address)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ After=multi-user.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
PrivateTmp=true
|
PrivateTmp=true
|
||||||
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker --remote %i
|
ExecStart=/usr/libexec/osbuild-composer/osbuild-worker %i
|
||||||
CacheDirectory=osbuild-composer
|
CacheDirectory=osbuild-composer
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=10s
|
RestartSec=10s
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ After=multi-user.target osbuild-composer.socket
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
PrivateTmp=true
|
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
|
Restart=on-failure
|
||||||
RestartSec=10s
|
RestartSec=10s
|
||||||
CPUSchedulingPolicy=batch
|
CPUSchedulingPolicy=batch
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue