It would be useful to have a 'reload' function in the init.d script. Reproducible: Always I think that the config file should be moved to its own variable to make a reload function work. caddy reload --config "${config_file}"
I added it in PR. Anyone with openrc please try it out and report back if it is working as intended.
(In reply to Rahil Bhimjiani from comment #1) > I added it in PR. Anyone with openrc please try it out and report back if it > is working as intended. Thanks. I made some adjustments. What do you think? # diff -u initd-2.7.5.1 initd-2.7.5.2 --- initd-2.7.5.1 2023-10-14 21:34:21.666613022 +0200 +++ initd-2.7.5.2 2023-10-14 22:01:16.583562342 +0200 @@ -1,13 +1,15 @@ #!/sbin/openrc-run +# shellcheck shell=bash description="Caddy web server" pidfile=${pidfile:-"/run/${RC_SVCNAME}.pid"} command="/usr/bin/caddy" command_user="${command_user:-"http:http"}" -caddy_config="/etc/caddy/Caddyfile" +caddy_config="${caddy_config:-"/etc/caddy/Caddyfile"}" command_args="${command_args:-"run --config ${caddy_config}"}" command_background="true" -logfile=/var/log/${RC_SVCNAME}/${RC_SVCNAME}.log +extra_started_commands="reload" +logfile="${logfile:-"/var/log/${RC_SVCNAME}/${RC_SVCNAME}.log"}" start_stop_daemon_args="--user ${command_user%:*} --group ${command_user#*:} --stdout ${logfile} --stderr ${logfile}"
Oops. Totally missed that caddy_config bug. Thanks for pointing out. Is providing logfile in conf.d a common practice? and can you elaborate on what does "extra_started_commands" do? I'm on phone so cand dig into openrc efficiently now
(In reply to Rahil Bhimjiani from comment #3) > Oops. Totally missed that caddy_config bug. Thanks for pointing out. Is > providing logfile in conf.d a common practice? I don't know if it is best practice or not. Personally I wanted to set the logfile to the same directory as I keep other caddy per-domain access logs. > > and can you elaborate on what does "extra_started_commands" do? I'm on phone > so cand dig into openrc efficiently now extra_started_commands specifies what extra functions() that are defined. In this case we want extra_started_commands="reload" so that the reload function becomes available.
Done. Mimicked the behaviour from openssh's initd. Forza, recheck the PR and field-test it please.
(In reply to Rahil Bhimjiani from comment #5) > Done. Mimicked the behaviour from openssh's initd. Forza, recheck the PR and > field-test it please. Looks good. I like that you added checkconfig. I do get tge following outout on the console when running it: rc-service caddy reload {"level":"warn","ts":1697358267.8459482,"msg":"unable to determine directory for user configuration; falling back to current directory","error":"neither $XDG_CONFIG_HOME nor $HOME are defined"} {"level":"info","ts":1697358267.8470907,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""} {"level":"info","ts":1697358267.8813837,"msg":"redirected default logger","from":"stderr","to":"/var/log/caddy/caddy_main.log"} * Reloading caddy ... 2023/10/15 08:24:27.941 WARN unable to determine directory for user configuration; falling back to current directory {"error": "neither $XDG_CONFIG_HOME nor $HOME are defined"} 2023/10/15 08:24:27.942 INFO using provided configuration {"config_file": "/etc/caddy/Caddyfile", "config_adapter": ""} [ ok ] In conf.d, I think that caddy_config should be above command_args, so that the variable is set before used in command_args?
I realise that the warning about $HOME isn't new. But maybe we should silence it with "2>&1 >/dev/null" ?
> In conf.d, I think that caddy_config should be above command_args, so that the variable is set before used in command_args? It's all commented out but fixed it anyway. > But maybe we should silence it with "2>&1 >/dev/null" ? I tried `caddy reload` & `caddy validate` with `> /dev/null` but it doesn't totally suppress it. If you find a way let me know.
Also added an error when checkconfig fails
This should work: checkconfig() { if [ ! -f "${caddy_config}" ] ; then ewarn "${caddy_config} does not exist." return 1 fi "${command}" validate --config "${caddy_config}" >> "${logfile}" 2>&1 } ... reload() { if ! service_started "${SVCNAME}" ; then eerror "${SVCNAME} isn't running" return 1 fi checkconfig || return 1 ebegin "Reloading ${SVCNAME}" "${command}" reload --force --config "${caddy_config}" >> "${logfile}" 2>&1 eend $? } Instead of ">> ${logfile} 2>&1" you can also do "> /dev/null 2>&1"
Improved. It should work now as you wanted, Forza.
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=dcf6809eba95a9070a2768f60e1ba5f5a448d994 commit dcf6809eba95a9070a2768f60e1ba5f5a448d994 Author: Rahil Bhimjiani <rahil3108@gmail.com> AuthorDate: 2023-10-12 06:10:49 +0000 Commit: Zac Medico <zmedico@gentoo.org> CommitDate: 2023-10-30 02:07:51 +0000 www-servers/caddy: add 2.7.5 & update live 1. split out LICENSE 2. Install Caddyfile as upstream intended. 3. show correct version on `caddy version` 4. misc improvements in initd & confd like validate config file, reload, add variables for config file & logfile Closes: https://bugs.gentoo.org/915687 Signed-off-by: Rahil Bhimjiani <rahil3108@gmail.com> Signed-off-by: Zac Medico <zmedico@gentoo.org> www-servers/caddy/Manifest | 3 + www-servers/caddy/caddy-2.7.5.ebuild | 98 ++++++++++++++++++++++ www-servers/caddy/caddy-9999.ebuild | 28 +++++-- www-servers/caddy/files/confd-2.7.5 | 5 ++ www-servers/caddy/files/initd-2.7.5 | 53 ++++++++++++ .../remove-binary-altering-commands-2.7.5.patch | 61 ++++++++++++++ 6 files changed, 240 insertions(+), 8 deletions(-)