summaryrefslogtreecommitdiffstats
path: root/znc/init.d/znc
diff options
context:
space:
mode:
Diffstat (limited to 'znc/init.d/znc')
-rwxr-xr-xznc/init.d/znc111
1 files changed, 52 insertions, 59 deletions
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 $?
}