10

I'm using systemd to start a caddy webserver on an ubuntu 16.04 machine. Whenever I run sudo service caddy start and service caddy status, I get this error:

● caddy.service - Caddy webserver
   Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2016-08-29 05:03:02 EDT; 4s ago
     Docs: https://caddyserver.com/
  Process: 1135 ExecStart=/usr/local/bin/caddy -agree -email me@example -pidfile=/var/run/caddy/caddy.pid (code=exited, status
 Main PID: 1135 (code=exited, status=1/FAILURE)

systemd[1]: Started Caddy webserver.
caddy[1135]: Activating privacy features... done.
caddy[1135]: 2016/08/29 05:03:02 Caddyfile:12 - Parse error: unknown property 'errors'
systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: caddy.service: Unit entered failed state.
systemd[1]: caddy.service: Failed with result 'exit-code'.
ki9
  • 5,183
  • 5
  • 37
  • 48

2 Answers2

26

In my /etc/systemd/system/caddy.service file, I had the following line:

Restart=on-failure

Commenting that out (with # or ;) and restarting the service showed the underlying problem, which was in my Caddyfile.

EDIT:

service caddy status only prints a few lines from the log, so sometimes you can find the underlying problem by simply looking at the full log. If using syslog, this is done with:

journalctl -u caddy
ki9
  • 5,183
  • 5
  • 37
  • 48
6

For anyone else pulling their hair out, note the lines StartLimitInterval and StartLimitBurst in the caddy.service file - if you're testing and repeatedly stop / starting you will hit the StartLimitBurst limit. Need to increase it to lots, or change the StartLimitInterval, to allow this.

Tobin
  • 1,698
  • 15
  • 24
  • looks like the keyword `StartLimitInterval` might have changed to `StartLimitIntervalSec` according to: https://www.freedesktop.org/software/systemd/man/systemd.unit.html#StartLimitIntervalSec= – Alex Fortin Nov 04 '18 at 18:44
  • 1
    Moreover, the intuition is that if the `StartLimitBurst` limit is encountered within `StartLimitIntervalSec` seconds, the process is not allowed to try to start anymore. So what you will want is to increase `StartLimitBurst` and to decrease `StartLimitIntervalSec`. For example, in my own process, I used: `StartLimitBurst`=100 and `StartLimitInterval`=3. (I do not know if this a good practice, but it is only an example) – Alex Fortin Nov 04 '18 at 18:46