aboutsummaryrefslogtreecommitdiffstats
path: root/main/quassel/quasselcore.initd
blob: 8a0ccbb778f9e4988646f37ca213966b80af41d7 (plain)
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
#!/sbin/openrc-run
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-irc/quassel/files/quasselcore.init,v 1.8 2011/08/19 11:43:49 scarabeus Exp $

depend() {
	need localmount net
	after bootmisc postgres
}

CORE="$(which quasselcore)"
PID="/run/quassel.pid"
LOGFILE=${LOGFILE:-"/var/log/quassel.log"}
CONFIGDIR=${CONFIGDIR:-"/var/lib/quassel"}
QUASSEL_USER=${QUASSEL_USER:-"quassel"}

checkconfig() {
	# set defaults
	LOGLEVEL=${LOGLEVEL:-"Info"}

	# check config folder
	if [ ! -d "${CONFIGDIR}" ]; then
		mkdir "${CONFIGDIR}" || return 1
	fi
	# permissions always changed just to avoid runtime issues
	chown -R "${QUASSEL_USER}":"${QUASSEL_USER}" "${CONFIGDIR}" || return 1

	# check log file
	if [ ! -e "${LOGFILE}" ]; then
		touch "${LOGFILE}" || return 1
	fi
	# permissions always changed just to avoid runtime issues
	chown "${QUASSEL_USER}":"${QUASSEL_USER}" "${LOGFILE}" || return 1
}

start() {
	checkconfig || return 1

	ebegin "Starting Quassel Core"

	if [ -n "${RC_UNAME}" ]; then
		# running on baselayout-2/openrc
		start-stop-daemon --start --user "${QUASSEL_USER}" --background --make-pidfile \
		--pidfile "${PID}" \
		--exec "${CORE}" -- --logfile="${LOGFILE}" --loglevel="${LOGLEVEL}" \
		${LISTEN:+--listen="${LISTEN}"} ${PORT:+--port="${PORT}"} \
		--configdir="${CONFIGDIR}"
	else
		# running on baselayout-1
		start-stop-daemon --start --chuid "${QUASSEL_USER}" --background --make-pidfile \
		--pidfile "${PID}" --env HOME="${CONFIGDIR}" \
		--exec "${CORE}" -- --logfile="${LOGFILE}" --loglevel="${LOGLEVEL}" \
		${LISTEN:+--listen="${LISTEN}"} ${PORT:+--port="${PORT}"} \
		--configdir="${CONFIGDIR}"
	fi
	eend $?
}

stop() {
	ebegin "Stopping Quassel Core"
	start-stop-daemon --stop --pidfile "${PID}" --exec "${CORE}"
	eend $?
}