#!/sbin/openrc-run

supervisor=supervise-daemon

name="GitLab (mailroom)"
description="GitLab service for processing incoming mails."

: ${gitlab_base:="/usr/lib/bundles/gitlab"}
: ${gitlab_config:="/etc/gitlab/gitlab.yml"}
: ${mailroom_logfile:="/var/log/gitlab/mail_room.log"}
: ${mailroom_config:="$gitlab_base/config/mail_room.yml"}

command="$gitlab_base/bin/mail_room"
command_args="-c $mailroom_config"
command_background="yes"
command_user="git"

directory="$gitlab_base"
error_log="$mailroom_logfile"
output_log="$mailroom_logfile"

supervise_daemon_args="
	--env RAILS_ENV=production
	--env TZ=:/etc/localtime
	--env MAIL_ROOM_GITLAB_CONFIG_FILE=$gitlab_config
	"
start_stop_daemon_args="--interpreted $supervise_daemon_args"
pidfile="/run/gitlab/mail_room.pid"

required_files="$mailroom_config $gitlab_config"

depend() {
	need redis
	use net
}

start_pre() {
	checkpath -d -m 755 -o $command_user -q "${pidfile%/*}" || return 1
	checkpath -f -m 640 -o $command_user "$mailroom_logfile"
}
