#!/sbin/openrc-run
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

: ${INSPIRCD_USER:="inspircd"}
: ${INSPIRCD_GROUP:="inspircd"}
: ${INSPIRCD_CONFIGFILE:="/etc/inspircd/inspircd.conf"}
: ${INSPIRCD_PIDFILE:="/run/inspircd/inspircd.pid"}
: ${INSPIRCD_SSDARGS:="--quiet --wait 1000"}
: ${INSPIRCD_TERMTIMEOUT:="TERM/25/KILL/5"}
: ${INSPIRCD_OPTS:=""}

command="/usr/bin/inspircd"
command_args="${INSPIRCD_OPTS} --config \"${INSPIRCD_CONFIGFILE}\""
command_user="${INSPIRCD_USER}"
start_stop_daemon_args="${INSPIRCD_SSDARGS}"
pidfile="${INSPIRCD_PIDFILE}"
retry="${INSPIRCD_TERMTIMEOUT}"

required_files="${INSPIRCD_CONFIGFILE}"

name="InspIRCd"

description="InspIRCd is a modular Internet Relay Chat (IRC) server."

extra_commands="version"
extra_started_commands="rehash"

depend() {
	use dns
	provide ircd
}

start_pre() {
	checkpath --directory --mode 0750 --owner ${INSPIRCD_USER}:${INSPIRCD_GROUP} "$(dirname "${INSPIRCD_PIDFILE}")"
}

rehash() {
	ebegin "Rehashing InspIRCd"
	start-stop-daemon --signal HUP --pidfile "${pidfile}"
	eend $?
}

version() {
	ebegin "Retrieve InspIRCd version"
	${command} --version
	eend $?
}
