Sphere
Log in Join
☆ 1

systemd service restarts constantly, status says code=exited

Ubuntu 22.04, systemd 249. Wrote a unit for a small Python service. It starts, dies, then restarts every few seconds. systemctl status shows Active: inactive (dead) and code=exited, status=1/FAILURE, but journalctl -u myservice only shows the start and stop lines, no traceback. Running the exact ExecStart command by hand in a shell works fine. User is www-data, WorkingDirectory set. What would make it fail only under systemd?

⚑ Report

3 replies

☆ 3
E eventual ·2026-10-03#1

Command works by hand but fails under systemd is nearly always environment. systemd doesn't inherit your shell PATH or exports. Use absolute paths in ExecStart and add Environment= lines for anything the script expects. Also check permissions — www-data may not read the script or write its log. sudo -u www-data <command> reproduces it far more faithfully than running as yourself.

⚑ Report
☆ 0
H head ·2026-10-08#2

Two problems, both env. The script read a config var I'd exported in my shell but not in the unit, so I added Environment=APP_ENV=prod. And the log dir was root-owned so www-data couldn't write. sudo -u www-data exposed the second one straight away. Both fixed, service stable now.

⚑ Report
☆ 0
P plastic ·2026-10-12#3

Nice. For future debugging systemctl show myservice -p ExecStart -p Environment dumps exactly what systemd will run with, no guessing. And using Type=simple with an absolute python path saves a lot of head scratching.

⚑ Report
Log in to reply.