From 6ca7f73ea212014c1f2b112d5a31f20e6437cd8b Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Sat, 16 Apr 2022 12:23:04 +0000 Subject: [PATCH 1/2] Respect XDG_CONFIG_HOME if set Signed-off-by: Samir Benmendil --- podman_compose.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index 3bbad25..6e10e72 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1746,10 +1746,12 @@ def compose_systemd(compose, args): 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@` """ - 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,7 +1785,7 @@ 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": @@ -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 From 92781e4487a4bbee84a39dfe378c28615fc33746 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Sat, 16 Apr 2022 12:30:24 +0000 Subject: [PATCH 2/2] Install systemd unit into XDG_CONFIG_HOME/systemd/user Signed-off-by: Samir Benmendil --- podman_compose.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index 6e10e72..49c4427 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1742,7 +1742,7 @@ 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@` """ @@ -1789,7 +1789,7 @@ def compose_systemd(compose, args): 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} @@ -1819,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")