summaryrefslogtreecommitdiff
blob: c77984ef92bc26d8621551990c26135009378476 (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
64
65
66
67
68
69
70
71
72
73
#!/sbin/runscript
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-admin/syslog-ng/files/syslog-ng.rc6.3.3,v 1.2 2011/10/19 06:19:38 mr_bones_ Exp $

extra_commands="checkconfig"
extra_started_commands="reload"

description_checkconfig="Check the configuration file that will be used by \"start\""
description_reload="Reload the configuration without exiting"

SYSLOG_NG_SERVICE=${SVCNAME#*.}
SYSLOG_NG_SERVICE=${SYSLOG_NG_SERVICE:-syslog-ng}

SYSLOG_NG_CONFIGFILE=${SYSLOG_NG_CONFIGFILE:-/etc/syslog-ng/${SYSLOG_NG_SERVICE}.conf}
SYSLOG_NG_PIDFILE=${SYSLOG_NG_PIDFILE:-/var/run/${SVCNAME}.pid}
SYSLOG_NG_OPTS="--cfgfile ${SYSLOG_NG_CONFIGFILE} --pidfile ${SYSLOG_NG_PIDFILE} ${SYSLOG_NG_OPTS}"

depend() {
	# Make networking dependency conditional on configuration
	if [ -f "${SYSLOG_NG_CONFIGFILE}" ]; then
		case `sed 's/#.*//' "${SYSLOG_NG_CONFIGFILE}"` in
			*source*tcp*|*source*udp*|*destination*tcp*|*destination*udp*)
				need net
				use stunnel ;;
		esac
	fi

	config "${SYSLOG_NG_CONFIGFILE}"
	use clock
	need hostname localmount
	provide logger
}

checkconfig() {
	if [ ! -e "${SYSLOG_NG_CONFIGFILE}" ] ; then
		eerror "You need to create ${SYSLOG_NG_CONFIGFILE} first."
		eerror "An example can be found in /usr/share/doc/syslog"

		return 1
	fi
	syslog-ng -s -f "${SYSLOG_NG_CONFIGFILE}"

	# the start and reload functions have their own eends so
	# avoid calling this twice when there are no problems
	[ $? -eq 0 ] || eend $? "Configuration error. Please fix your configfile (${SYSLOG_NG_CONFIGFILE})"
}

start() {
	checkconfig || return 1
	ebegin "Starting ${SVCNAME}"
	[ -n "${SYSLOG_NG_OPTS}" ] && SYSLOG_NG_OPTS="-- ${SYSLOG_NG_OPTS}"
	start-stop-daemon --start --pidfile "${SYSLOG_NG_PIDFILE}" --exec /usr/sbin/syslog-ng ${SYSLOG_NG_OPTS}
	eend $? "Failed to start ${SVCNAME}"
}

stop() {
	ebegin "Stopping ${SVCNAME}"
	start-stop-daemon --stop --pidfile "${SYSLOG_NG_PIDFILE}"
	eend $? "Failed to stop ${SVCNAME}"
	sleep 1 # needed for syslog-ng to stop in case we're restarting
}

reload() {
	if [ ! -f "${SYSLOG_NG_PIDFILE}" ]; then
		eerror "${SVCNAME} isn't running"
		return 1
	fi
	checkconfig || return 1
	ebegin "Reloading configuration and re-opening log files"
	start-stop-daemon --signal HUP --pidfile "${SYSLOG_NG_PIDFILE}"
	eend $?
}