diff --git a/podman_compose.py b/podman_compose.py index 3bbad25a..49c44278 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1742,14 +1742,16 @@ def compose_systemd(compose, args): """ create systemd unit file and register its compose stacks - When first installed type `sudo podman-compose -a create-unit` + When first installed type `podman-compose -a create-unit` later you can add a compose stack by running `podman-compose -a register` then you can start/stop your stack with `systemctl --user start podman-compose@<PROJ>` """ - stacks_dir = ".config/containers/compose/projects" + config_home = os.environ.get("XDG_CONFIG_HOME", "~/.config") + config_home = os.path.expanduser(config_home) + stacks_dir = "containers/compose/projects" if args.action == "register": proj_name = compose.project_name - fn = os.path.expanduser(f"~/{stacks_dir}/{proj_name}.env") + fn = f"{config_home}/{stacks_dir}/{proj_name}.env" os.makedirs(os.path.dirname(fn), exist_ok=True) print(f"writing [{fn}]: ...") with open(fn, "w", encoding="utf-8") as f: @@ -1783,11 +1785,11 @@ def compose_systemd(compose, args): """ ) elif args.action in ("list", "ls"): - ls = glob.glob(os.path.expanduser(f"~/{stacks_dir}/*.env")) + ls = glob.glob(f"{config_home}/{stacks_dir}/*.env") for i in ls: print(os.path.basename(i[:-4])) elif args.action == "create-unit": - fn = "/usr/lib/systemd/user/podman-compose@.service" + fn = f"{config_home}/systemd/user/podman-compose@.service" out = f"""\ # {fn} @@ -1796,7 +1798,7 @@ def compose_systemd(compose, args): [Service] Type=simple -EnvironmentFile=%h/{stacks_dir}/%i.env +EnvironmentFile=%E/{stacks_dir}/%i.env ExecStartPre=-{script} up --no-start ExecStartPre=/usr/bin/podman pod start pod_%i ExecStart={script} wait @@ -1817,7 +1819,7 @@ def compose_systemd(compose, args): ) else: print(out) - log(f"Could not write to [{fn}], use 'sudo'") + log(f"Could not write to [{fn}]") @cmd_run(podman_compose, "pull", "pull stack images")