collectd: run sensors-detect in background

Message ID 20200325063538.15980-1-arne_f@ipfire.org
State Accepted
Commit a3b07005c11938f426e208be42cf32bcbc62da31
Headers
Series collectd: run sensors-detect in background |

Commit Message

Arne Fitzenreiter March 25, 2020, 6:35 a.m. UTC
  on some machines the i2c sensor search take very long time
which cause hang at first boot.

Now the search is started in background and waited for max one
minute before continue load of collectd.
On such machines collectd will not get all sensors at first startup.

fixes #12329

Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
---
 src/initscripts/system/collectd | 56 ++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 19 deletions(-)
  

Comments

Michael Tremer March 25, 2020, 9:10 a.m. UTC | #1
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>

This is an interesting approach to an interesting problem.

I guess it solves the problem well, although we should not be in the position where we have to build all this code :)

> On 25 Mar 2020, at 06:35, Arne Fitzenreiter <arne_f@ipfire.org> wrote:
> 
> on some machines the i2c sensor search take very long time
> which cause hang at first boot.
> 
> Now the search is started in background and waited for max one
> minute before continue load of collectd.
> On such machines collectd will not get all sensors at first startup.

Can scan_for_sensors() not simply check if collectd is already running and if so, simply restart it?

Best,
-Michael

> 
> fixes #12329
> 
> Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
> ---
> src/initscripts/system/collectd | 56 ++++++++++++++++++++++-----------
> 1 file changed, 37 insertions(+), 19 deletions(-)
> 
> diff --git a/src/initscripts/system/collectd b/src/initscripts/system/collectd
> index 5233525f0..20072780a 100644
> --- a/src/initscripts/system/collectd
> +++ b/src/initscripts/system/collectd
> @@ -6,6 +6,28 @@
> 
> eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
> 
> +scan_for_sensors() {
> +	touch /var/lock/sensors_search
> +	# pre scan and try to load modules
> +	"yes" | /usr/sbin/sensors-detect > /dev/null
> +	if [ -e /etc/sysconfig/lm_sensors ]; then
> +
> +		# Module load
> +		. /etc/sysconfig/lm_sensors
> +		for modul in $BUS_MODULES $HWMON_MODULES ; do
> +			modprobe $modul > /dev/null 2>&1;
> +		done
> +	fi
> +
> +	# Final scan
> +	"yes" | /usr/sbin/sensors-detect > /dev/null
> +
> +	if [ ! -e /etc/sysconfig/lm_sensors ]; then
> +		echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
> +	fi
> +	rm /var/lock/sensors_search
> +}
> +
> if [ "$RRDLOG" = '' ]; then
> 	RRDLOG=/var/log/rrd
> fi
> @@ -42,27 +64,23 @@ case "$1" in
> 
> 		# At first run search for sensors with sensors-detect
> 		if [ ! -e /etc/sysconfig/lm_sensors ]; then
> -			boot_mesg "Searching for Sensors..."
> -
> -			# pre scan and try to load modules
> -			"yes" | /usr/sbin/sensors-detect > /dev/null
> -			if [ -e /etc/sysconfig/lm_sensors ]; then
> -
> -				# Module load
> -				. /etc/sysconfig/lm_sensors
> -				for modul in $BUS_MODULES $HWMON_MODULES ; do
> -					modprobe $modul > /dev/null 2>&1;
> -				done
> -			fi
> -
> -			# Final scan
> -			"yes" | /usr/sbin/sensors-detect > /dev/null
> -			evaluate_retval
> +			# Don't run at next boot again
> +			touch /etc/sysconfig/lm_sensors
> +			boot_mesg -n "Searching for Sensors..."
> +			scan_for_sensors &
> +			sleep 2
> +		fi
> 
> -			if [ ! -e /etc/sysconfig/lm_sensors ]; then
> -				echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
> -			fi
> +		if [ -e /var/lock/sensors_search ]; then
> +			for (( i=1; i<30; i++)) do
> +				if [ ! -e /var/lock/sensors_search ]; then
> +					break;
> +				fi
> +				boot_mesg -n "."
> +				sleep 2
> +			done
> 		fi
> +		boot_mesg ""
> 
> 		# Load sensor modules only first start
> 		if [ ! -e /var/lock/sensors_modules ]; then
> -- 
> 2.17.1
>
  
Arne Fitzenreiter March 26, 2020, 12:01 p.m. UTC | #2
> Can scan_for_sensors() not simply check if collectd is already running
> and if so, simply restart it?
> 
Im not sure. scan_for_sensors generate a list of kernel modules that 
must loaded before collectd.
I have not tested restarting collectd after it has finished.

Arne
  

Patch

diff --git a/src/initscripts/system/collectd b/src/initscripts/system/collectd
index 5233525f0..20072780a 100644
--- a/src/initscripts/system/collectd
+++ b/src/initscripts/system/collectd
@@ -6,6 +6,28 @@ 
 
 eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
 
+scan_for_sensors() {
+	touch /var/lock/sensors_search
+	# pre scan and try to load modules
+	"yes" | /usr/sbin/sensors-detect > /dev/null
+	if [ -e /etc/sysconfig/lm_sensors ]; then
+
+		# Module load
+		. /etc/sysconfig/lm_sensors
+		for modul in $BUS_MODULES $HWMON_MODULES ; do
+			modprobe $modul > /dev/null 2>&1;
+		done
+	fi
+
+	# Final scan
+	"yes" | /usr/sbin/sensors-detect > /dev/null
+
+	if [ ! -e /etc/sysconfig/lm_sensors ]; then
+		echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
+	fi
+	rm /var/lock/sensors_search
+}
+
 if [ "$RRDLOG" = '' ]; then
 	RRDLOG=/var/log/rrd
 fi
@@ -42,27 +64,23 @@  case "$1" in
 
 		# At first run search for sensors with sensors-detect
 		if [ ! -e /etc/sysconfig/lm_sensors ]; then
-			boot_mesg "Searching for Sensors..."
-
-			# pre scan and try to load modules
-			"yes" | /usr/sbin/sensors-detect > /dev/null
-			if [ -e /etc/sysconfig/lm_sensors ]; then
-
-				# Module load
-				. /etc/sysconfig/lm_sensors
-				for modul in $BUS_MODULES $HWMON_MODULES ; do
-					modprobe $modul > /dev/null 2>&1;
-				done
-			fi
-
-			# Final scan
-			"yes" | /usr/sbin/sensors-detect > /dev/null
-			evaluate_retval
+			# Don't run at next boot again
+			touch /etc/sysconfig/lm_sensors
+			boot_mesg -n "Searching for Sensors..."
+			scan_for_sensors &
+			sleep 2
+		fi
 
-			if [ ! -e /etc/sysconfig/lm_sensors ]; then
-				echo "#No Sensors detected " > /etc/sysconfig/lm_sensors
-			fi
+		if [ -e /var/lock/sensors_search ]; then
+			for (( i=1; i<30; i++)) do
+				if [ ! -e /var/lock/sensors_search ]; then
+					break;
+				fi
+				boot_mesg -n "."
+				sleep 2
+			done
 		fi
+		boot_mesg ""
 
 		# Load sensor modules only first start
 		if [ ! -e /var/lock/sensors_modules ]; then