#!/sbin/openrc-run

name="Docker Registry"

# $conffile, $user and $group are deprecated since Alpine v3.17.
: ${cfgfile:=${conffile:-"/etc/docker-registry/config.yml"}}
: ${command_user:=${user:-"docker-registry"}:${group:-${user:-"docker-registry"}}}

: ${healthcheck_url="http://127.0.0.1:5001/debug/health"}
: ${healthcheck_timer=5}

command="/usr/bin/docker-registry"
command_args="serve $cfgfile"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

required_files="$cfgfile"

depend() {
	need localmount net
	use dns
}

start_pre() {
	if [ "$logfile" ]; then
		error_log="$logfile"
		checkpath -f -m 0644 -o "$command_user" "$logfile" || return 1
	fi
}

healthcheck() {
	[ "$healthcheck_url" ] || return 0
	wget -q -O - "$healthcheck_url" >/dev/null 2>&1
}
