Caddy.service: Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing

1. Caddy version (caddy version):

Latest version, 2.

2. How I run Caddy:

Trying to follow a Digital Ocean tutorial and load the Caddy service into sytemd. I will show my commands under the Command section.

a. System environment:

Ubuntu 20.04 (LTS) x64, systemd

b. Command:

These are the commands I’m running to get the Caddy service into systemd.

sudo sh -c 'curl https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service > /etc/systemd/system/caddy.service'
sudo chmod 644 /etc/systemd/system/caddy.service
sudo systemctl daemon-reload
sudo systemctl status caddy

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

n/a

3. The problem I’m having:

When I run that last command sudo systemctl status caddy, I get an error and cannot proceed.

4. Error messages and/or full log output:

$ sudo systemctl status caddy
● caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: https://caddyserver.com/docs/

Nov 30 23:10:10 ubuntu-s-1vcpu systemd[1]: /etc/systemd/system/caddy.service:1: Assignment outside of section. Ignoring.
Nov 30 23:10:10 ubuntu-s-1vcpu systemd[1]: caddy.service: Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.
Nov 30 23:14:42 ubuntu-s-1vcpu systemd[1]: /etc/systemd/system/caddy.service:1: Assignment outside of section. Ignoring.
Nov 30 23:23:17 ubuntu-s-1vcpu systemd[1]: /etc/systemd/system/caddy.service:1: Assignment outside of section. Ignoring.
Nov 30 23:23:17 ubuntu-s-1vcpu systemd[1]: caddy.service: Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.
Nov 30 23:23:22 ubuntu-s-1vcpu systemd[1]: /etc/systemd/system/caddy.service:1: Assignment outside of section. Ignoring.

5. What I already tried:

googling the error and trying different things

6. Links to relevant resources:

I am using this DO tutorial, but had a adapt it quite a bit as it is old and built for Caddy 1. How To Host a Website with Caddy on Ubuntu 18.04 | DigitalOcean

I haven’t looked into why your setup is failing, but is there a reason you didn’t just follow our official instructions? We work hard to make our documentation good. I suspect just scrapping what you have so far and following the official instructions rather than a random tutorial on the Internet will get you to a solution faster. :slight_smile:

Since you’re on DigitalOcean anyway, you could just use our one-click image: https://marketplace.digitalocean.com/apps/caddy

1 Like

Thank you for the reply. I was simply following the one on DO because I assumed there would be stuff that was specific to DO that I would need to follow.

So I went through the instructions at the link you provided. I got to the line systemctl status caddy and then got the following error:

● caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2020-12-01 21:07:00 UTC; 1h 10min ago
       Docs: https://caddyserver.com/docs/
    Process: 131997 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=217/USER)
   Main PID: 131997 (code=exited, status=217/USER)

Is there a log somewhere that would show more details about the error?

I would like to do this manually as opposed to the prebuilt image just so I can learn more about how it works behind the scenes. But if I can’t get that to work, I will try the prebuilt image.

Thanks!

It means the caddy user doesn’t exist.

If you were to install Caddy with the debian package, that would be done for you:

You’ll need to make sure to undo everything you’ve done so far, first, before installing that way.

Doesn’t the previously linked instructions have the user ‘caddy’ get added?

sudo useradd --system \
    --gid caddy \
    --create-home \
    --home-dir /var/lib/caddy \
    --shell /usr/sbin/nologin \
    --comment "Caddy web server" \
    caddy

So I tried the method at that link and got:

caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2020-12-01 23:11:34 UTC; 6s ago
       Docs: https://caddyserver.com/docs/
    Process: 2178 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
   Main PID: 2178 (code=exited, status=1/FAILURE)

And now when I tried to go back and do the way from those instructions, I am getting the same ‘status=1/FAILURE’. What would be causing that?

Did you do this on a fresh OS? If not, you need to be careful and know what you’re doing if you’re going to be replacing or undoing previous actions. We don’t know what steps you took exactly, so only you can do that correctly; otherwise just start with a fresh OS. This is the sysadmin life… heh.

If it is a Caddy issue, you’ll see some logs and an error message. Otherwise, it’s a system misconfiguration.

Honestly if I was you I’d just use the marketplace droplet. It’s all set up for you.

1 Like

OK, so I re-imaged the droplet with a fresh Ubuntu 20 image. I downloaded xcaddy, figured out how to get it in my path, then build caddy. Then I moved caddy to /usr/bin. Verified it works with caddy version. Added the group and added the user using the given commands in the tut. Downloaded caddy.service and put it in /etc/systemd/system/caddy.service. Created the directory /etc/caddy and added an empty CaddyFile to that folder.

Then I ran
sudo systemctl daemon-reload
sudo systemctl enable caddy
sudo systemctl start caddy
And when I run systemctl status caddy I get:

● caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2020-12-02 17:51:53 UTC; 18min ago
       Docs: https://caddyserver.com/docs/
    Process: 5342 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
   Main PID: 5342 (code=exited, status=1/FAILURE)
● caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2020-12-02 17:51:53 UTC; 18min ago
       Docs: https://caddyserver.com/docs/
    Process: 5342 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
   Main PID: 5342 (code=exited, status=1/FAILURE)

Sorry for all the issues! I’m learning a ton about linux and the terminal and Caddy, so this is good for me. I think I’m close.

I contacted DO about how to apply a droplet image to an existing droplet, they didn’t provide a helpful response. It seems to me like you can only create a new droplet with that image, not apply it to an existing one.

1 Like

Did you follow the install instructions exactly? xcaddy is not part of them. That’s only for custom caddy builds, usually for plugin developers. If you’re plugging some unknown code into Caddy that could potentially cause problems. Do the logs say anything? What if you try running Caddy manually? (Make sure to run as the caddy user)

Alright, figured it out!! I commented out the --config /etc/caddy/Caddyfile section in the caddy.service file and it worked beautifully. So I am assuming my empty CaddyFile was causing the issue.

Is there any way to allow it to work with an empty CaddyFile? Or is there a way to show an explicit error to the user CaddyFile is empty, please fix! or something along those lines?

I marked your first reply as the answer as the rest of the replies were different issues.

Thank you for all your help!!

1 Like

Why do you have an empty Caddyfile? What are you trying to do? It doesn’t make sense to run Caddy without a config.

I’m simply trying to see if I can get Caddy running on my server. I haven’t started playing around with the configuration of it yet. I just wanted to get it working first.

The digitalocean droplet (and by proxy the .deb package) ships with a default working Caddyfile. Why is yours empty?

I wasn’t able to figure out how to use the Caddy image on my droplet, so I’m doing it all from scratch.

What we were trying to say is if you followed the given instructions, e.g. using the official Caddy droplet:

https://marketplace.digitalocean.com/apps/caddy

Or the debian package we provide:

You wouldn’t have had any of these issues.

Thank you, that makes sense. Like I said earlier, I couldn’t figure out how to apply the image to an existing droplet. It seemed to only want to create a new droplet. And I wanted to learn as much as I could about the process too.

But I’m just wondering about people not using Digital Ocean but following the installation instructions on their server. Is that not a normal occurrence that someone would try and get Caddy running first before loading in a configuration?

Yes, and that’s what the package installation is for:

It sets up a working Caddy, with a default configuration that says “yay, you did it!”, just like apache and nginx do as well.

The DO droplet is basically just a machine image, with that already done for you.

Glad you got it working!

Ah yep, an empty Caddyfile is an error. (Instead, just run Caddy without a config. If you say “run this config” but it’s empty, that’s an error.)

Is there any way to allow it to work with an empty CaddyFile? Or is there a way to show an explicit error to the user CaddyFile is empty, please fix! or something along those lines?

Yes, exactly.

Caddy outputs an error in this case, and systemd probably has them in its logs somewhere, you just have to find them… which I’m not really good at.

FWIW this is what it looks like when you run Caddy pointing to an empty file:

$ caddy run --config Caddyfile
2020/12/02 21:41:17.961	INFO	using provided configuration	{"config_file": "Caddyfile", "config_adapter": ""}
run: adapting config using caddyfile: EOF
1 Like

Thanks again for all your help guys! And sorry for being such a pain in the butt! I’m liking what I’m seeing of Caddy so far and excited to dive in even deeper. Also glad I didn’t have to resort back to nginx! :slight_smile:

2 Likes

in my relatively limited experience, journalctl -u caddy -e -n 50 would give you enough context to work with.
journalctl = parse system log journal
-u caddy = filter by user ‘caddy’
-e = begin reading from end of file (show most recent logs first)
-n 50 = read 50 lines
I documented some other useful tips here. https://bytes.eiphax.tech

1 Like