#!/sbin/runscript # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License, v2 or later # $Header: $ extra_commands="checkconfig" extra_started_commands="reload" ZNC_USER=${ZNC_USER:-"nobody"} ZNC_DAEMON=${ZNC_DAEMON:-"/usr/bin/znc"} ZNC_EXTRA_ARGS="" depend() { need net use oidentd provide znc } checkconfig() { local instance=${RC_SVCNAME#*.} local instanceVar=$(shell_var "${instance}") if [ -n "$instanceVar" ]; then eval local_datadir=\$ZNC_DATADIR_${instanceVar} if [ -n "${local_datadir}" ]; then ZNC_DATADIR=${local_datadir} fi eval local_user=\$ZNC_USER_${instanceVar} if [ -n "${local_user}" ]; then ZNC_USER=${local_USER} fi eval local_daemon=\$ZNC_DAEMON_${instanceVar} if [ -n "${local_daemon}" ]; then ZNC_DAEMON=${local_daemon} fi fi if [ ! -d "${ZNC_DATADIR}" ]; then eerror "Please set a valid datadir for ZNC!" return 1 fi return 0 } _get_pid_file() { echo "${1}/.pid" } start() { checkconfig || return 1 ebegin "Starting ZNC: ${ZNC_DATADIR}" pidfile=$(_get_pid_file "${ZNC_DATADIR}") start-stop-daemon --start --quiet --user ${ZNC_USER} --exec ${ZNC_DAEMON} \ --pidfile ${pidfile} --make-pidfile --background \ --chdir ${ZNC_DATADIR} --wait 500 -- -d ${ZNC_DATADIR} -f eend $? } stop() { checkconfig || return 1 ebegin "Stopping ZNC: ${ZNC_DATADIR}" pidfile=$(_get_pid_file "${ZNC_DATADIR}") start-stop-daemon --stop --user ${ZNC_USER} --exec ${ZNC_DAEMON} \ --pidfile ${pidfile} eend $? } reload() { checkconfig || return 1 ebegin "Reloading ZNC: ${ZNC_DATADIR}" pidfile=$(_get_pid_file "${ZNC_DATADIR}") if [ -r ${pidfile} ]; then pid=$(< ${pidfile}) kill -HUP ${pid} else eerror "Could not find the ZNC process! (pidfile not present)" fi eend $? }