--- prog/detect/sensors-detect | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) --- lm-sensors.orig/prog/detect/sensors-detect 2012-01-25 15:14:52.000000000 +0100 +++ lm-sensors/prog/detect/sensors-detect 2012-01-25 18:10:59.304053855 +0100 @@ -6493,6 +6493,17 @@ sub generate_modprobes return ($configfile, \@bus_modules, \@hwmon_modules); } +sub systemd_service_property +{ + my ($service, $prop) = @_; + my $status; + + $status = `systemctl show --property=$prop $service.service`; + chomp($status); + $status =~ s/.*=(.*)/$1/; + return $status; +} + sub write_config { my ($configfile, $bus_modules, $hwmon_modules) = @_; @@ -6562,16 +6573,16 @@ EOT } close(SYSCONFIG); - if (-x "/bin/systemctl" && -d "/lib/systemd/system" && - ! -f "/lib/systemd/system/lm_sensors.service") { - print "Copy prog/init/lm_sensors.service to /lib/systemd/system\n". - "and run 'systemctl enable lm_sensors.service'\n". - "for initialization at boot time.\n"; - return; - } + # Systemd integration + if (-d "/sys/fs/cgroup/systemd") { + if (systemd_service_property("lm_sensors", "LoadState") ne "loaded") { + # Service file is missing + print "Copy prog/init/lm_sensors.service to /lib/systemd/system\n". + "and run 'systemctl enable lm_sensors.service'\n". + "for initialization at boot time.\n"; + return; + } - if (-x "/bin/systemctl" && - -f "/lib/systemd/system/lm_sensors.service") { system("/bin/systemctl", "enable", "lm_sensors.service"); system("/bin/systemctl", "start", "lm_sensors.service"); # All done, don't check for /etc/init.d/lm_sensors @@ -6633,8 +6644,12 @@ sub main exit -1; } - if (-x "/bin/systemctl" && -f "/lib/systemd/system/lm_sensors.service") { - system("/bin/systemctl", "stop", "lm_sensors.service"); + # If lm_sensors service is running, stop it + if (-d "/sys/fs/cgroup/systemd") { + if (systemd_service_property("lm_sensors", "ActiveState") eq "active") { + print "Stopping lm_sensors.service...\n"; + system("/bin/systemctl", "stop", "lm_sensors.service"); + } } elsif (-x "/sbin/service" && -f "/etc/init.d/lm_sensors" && -f "/var/lock/subsys/lm_sensors") { system("/sbin/service", "lm_sensors", "stop");