#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: ipfs_go
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown

# ipfs_go_enable (bool):         Set to NO by default
#                                Set to YES to enable ipfs_go
# ipfs_go_user (str):            Set to ipfs-go by default
#                                Set it to ipfs_go daemon user
# ipfs_go_group (str):           Set to ipfs-go by default
#                                Set it to ipfs_go daemon group
# ipfs_go_path (str): 	         Set to /var/db/ipfs-go/.ipfs by default
#                                Set it to ipfs repo path
# ipfs_go_syslog_priority (str): Set to "info" by default.
#                                Set it to priority to be used by syslog
# ipfs_go_syslog_facility (str): Set to "daemon" by default.
#                                Set it to facility to be used by syslog
# ipfs_go_syslog_tag (str):      Set to "ipfs-go" by default.
#                                Set it to tag to be used by syslog

. /etc/rc.subr

name=ipfs_go
rcvar=ipfs_go_enable
load_rc_config $name

: ${ipfs_go_enable:="NO"}
: ${ipfs_go_user:="ipfs-go"}
: ${ipfs_go_group:="ipfs-go"}
: ${ipfs_go_path:="/var/db/ipfs-go/.ipfs"}
: ${ipfs_go_syslog_priority:="info"}
: ${ipfs_go_syslog_facility:="daemon"}
: ${ipfs_go_syslog_tag:="ipfs-go"}

pidfile="/var/run/${name}.pid"

command="/usr/sbin/daemon"
command_args="-S -m 3 -s ${ipfs_go_syslog_priority} -l ${ipfs_go_syslog_facility} -T ${ipfs_go_syslog_tag} -p ${pidfile} /usr/bin/env IPFS_PATH=${ipfs_go_path} ${ipfs_go_env} /usr/local/bin/ipfs-go daemon --init --init-profile=server --migrate=true ${ipfs_go_args}"
procname="/usr/local/bin/ipfs-go"

start_precmd="ipfs_go_startprecmd"

ipfs_go_startprecmd() {
  if [ ! -e "${pidfile}" ]; then
    install -g ${ipfs_go_group} -o ${ipfs_go_user} -- /dev/null "${pidfile}"
  fi
}

run_rc_command "$1"
