From 6e24d335172b43286a284167c2d54d8f240fc9a0 Mon Sep 17 00:00:00 2001 From: Aaditya Bagga Date: Tue, 6 Nov 2018 20:26:33 +0530 Subject: [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. --- sh/runit.sh | 16 ++++++++++++++-- 1 file 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() -- cgit v1.2.3