systemd service fails on startup but works when started manually

Solvedjournalctllinuxsystemd4 replies · 38 views · started

Accepted solution

by Noor LopezJump to the reply

"Works manually, fails at boot" is very often a dependency on the newtork. if your app connects to something or binds to a specific IP, add this to the [Unit] section:

Wants=network-online.target
After=network-online.target
  1. ok weird one my custom service fails during boot but starts fine afterwards by hand. i suspect its starting too early and smth isnt ready yet, but Im guessing.

    How do ppl dig into this properly? Id like to understand teh logs rather than just adding sleeps to the script. Its a Debian-based box, nothing exotic lol The app itself is a small Python service that talks to a database. im about to throw this thing out the window lol

    3
  2. Consider adding Restart=on-failure with a RestartSec=5. It doesnt fix the root cause, but it makes the service resilient to transient issues, which is good practice anyway. Just dont let it hide a real problem: check the journal for repeated restarts. good luck man!

    21 1 helpful
  3. Well. Other boot-time differences: environment variables (ur shell has them, systemd doenst), relative paths (set WorkingDirectory=), and mounts that arent ready yet (use RequiresMountsFor=/path). Compare what the app expects with what teh unit actually provides. Running systemctl show myapp dumps the effective settings, which helps when youre not sure what applies. fingers crossed 🤞

    lol

    0 6 helpful
  4. "Works manually, fails at boot" is very often a dependency on the newtork. if your app connects to something or binds to a specific IP, add this to the [Unit] section:

    Wants=network-online.target
    After=network-online.target
    
    2 4 helpful
  5. @noor.lopez added network-online.target and RequiresMountsFor for teh data disk 🔥 rebooted three times, service comes up every time. journalctl -b -1 was exactly what i needed.

    report back with what you find.

    1 0 helpful

Reply to this topic

Sign in or create an account to reply.