Skip to content

Commit

Permalink
simplify ext-newrelic startup handling
Browse files Browse the repository at this point in the history
the previous if checks were leftovers from a time when that shell script was run unconditionally on dyno startup

it is now bundled with the extension, so the sanity checks (is the binary there etc) are no longer needed
  • Loading branch information
dzuelke committed Aug 19, 2019
1 parent 6976ee3 commit 9c89856
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- ext-newrelic/9.0.2.245 [David Zuelke]

### CHG

- Simplify ext-newrelic startup handling [David Zuelke]

### FIX

- Fix HHVM boot scripts failing if a `composer` shell function is present [David Zuelke]
Expand Down
65 changes: 30 additions & 35 deletions support/build/extensions/no-debug-non-zts-20121212/newrelic
Original file line number Diff line number Diff line change
Expand Up @@ -58,53 +58,48 @@ popd
mkdir -p ${OUT_PREFIX}/bin
# gets sourced on dyno boot
cat > ${OUT_PREFIX}/bin/profile.newrelic.sh <<'EOF'
if [[ -n "$NEW_RELIC_LICENSE_KEY" ]]; then
if [[ -f "/app/.heroku/php/bin/newrelic-daemon" ]]; then
export NEW_RELIC_APP_NAME=${NEW_RELIC_APP_NAME:-${HEROKU_APP_NAME:-"PHP Application on Heroku"}}
export NEW_RELIC_LOG_LEVEL=${NEW_RELIC_LOG_LEVEL:-"warning"}
export NEW_RELIC_DAEMON_LOG_LEVEL="$NEW_RELIC_LOG_LEVEL"
if [[ "$NEW_RELIC_DAEMON_LOG_LEVEL" == verbose* || "$NEW_RELIC_DAEMON_LOG_LEVEL" == *debug ]]; then
NEW_RELIC_DAEMON_LOG_LEVEL="debug"
fi
# The daemon is a started in foreground mode so it will not daemonize
# (i.e. disassociate from the controlling TTY and disappear into the
# background).
#
# Perpetually tail and redirect the daemon log file to stderr so that it
# may be observed via 'heroku logs'.
touch /tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log
tail -qF -n 0 /tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log 1>&2 &
# daemon start
/app/.heroku/php/bin/newrelic-daemon --foreground --port "@newrelic-daemon" --logfile "/tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log" --loglevel "${NEW_RELIC_DAEMON_LOG_LEVEL}" --pidfile "/tmp/newrelic-daemon.pid" &
# give it a moment to connect
sleep 2
else
echo >&2 "WARNING: Add-on 'newrelic' detected, but PHP extension not yet installed. Push an update to the application to finish installation of the add-on; an empty change ('git commit --allow-empty') is sufficient."
fi
export NEW_RELIC_APP_NAME=${NEW_RELIC_APP_NAME:-${HEROKU_APP_NAME:-"PHP Application on Heroku"}}
export NEW_RELIC_LOG_LEVEL=${NEW_RELIC_LOG_LEVEL:-"warning"}
export NEW_RELIC_DAEMON_LOG_LEVEL="$NEW_RELIC_LOG_LEVEL"
if [[ "$NEW_RELIC_DAEMON_LOG_LEVEL" == verbose* || "$NEW_RELIC_DAEMON_LOG_LEVEL" == *debug ]]; then
NEW_RELIC_DAEMON_LOG_LEVEL="debug"
fi
# The daemon is a started in foreground mode so it will not daemonize
# (i.e. disassociate from the controlling TTY and disappear into the
# background).
#
# Perpetually tail and redirect the daemon log file to stderr so that it
# may be observed via 'heroku logs'.
touch /tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log
tail -qF -n 0 /tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log 1>&2 &
# daemon start
/app/.heroku/php/bin/newrelic-daemon --foreground --port "@newrelic-daemon" --logfile "/tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log" --loglevel "${NEW_RELIC_DAEMON_LOG_LEVEL}" --pidfile "/tmp/newrelic-daemon.pid" &
# give it a moment to connect
sleep 2
EOF
mkdir -p ${OUT_PREFIX}/etc/php/conf.d
cat > ${OUT_PREFIX}/etc/php/conf.d/newrelic.ini-dist <<'EOF'
extension = newrelic.so
newrelic.daemon.location = /app/.heroku/php/bin/newrelic-daemon
newrelic.daemon.port = @newrelic-daemon
newrelic.loglevel = ${NEW_RELIC_LOG_LEVEL}
newrelic.daemon.loglevel = ${NEW_RELIC_DAEMON_LOG_LEVEL}
newrelic.license = ${NEW_RELIC_LICENSE_KEY}
newrelic.appname = ${NEW_RELIC_APP_NAME}
newrelic.logfile = stderr ; the stdout default messes up boots as we capture output for crash detection
; The daemon gets spawned by the PHP agent and is configured with the same values
;
; There is code in bin/compile to create .profile.d/newrelic.sh. That script
; starts the daemon and runs a perpetual tail command which will redirect daemon
; logs to stderr so that it may be observed via 'heroku logs'.
; make sure the extension ("agent") does not start the daemon (we do that on dyno boot)
newrelic.daemon.dont_start = 3
; so we know where to connect to; @newrelic-daemon is an abstract socket
newrelic.daemon.port = @newrelic-daemon
; we start the daemon on dyno boot, but the values below are still in here for reference (they're passed via cmdline args to newrelic-daemon)
newrelic.daemon.loglevel = ${NEW_RELIC_DAEMON_LOG_LEVEL}
; the newrelic start script runs a perpetual tail command which will redirect daemon logs to stderr so that they may be observed via 'heroku logs'
newrelic.daemon.logfile = /tmp/heroku.ext-newrelic.newrelic-daemon.${PORT}.log
; or else:
Expand Down
6 changes: 3 additions & 3 deletions test/spec/php_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
else
# a NEW_RELIC_LICENSE_KEY triggers the automatic installation of ext-newrelic at the end of the build
@app = new_app_with_stack_and_platrepo('test/fixtures/bootopts',
config: { "NEW_RELIC_LOG_LEVEL" => "info", "NEW_RELIC_LICENSE_KEY" => "this willtriggernewrelic" },
config: { "NEW_RELIC_LOG_LEVEL" => "info", "NEW_RELIC_LICENSE_KEY" => "thiswilltriggernewrelic" },
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs 'php:#{series}.*'") or raise "Failed to require PHP version" }
)
end
Expand Down Expand Up @@ -86,11 +86,11 @@
it "launches newrelic-daemon, but not the extension, during boot preparations, with #{script}" do
out = @app.run("#{script} -F conf/fpm.include.broken") # prevent FPM from starting up using an invalid config, that way we don't have to wrap the server start in a `timeout` call

expect(out).not_to match(/spawned daemon child/) unless mode.include? "without NEW_RELIC_LICENSE_KEY" # extension does not spawn its own daemon
expect(out).not_to match(/spawned daemon child/) # extension does not spawn its own daemon

out_before_fpm, out_after_fpm = out.split("Starting php-fpm", 2)

expect(out_before_fpm).to match(/listen="@newrelic-daemon"[^\n]+?startup=init/) unless mode.include? "without NEW_RELIC_LICENSE_KEY" # NR daemon starts on boot
expect(out_before_fpm).to match(/listen="@newrelic-daemon"[^\n]+?startup=init/) # NR daemon starts on boot
expect(out_before_fpm).not_to match(/daemon='@newrelic-daemon'[^\n]+?startup=agent/) # extension does not connect to daemon before FPM starts
expect(out_before_fpm).to match(/New Relic PHP Agent globally disabled/) # NR extension reports itself disabled

Expand Down

0 comments on commit 9c89856

Please sign in to comment.