summaryrefslogtreecommitdiffstats
path: root/eggdrop/init.d/eggdrop
blob: a4d2157f346180bdf9ef855a7a1c5a8108cb6f66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/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 $?
}