#!/sbin/openrc-run
description="Sync server for shell history"

: ${command_user:="atuin:atuin"}
: ${output_log="/var/log/atuin-server.log"}
: ${error_log="/var/log/atuin-server.log"}
: ${cfgdir:="/etc/atuin"}
: ${loglevel:="WARN"}

command="/usr/bin/atuin-server"
command_args="server start $command_args"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

required_files="$cfgdir/server.toml"

depend() {
	need net
	use postgresql
}

start_pre() {
	export ATUIN_CONFIG_DIR="$cfgdir"
	export RUST_LOG="$loglevel"

	if [ "$output_log" ]; then
		checkpath -f -o "$command_user" -m 640 -q "$output_log" || return 1
	fi
	if [ "$error_log" ]; then
		checkpath -f -o "$command_user" -m 640 -q "$error_log" || return 1
	fi
}
