From 654aa459549e99f38cc98f9ec32ea732ae77be7b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 17 Dec 2010 23:09:20 +0100 Subject: znc: separate scripts for every znc instance --- znc/init.d/znc | 111 +++++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 59 deletions(-) (limited to 'znc/init.d') diff --git a/znc/init.d/znc b/znc/init.d/znc index eaca712..3ce3e1a 100755 --- a/znc/init.d/znc +++ b/znc/init.d/znc @@ -7,91 +7,84 @@ opts="checkconfig reload" ZNC_USER=${ZNC_USER:-"nobody"} ZNC_DAEMON=${ZNC_DAEMON:-"/usr/bin/znc"} +ZNC_EXTRA_ARGS="" depend() { need net use oidentd + provide znc } checkconfig() { - if [ -z "${ZNC_DATADIR}" ]; then - eerror "Please set at least one datadir for ZNC!" - return 1 + 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 - mkdir -p /var/run/znc/ - if [ ! -d /var/run/znc ]; then - eerror "Unable to create /var/run/znc!" + 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" - eindent - - for dir in ${ZNC_DATADIR}; do - if [ -d "${dir}" ]; then - ebegin "${dir}" - - pidfile=$(mktemp --tmpdir=/var/run/znc) - start-stop-daemon --start --quiet \ - --chuid ${ZNC_USER} \ - --exec ${ZNC_DAEMON} \ - --pidfile ${pidfile} \ - --make-pidfile --background \ - --chdir ${dir} --wait 500 \ - -- -d ${dir} -f - - eend $? - fi - done + ebegin "Starting ZNC: ${ZNC_DATADIR}" + + pidfile=$(_get_pid_file "${ZNC_DATADIR}") + start-stop-daemon --start --quiet --chuid ${ZNC_USER} --exec ${ZNC_DAEMON} \ + --pidfile ${pidfile} --make-pidfile --background \ + --chdir ${ZNC_DATADIR} --wait 500 -- -d ${ZNC_DATADIR} -f - eoutdent + eend $? } stop() { checkconfig || return 1 - ebegin "Stopping ZNC" - eindent - - for pidfile in /var/run/znc/* ; do - if [ -r ${pidfile} ]; then - pid=$(< ${pidfile}) - - if [ -L /proc/${pid}/cwd ]; then - ebegin $(readlink /proc/${pid}/cwd) + ebegin "Stopping ZNC: ${ZNC_DATADIR}" - start-stop-daemon --stop --user ${ZNC_USER} \ - --exec ${ZNC_DAEMON} \ - --pidfile ${pidfile} + pidfile=$(_get_pid_file "${ZNC_DATADIR}") + start-stop-daemon --stop --user ${ZNC_USER} --exec ${ZNC_DAEMON} \ + --pidfile ${pidfile} - eend $? - fi - fi - done - - eoutdent + eend $? } reload() { - ebegin "Reloading ZNC" - eindent - - for pidfile in /var/run/znc/* ; do - if [ -r ${pidfile} ]; then - pid=$(< ${pidfile}) - - if [ -L /proc/${pid}/cwd ]; then - ebegin $(readlink /proc/${pid}/cwd) - kill -HUP ${pid} - eend $? - fi - fi - done + 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 - eoutdent + eend $? } -- cgit v1.2.3