#!/bin/sh

# PROVIDE: backrest
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Configuration settings for backrest in /etc/rc.conf
#
# backrest_enable (bool):     Enable backrest. (Default=NO)
# backrest_env_file (str):    Path containing the environment variables
#                             to be used by backrest. (Default: /usr/local/etc/backrest/config.env)
# backrest_logfile (str):     Log file used to store the backrest's output. (Default: /var/log/backrest.log)
# backrest_pidfile (str):     File used by backrest to store the process ID. (Default: /var/run/backrest.pid)
# backrest_runas (str):       User to run backrest as. (Default: www)

. /etc/rc.subr

name="backrest"
desc="Web UI and orchestrator for restic backup"
rcvar="backrest_enable"

load_rc_config $name

: ${backrest_enable:="NO"}
: ${backrest_env_file:="/usr/local/etc/backrest/config.env"}
: ${backrest_logfile:="/var/log/backrest.log"}
: ${backrest_pidfile:="/var/run/backrest.pid"}
: ${backrest_runas:="www"}

pidfile="${backrest_pidfile}"
procname="/usr/local/bin/backrest"
command="/usr/sbin/daemon"
command_args="-o '${backrest_logfile}' -p '${pidfile}' -u '${backrest_runas}' -t '${desc}' -- '${procname}'"

run_rc_command "$1"
