#!/sbin/openrc-run

name="Gitlab Container Registry"
supervisor=supervise-daemon

cfgfile=${cfgfile:-"/etc/gitlab-registry/config.yml"}
command_user=${command_user:-"gitlab-registry:gitlab-registry"}

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

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

logfile=/var/log/gitlab-registry.log
supervise_daemon_args="-1 $logfile -2 $logfile"

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
}
