From 756c1aa06ee889292911614fa30b863973fd7646 Mon Sep 17 00:00:00 2001 From: ZNeumann Date: Tue, 18 Jun 2024 13:43:44 -0600 Subject: [PATCH] fix(scripts): fix rhel and alpine init scripts (#919) Systemd systems may not have access to the functions file provided by initscripts. The code from initscripts is provided under the GNU v2 license and will not be pulled in. Additionally, a header comment block must be added, using https://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html for specs --------- Co-authored-by: Michal Nowacki --- agent/scripts/init.alpine | 3 +-- agent/scripts/init.rhel | 47 +++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/agent/scripts/init.alpine b/agent/scripts/init.alpine index 63d143e66..0fc717dbc 100755 --- a/agent/scripts/init.alpine +++ b/agent/scripts/init.alpine @@ -1,10 +1,9 @@ +#!/sbin/openrc-run # # Copyright 2020 New Relic Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # -#!/sbin/openrc-run - description="New Relic Daemon" command="${nrdaemon:-/usr/bin/newrelic-daemon}" command_args= diff --git a/agent/scripts/init.rhel b/agent/scripts/init.rhel index 82f43608c..2e88a6307 100644 --- a/agent/scripts/init.rhel +++ b/agent/scripts/init.rhel @@ -10,6 +10,15 @@ # processname: newrelic-daemon # config: /etc/newrelic/newrelic.cfg # +### BEGIN INIT INFO +# Provides: newrelic-daemon +# Required-Start: $all +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: The New Relic Daemon is used by the New Relic PHP Agent to communicate +# with the New Relic Backend +### END INIT INFO LANG=C NAME=newrelic-daemon @@ -18,7 +27,11 @@ DESC="New Relic Daemon" # # Source function library. # -. /etc/init.d/functions +has_initd_functions=0 +if [ -f /etc/init.d/functions ]; then + . /etc/init.d/functions + has_initd_functions=1 +fi ulimit -n 2048 > /dev/null 2>&1 @@ -223,14 +236,22 @@ EOF if running ; then if [ -z "${NR_SILENT}" -a -z "${SILENT}" ]; then - success - echo + if [ $has_initd_functions -eq 1 ]; then + success + echo + else + echo " [ OK ]" + fi fi return 0 else if [ -z "${NR_SILENT}" -a -z "${SILENT}" ]; then - failure - echo + if [ $has_initd_functions -eq 1 ]; then + failure + echo + else + echo " [FAILED]" + fi fi return 1 fi @@ -274,14 +295,22 @@ stop() { if running ; then if [ -z "${NR_SILENT}" -a -z "${SILENT}" ]; then - failure - echo + if [ $has_initd_functions -eq 1 ]; then + failure + echo + else + echo " [FAILED]" + fi fi return 1 else if [ -z "${NR_SILENT}" -a -z "${SILENT}" ]; then - success - echo + if [ $has_initd_functions -eq 1 ]; then + success + echo + else + echo " [ OK ]" + fi fi return 0 fi