Skip to content

Instantly share code, notes, and snippets.

@magkopian
Last active November 7, 2015 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magkopian/7238b974f6a1a17973d5 to your computer and use it in GitHub Desktop.
Save magkopian/7238b974f6a1a17973d5 to your computer and use it in GitHub Desktop.
Patch that makes the newrelic-daemon to run as the user newrelic-php instead of root. It works only on Debian or Debian based distros. You can find more information on the following link https://discuss.newrelic.com/t/daemon-running-as-root/16651/7.
--- original/etc/init.d/newrelic-daemon 2015-11-07 18:52:55.441693757 +0200
+++ edited/etc/init.d/newrelic-daemon 2015-11-07 20:13:17.994378592 +0200
@@ -16,6 +16,7 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
LABEL=newrelic-daemon
NAME=newrelic-daemon
+USER=newrelic-php
DESC="New Relic Daemon"
id=`id -u 2> /dev/null`
@@ -82,9 +83,13 @@
pidarg=
if [ -z "${pidfile}" ]; then
if [ -d /var/run ]; then
- pidfile=/var/run/newrelic-daemon.pid
+ mkdir -p /var/run/$USER
+ chown $USER:$USER /var/run/$USER
+ pidfile=/var/run/$USER/newrelic-daemon.pid
elif [ -d /var/pid ]; then
- pidfile=/var/pid/newrelic-daemon.pid
+ mkdir -p /var/pid/$USER
+ chown $USER:$USER /var/pid/$USER
+ pidfile=/var/pid/$USER/newrelic-daemon.pid
fi
if [ -n "${pidfile}" ]; then
pidarg=" --pidfile ${pidfile}"
@@ -208,7 +213,7 @@
fi
RETVAL=0
- "${nrdaemon}" ${nrdaemonopts} || RETVAL=1
+ start-stop-daemon --oknodo --start --name $NAME --chuid $USER --pidfile $pidfile --exec $nrdaemon -- $nrdaemonopts || RETVAL=1
sleep 1
if [ "x${RETVAL}" = "x0" ]; then
if running ; then
@@ -229,8 +234,8 @@
if [ -z "${NR_SILENT}" -a -z "${SILENT}" ]; then
log_begin_msg "Stopping $DESC: $NAME"
fi
- force_stop
- RETVAL=$?
+ RETVAL=0
+ start-stop-daemon --oknodo --stop --name $NAME --pidfile $pidfile --retry=TERM/30/KILL/5 || RETVAL=1
if [ -z "${NR_SILENT}" -a -z "${SILENT}" ]; then
log_end_msg $RETVAL
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment