Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect XDG_CONFIG_HOME when generating systemd unit #477

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}

Expand All @@ -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
Expand All @@ -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")
Expand Down