#!/sbin/openrc-run

description="git-pages static site server"

: ${cfgfile:="/etc/git-pages/config.toml"}
: ${datadir:="/var/lib/git-pages"}
: ${command_user:="git-pages"}

command="/usr/bin/git-pages"
command_args="-config $cfgfile"
command_background="yes"
directory="$datadir"
pidfile="/run/$RC_SVCNAME.pid"

depend() {
    need net
    use dns logger
}

start_pre() {
    checkpath -d -o "$command_user" /etc/git-pages
    checkpath -d -o "$command_user" "$datadir"

    if ! [ -e "$cfgfile" ]; then
        eerror "Config file $cfgfile doesn't exist."
	eerror "You can check /etc/git-pages/config.default.toml for default values,"
	eerror "and /etc/git-pages/config.example.toml for a configuration example."
        return 1
    fi

    if [ "$error_log" ]; then
        output_log="$error_log"
    else
        output_logger="logger -t '${RC_SVCNAME}' -p daemon.info"
        error_logger="logger -t '${RC_SVCNAME}' -p daemon.error"
    fi
}
