containerswindows-subsystem-for-linuxsystemdpodmanquestdb

Running podman start through systemd service gives error 125 while manually doing it works fine


I`m trying to make a .service on wsl to autostart a QuestDB container on start and restart it when needed. For some reason I get error 125 when trying to start the service but it works perfectly fine if I input the command giving me the error directly.

Used sudo nano systemctl /etc/systemd/system/podman-QuestDBTeste.service to create the file and the content is as follows:

[Unit]
Description=QuestDB Container
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=10
ExecStartPre=/bin/bash -c 'fuser -k 9000/tcp 8812/tcp 9009/tcp || true'
ExecStart=/usr/bin/podman start -a QuestDBTeste > /home/gabriel/podman_log.txt
ExecStop=podman stop -t 2 QuestDBTeste
ExecReload=/usr/bin/podman restart QuestDBTeste

[Install]
WantedBy=multi-user.target

When I send systemctl status podman-QuestDBTeste.service I get

podman-QuestDBTeste.service - QuestDB Container
     Loaded: loaded (/etc/systemd/system/podman-QuestDBTeste.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Mon 2024-05-27 22:39:16 -03; 9s ago
    Process: 4114 ExecStartPre=/bin/bash -c fuser -k 9000/tcp 8812/tcp 9009/tcp || true (code=exited, status=0/SUCCESS)
    Process: 4116 ExecStart=sudo /usr/bin/podman start -a QuestDBTeste > /home/gabriel/podman_log.txt (code=exited, status=125)
   Main PID: 4116 (code=exited, status=125)

But if I type directly podman start -a QuestDBTeste, it works perfectly fine and starts the container.

I have no idea why and was expecting the .service to work the same as me inputing podman start -a QuestDBTeste


Solution

  • Maybe avoid sudo and redirections in your service config so it behaves as close as possible to the local command line? Something like

    [Unit]
    Description=QuestDB Container
    After=network.target
    
    [Service]
    Type=simple
    Restart=always
    RestartSec=10
    ExecStartPre=/bin/bash -c 'fuser -k 9000/tcp 8812/tcp 9009/tcp || true'
    ExecStart=/usr/bin/podman start -a QuestDBTeste
    ExecStop=/usr/bin/podman stop -t 2 QuestDBTeste
    ExecReload=/usr/bin/podman restart QuestDBTeste
    User=gabriel
    Group=gabriel
    Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    StandardOutput=append:/home/gabriel/podman_log.txt
    StandardError=append:/home/gabriel/podman_error_log.txt
    
    [Install]
    WantedBy=multi-user.target
    

    Then

    sudo systemctl daemon-reload
    sudo systemctl restart podman-QuestDBTeste.service