summaryrefslogblamecommitdiffstats
path: root/eggdrop/init.d/eggdrop
blob: a4d2157f346180bdf9ef855a7a1c5a8108cb6f66 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                            

                   















































































                                                                                                 
#!/sbin/runscript
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: $

opts="checkconfig"

EGGDROP_USER=${EGGDROP_USER:-"nobody"}
EGGDROP_DAEMON=${EGGDROP_DAEMON:-"/opt/eggdrop/eggdrop"}
EGGDROP_EXTRA_ARGS=""

depend() {
	need net
	use oidentd
	provide eggdrop
}

checkconfig() {
	local instance=${RC_SVCNAME#*.}
	local instanceVar=$(shell_var "${instance}")
	
	if [ -n "$instanceVar" ]; then
		eval local_datadir=\$EGGDROP_DATADIR_${instanceVar}

		if [ -n "${local_datadir}" ]; then
			EGGDROP_DATADIR=${local_datadir}
		fi

		eval local_user=\$EGGDROP_USER_${instanceVar}

		if [ -n "${local_user}" ]; then
			EGGDROP_USER=${local_USER}
		fi

		eval local_daemon=\$EGGDROP_DAEMON_${instanceVar}

		if [ -n "${local_daemon}" ]; then
			EGGDROP_DAEMON=${local_daemon}
		fi
	fi

	if [ -n "${instance}" ]; then
		EGGDROP_EXTRA_ARGS="--startas eggdrop(${instance})"
	fi

	if [ ! -d "${EGGDROP_DATADIR}" ]; then
		eerror "Please set a valid datadir for the eggdrop!"
		return 1
	fi

	return 0
}

_get_pid_file() {
	local pid=$(grep "^ *set pidfile" "${1}/eggdrop.conf" | cut -d\" -f2)

	if [ -n "$pid" ]; then
		echo "${1}/$pid"
	else		
		local botnet_nick=$(grep "^ *set botnet-nick" "${1}/eggdrop.conf" | cut -d\" -f2)
	
		if [ -n "${botnet_nick}" ]; then
			echo "${1}/pid.${botnet_nick}"
		else
			local nick=$(grep "^ *set nick" "${1}/eggdrop.conf" | cut -d\" -f2)
			echo "${1}/pid.${nick}"
		fi
	fi
}

start() {
	checkconfig || return 1
	ebegin "Starting Eggdrop: ${EGGDROP_DATADIR}"

	pidfile=$(_get_pid_file "${EGGDROP_DATADIR}")
	start-stop-daemon --start --quiet --chuid ${EGGDROP_USER} \
			  --exec ${EGGDROP_DAEMON} --pidfile ${pidfile} \
			  --chdir ${EGGDROP_DATADIR} --wait 500 \
			  ${EGGDROP_EXTRA_ARGS}

	eend $?
}

stop() {
	checkconfig || return 1
	ebegin "Stopping Eggdrop: ${EGGDROP_DATADIR}"

	pidfile=$(_get_pid_file "${EGGDROP_DATADIR}")
	start-stop-daemon --stop --user ${EGGDROP_USER} \
			  --exec ${EGGDROP_DAEMON} \
	               	  --pidfile ${pidfile}

	eend $?
}