aboutsummaryrefslogtreecommitdiffstats
path: root/www-servers/caddy-bin/files/caddy.initd
blob: c0112d3263d08ec688fc78e530b2257110647563 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="${RC_SVCNAME}"
extra_commands="configtest"
extra_started_commands="reload"
description_configtest="Run Caddy's internal config check"
description_reload="Reload Caddy configuration"

export CADDYPATH="${CADDYPATH}"
command="caddy"
command_args="${CADDY_OPTS}"
command_user="${command_user:-caddy:http}"
command_background=yes
pidfile="/run/${RC_SVCNAME}.pid"

depend() {
	use net
	after dns
}

start_pre() {
	if [ "${RC_CMD}" != "restart" ]; then
		configtest || return 1
	fi
}

stop_pre() {
	if [ "${RC_CMD}" = "restart" ]; then
		configtest || return 1
	fi
}

reload() {
	configtest || return 1
	ebegin "Refreshing ${name}'s configuration"
	start-stop-daemon --signal USR1 --pidfile "${pidfile}"
	eend $? "Failed to reload ${name}"
}

configtest() {
	ebegin "Checking ${name} configuration"
	if ! ${command} -validate -conf="${CADDY_CONFIG}" >/dev/null 2>&1; then
		${command} -validate -conf="${CADDY_CONFIG}"
	fi
	eend $? "Failed, please correct the errors above"
}