Setting run user with oci containers and systemd

Hello @kreativmonkey,

I get the config working well now!
I have added control of process by sdnotify. By this by its own, dont solve the problem.
Finally I get it working calling podman with a login shell. Now it is working like a charm after reboot.

  systemd.services.podman-hass = {
    enable = true;
    wantedBy = [ "default.target" ]; 
    after = [ "network.target" ];
    description = "Home Assistant pod";
    serviceConfig = 
    let 
      podmancli = "${pkgs.bash}/bin/bash -l -c \"${config.virtualisation.podman.package}/bin/podman";
      endpodmancli = "\"";
      hass_version = "0.118.0";
      podname = "hass";
      cleanup_pod = [
        "${podmancli} stop -i ${podname} ${endpodmancli}"
        "${podmancli} rm -i ${podname} ${endpodmancli}"
      ];
    in
    {
      User = "podmanager";
      WorkingDirectory = "/home/podmanager";
      ExecStartPre = cleanup_pod;
      ExecStart = "${podmancli} run " +
        "--rm " +
        "--name=${podname} " +
        "--sdnotify=conmon " +
        "--log-driver=journald " +
        "-p '50000:8123' " +
        "-v '/etc/localtime:/etc/localtime:ro' " +
        "-v '/home/podmanager/hass/config:/config' " +
        "homeassistant/home-assistant:${hass_version} ${endpodmancli}"; 

      Type = "notify";
      NotifyAccess = "all";
      ExecStop = "${podmancli} stop ${podname} ${endpodmancli}";
      ExecStopPost = cleanup_pod;
      Restart = "always";
      TimeoutStopSec = 15;
    };
  };

2 Likes