@cryptotaxi247 / netdata-1 / commits / b5e1e3690

Properly guard commands when installing services for offline service managers. (#13848)

Austin S. Hemmelgarn committed Oct 19, 2022 at 07:11 UTC b5e1e3690c9a8e59abe3a3a247ce7906f3259053
1 file changed +11 -5
system/install-service.sh.in
+11 -5
@@ -243,7 +243,9 @@ install_systemd_service() {
243 fi
244
245 if [ "${ENABLE}" = "auto" ]; then
246 - IS_NETDATA_ENABLED="$(systemctl is-enabled netdata 2> /dev/null || echo "Netdata not there")"
246 + if [ "$(check_systemd)" = "YES" ]; then
247 + IS_NETDATA_ENABLED="$(systemctl is-enabled netdata 2> /dev/null || echo "Netdata not there")"
248 + fi
249
250 if [ "${IS_NETDATA_ENABLED}" = "disabled" ]; then
251 ENABLE="disable"
@@ -258,7 +260,7 @@ install_systemd_service() {
260 exit 4
261 fi
262
261 - if check_systemd; then
263 + if [ "$(check_systemd)" = "YES" ]; then
264 if ! systemctl daemon-reload; then
265 warning "Failed to reload systemd unit files."
266 fi
@@ -270,7 +272,7 @@ install_systemd_service() {
272 }
273
274 systemd_cmds() {
273 - if check_systemd; then
275 + if [ "$(check_systemd)" = "YES" ]; then
276 NETDATA_START_CMD='systemctl start netdata'
277 NETDATA_STOP_CMD='systemctl stop netdata'
278 else # systemd is not running, use external defaults by providing no commands
@@ -316,8 +318,12 @@ check_openrc() {
318 }
319
320 enable_openrc() {
319 - runlevel="$(rc-status -r)"
321 + if [ "$(check_openrc)" = "YES" ]; then
322 + runlevel="$(rc-status -r)"
323 + fi
324 +
325 runlevel="${runlevel:-default}"
326 +
327 if ! rc-update add netdata "${runlevel}"; then
328 warning "Failed to enable Netdata service in runlevel ${runlevel}."
329 fi
@@ -339,7 +345,7 @@ install_openrc_service() {
345 }
346
347 openrc_cmds() {
342 - if check_openrc; then
348 + if [ "$(check_openrc)" = "YES" ]; then
349 NETDATA_START_CMD='rc-service netdata start'
350 NETDATA_STOP_CMD='rc-service netdata stop'
351 else # Not booted using OpenRC, use external defaults by not providing commands.