Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Newrelic-daemon init script bug



I’ve been pulling my hair out trying to debug why newrelic-daemon refused to start (and without any log info). It turns out the init script incorrectly detected that newrelic-daemon was running (it was not). This is due to the following line:

maybepid=ps -ef | grep '/newrelic-daemon ' | sed -e '/grep/d' | awk '{if ($3 == 1) {print $2;}}'

This line incorrectly gets the pid of the init script, and not of newrelic-daemon itself. When I echo out the result of ps -ef | grep '/newrelic-daemon ', I get:

Nov 01 21:58:55 ip-10-0-1-167.ec2.internal newrelic-daemon[21109]: root 21075 21067 0 21:58 pts/0 00:00:00 /bin/sh /etc/init.d/newrelic-daemon restart
Nov 01 21:58:55 ip-10-0-1-167.ec2.internal newrelic-daemon[21109]: root 21109 1 0 21:58 ? 00:00:00 /bin/sh /etc/rc.d/init.d/newrelic-daemon start
Nov 01 21:58:55 ip-10-0-1-167.ec2.internal newrelic-daemon[21109]: root 21119 21109 0 21:58 ? 00:00:00 /bin/sh /etc/rc.d/init.d/newrelic-daemon start

…and the “pid” returned is 21109.
As you can see, this will not work. Simply changing that line to:

maybepid=ps -ef | grep '/newrelic-daemon ' | grep -v init | sed -e '/grep/d' | awk '{if ($3 == 1) {print $2;}}'

did the trick.

FYI, I am using CentOS 7 (i.e. systemd is involved). I’ll use the updated init script in my Chef cookbooks for now, but it would be great to not have to rely on anything custom.


Hi @ameir

Thanks for letting us know about this and about your workaround. That’s interesting that it seems to be a problem grabbing the PID on CentOS 7. Very recently we had reports of this issue on some CentOS 7 installs and as such I have filed this issue with our developers for attention, so we will get a resolution to this in a future version of the agent.

I will test your workaround, and if it works I will be sure to highlight this particular finding to our developers incase it helps them narrow down the issue quicker. Hopefully we can get an official fix into an upcoming PHP Agent so you don’t have to use anything custom. :smile:


This bug just hit me on Debian Jessie with newrelic-daemon From systemd, the daemon refuses to start. If I call the init script directly (in a place outside /etc/init.d), the daemon starts.

Please test your software for systemd compatibility, Better yet, ship systemd unit files instead of relying on broken sysvinit compatibility in systemd.

By the way, a line like

maybepid=ps -ef | grep '/newrelic-daemon ' | sed -e '/grep/d' | awk '{if ($3 == 1) {print $2;}}'

doesn’t deserve any awards for beauty or efficiency in any case. It can break in too many ways.



The following service unit file seems to work for me (Debian Jessie, newrelic-daemon

Description=The New Relic Proxy Daemon

ExecStart=/usr/bin/newrelic-daemon -c /etc/newrelic/newrelic.cfg --pidfile /var/run/



Great! Thanks for updating us all with what worked for you, @martijn.grendelman!

Let us know if you have any more questions we can help with! :blush:


@martijn.grendelman’s unit works for me if I change the Type from simple to forking, for those of us who arrive here from a Google search.