Hello
I need to run Caddy on Linux as a daemon. I am not interested in creating a systemd unit file or other dependencies.
Just launching Caddy, and let it run as a daemon (until killed/stopped) by itself.
Apparently, this should be a basic use case with a simple answer, but it turns out not to be so simple.
There are two general commands to run the web server.
-
The first one,
caddy run
, is described to “Start the Caddy process in the foreground”, which is the opposite of what we want. -
The second,
caddy start
was apparently the desired one to “run caddy and forget”, as it is described as the same as caddy run but in the background.
However, I have found the problematic situation that the background process of caddy start
keeps open stdout and stderr to the terminal (on v2.7.6). This is poorly documented, with caddy start only mentioning that “On Windows, the child process will remain attached to the terminal”, with no mention about limitations on *nix systems.
Still, we can find a more restrictive description on the source code at caddy/cmd/cobra.go at master · caddyserver/caddy · GitHub
‘caddy start’ to start Caddy in the background; only do this if you will be keeping the terminal window open until you run ‘caddy stop’ to close the server.
but I do want to be able to close the terminal, so it doesn’t fit either.
Seemingly available options would be to run nohup caddy run
or caddy start > /dev/null 2>&1
, but they do not look like the “right” solution (albeit maybe they are?).
I would expect caddy start
(maybe with some parameter) to run on background, with the parent writing the messages that it spawned the child (which the above solutions would miss), and exiting, while the child would daemonize itself closing stdout and stderr / opening /dev/null on those descriptors (stdin seems to be replaced by a socket, already).
Thus, what would be the preferred way to launch caddy directly in a terminal-to-be-closed ?
Thanks
PS: links to caddyserver.com shouldn’t count against the limit of 4 links in a post for new users