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.
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.
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.
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.
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.
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.
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.
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?
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.
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!
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