osbuild-composer: don't use hardcoded state directory

Use $STATE_DIRECTORY environment variable which is set by systemd
because we use: StateDirectory=osbuild-composer in the service unit.

also change systemd unit to include STATE_DIRECTORY, because
RHEL comes with older systemd version, so we need to set this variable explicitly.
This commit is contained in:
Martin Sehnoutka 2020-03-10 14:43:05 +01:00 committed by Tom Gundersen
parent 7957feff48
commit 9f4042af6c
2 changed files with 5 additions and 1 deletions

View file

@ -54,7 +54,10 @@ func main() {
flag.BoolVar(&verbose, "v", false, "Print access log")
flag.Parse()
stateDir := "/var/lib/osbuild-composer"
stateDir, ok := os.LookupEnv("STATE_DIRECTORY")
if !ok {
log.Fatal("STATE_DIRECTORY is not set. Is the service file missing StateDirectory=?")
}
listeners, err := activation.ListenersWithNames()
if err != nil {

View file

@ -15,6 +15,7 @@ Restart=on-failure
# systemd >= 240 sets this, but osbuild-composer runs on earlier versions
Environment="CACHE_DIRECTORY=/var/cache/osbuild-composer"
Environment="STATE_DIRECTORY=/var/lib/osbuild-composer"
[Install]
WantedBy=multi-user.target