aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaditya Bagga <aaditya_gnulinux@zoho.com>2018-11-06 20:26:33 +0530
committerWilliam Hubbs <w.d.hubbs@gmail.com>2021-09-11 17:20:50 -0500
commit6e24d335172b43286a284167c2d54d8f240fc9a0 (patch)
tree94eb1b9468e0cafdf115f53a3f181356d82fd7c6
parentd65e603acd9b1f542069c59482c5e22502afa872 (diff)
[runit integration] give a bit of time to start the service
Currently, we run sv start immediately after linking the service. The runsv process may not be up at the moment, as a result of which openrc will mark the service as stopped, even though it may be brought up by runit at the next scan. This is documented in the gentoo wiki: https://wiki.gentoo.org/wiki/Runit#OpenRC.27s_runit_integration_feature This PR adds a timeout so that correct process state can be reported. Before: * Starting netdata-runit ... fail: /run/openrc/sv/netdata: runsv not running * Failed to start netdata-runit After: * Starting netdata-runit ... fail: /run/openrc/sv/netdata: runsv not running ok: run: /run/openrc/sv/netdata: (pid 9042) 0s This fixes #253.
-rw-r--r--sh/runit.sh16
1 files changed, 14 insertions, 2 deletions
diff --git a/sh/runit.sh b/sh/runit.sh
index 3cef0f3a..5d82c9f6 100644
--- a/sh/runit.sh
+++ b/sh/runit.sh
@@ -20,8 +20,20 @@ runit_start()
service_link="${RC_SVCDIR}/sv/${service_path##*/}"
ebegin "Starting ${name:-$RC_SVCNAME}"
ln -snf "${service_path}" "${service_link}"
- sv start "${service_link}" > /dev/null 2>&1
- eend $? "Failed to start ${name:-$RC_SVCNAME}"
+ local i=0 retval=1
+ # it can take upto 5 seconds for runsv to start
+ while [ $i -lt 6 ] ; do
+ if sv start "${service_link}" > /dev/null 2>&1; then
+ retval=0
+ break
+ fi
+ sleep 1 && i=$(expr $i + 1)
+ done
+ if [ $retval -eq 1 ]; then
+ # clean up the link else sv will keep on trying
+ rm "${service_link}"
+ fi
+ eend $retval "Failed to start ${name:-$RC_SVCNAME}"
}
runit_stop()