From: Fabien Wernli Date: Thu, 11 Apr 2013 08:43:29 +0000 (+0200) Subject: allow for non-root user to run script. X-Git-Tag: collectd-5.4.0~34 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8a533ce6a4f030b8b5c505b649e232f1354dc24f;p=collectd.git allow for non-root user to run script. As collectdmon handles its pidfile, this would require to change COLLECTMONPIDIR to something else than only-root writeable /var/run Change-Id: I45d2de9dcc976f3b1e18cef5b6b78eeca1d270b2 Signed-off-by: Florian Forster --- diff --git a/contrib/redhat/init.d-collectd b/contrib/redhat/init.d-collectd index ec55a52a..52bf7433 100644 --- a/contrib/redhat/init.d-collectd +++ b/contrib/redhat/init.d-collectd @@ -18,12 +18,18 @@ prog="collectdmon" service="collectd" CONFIG=/etc/collectd.conf COLLECTD=/usr/sbin/collectd -COLLECTDMONPID=/var/run/collectdmon.pid +COLLECTDMONPIDIR="/var/run" +COLLECTDMONPID="$COLLECTDMONPIDIR/collectdmon.pid" if [ -r /etc/sysconfig/$service ]; then . /etc/sysconfig/$service fi +if [ ! -d $COLLECTDMONPIDIR ]; then + mkdir -p $COLLECTDMONPIDIR + [ -n "${RUNAS-}" ] && chown $RUNAS: $COLLECTDMONPIDIR +fi + check_config() { if test ! -r "$CONFIG"; then return 2 @@ -44,7 +50,7 @@ start () { echo $"not starting due to configuration error" failure $"not starting $service due to configuration error" else - daemon $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" $ARGS + daemon --user "${RUNAS-root}" $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" $ARGS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$service @@ -52,7 +58,7 @@ start () { } stop () { echo -n $"Stopping collectd: " - killproc $prog + killproc -p $COLLECTDMONPID $prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$service @@ -66,7 +72,7 @@ case "$1" in stop ;; status) - status $prog + status -p $COLLECTDMONPID $prog ;; restart|reload) check_config @@ -81,7 +87,7 @@ case "$1" in fi ;; condrestart) - [ -f /var/lock/subsys/$prog ] && restart || : + [ -f /var/lock/subsys/$service ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"