Page 1 of 1

[SOLVED] systemd service for fancontrol not working

PostPosted: Jan 7th, '15, 23:46
by mzurhorst
Hi all,
I have configured fancontrol because the fan of my Dell laptop is spinning all the time.
This is working quite well now, and I like to get fancontrol started automatically.

I was reading the man pages and some tutorials, and I thought that I have a tiny "fancontrol.service" file properly created.
However, the service starts, but after a short while, it is stopped for a unknown reason. It seems that systemd tries to restart the broken service, but fails.

Here is my service file. What is wrong with it?

Code: Select all
[Unit]
Description=Fancontrol service

[Service]
Type=forking
ExecStart=/sbin/fancontrol
PIDFile=/var/run/fancontrol.pid

[Install]
WantedBy=multi-user.target


Since /sbin/fancontrol is a shell script, I understood that "forking" is the appropriate type, and that the PID file should be specified as well.
I took the path for the PID file directly from the source code of the fancontrol shell script.

Thanks a lot in advance for your help!

Regards,
Marcus

Re: systemd service for fancontrol not working

PostPosted: Jan 8th, '15, 02:12
by doktor5000
Type should probably be "oneshot", you should probably start fancontrol with -D.
Also you didn't post where you put fancontrol.service and output of e.g.
Code: Select all
systemctl status fancontrol.service


Short google search shows up the following related threads:

https://bbs.archlinux.org/viewtopic.php?id=151431
https://forums.opensuse.org/showthread. ... ol-service ( please don't put the service into /usr/lib/systemd, it belongs into /etc/systemd/system/ )
http://forums.fedoraforum.org/showthread.php?t=286160 ( please don't put the service into /usr/lib/systemd, it belongs into /etc/systemd/system/ )
http://superuser.com/questions/786186/f ... -but-exits

Re: systemd service for fancontrol not working

PostPosted: Jan 9th, '15, 18:57
by doktor5000
FWIW, for the type, see http://enotty.pipebreaker.pl/2014/10/08 ... emd-units/ for explanations what type to use when.

Re: systemd service for fancontrol not working

PostPosted: Jan 13th, '15, 13:15
by mzurhorst
Sorry for the delay, I was waiting for a email notification ;)

Ok, let me answer the questions:
1) I created the file fancontrol.service in the folder /etc/systemd/service
2) Then, I activated the service via sudo systemctl --system enable fancontrol.service
(this created a symlink to my file inside /etc/systemd/system/multi-user.target.wants/)
3) When the laptop boots, the fan is silent, but turns to full power after a short while.
This is because the service fails and cannot be restarted. The fancontrol safety mechanism sets the fans to full speed.
4) I cannot find the -D switch for the fancontrol bash script in the man page: http://linux.die.net/man/8/fancontrol
What is this supposed to do? (the switch is accepted, but I tried some other letters, and it seems that the script is not doing any error checking at all)
5) The status output is this:
Code: Select all
[marcus@mzlaptop2 system]$ sudo systemctl -l status fancontrol.service
fancontrol.service - Fancontrol service
   Loaded: loaded (/etc/systemd/system/fancontrol.service; enabled)
   Active: failed (Result: timeout) since Di 2015-01-13 09:44:24 CET; 2h 26min ago
  Process: 854 ExecStart=/sbin/fancontrol (code=exited, status=0/SUCCESS)
Jan 13 09:42:54 mzlaptop2 fancontrol[854]: MINSTOP=60
Jan 13 09:42:54 mzlaptop2 fancontrol[854]: MINPWM=0
Jan 13 09:42:54 mzlaptop2 fancontrol[854]: MAXPWM=255
Jan 13 09:42:54 mzlaptop2 fancontrol[854]: Enabling PWM on fans...
Jan 13 09:42:54 mzlaptop2 fancontrol[854]: Starting automatic fan control...
Jan 13 09:44:24 mzlaptop2 systemd[1]: fancontrol.service operation timed out. Terminating.
Jan 13 09:44:24 mzlaptop2 systemd[1]: Failed to start Fancontrol service.
Jan 13 09:44:24 mzlaptop2 systemd[1]: Unit fancontrol.service entered failed state.
Jan 13 09:44:25 mzlaptop2 fancontrol[854]: Aborting, restoring fans...
Jan 13 09:44:25 mzlaptop2 fancontrol[854]: Verify fans have returned to full speed
[marcus@mzlaptop2 system]$


6) Regarding the type, I was just following the man page. I will check to references and report back in the next days.

Thanks for your help!

Regards,
Marcus

Re: systemd service for fancontrol not working

PostPosted: Jan 13th, '15, 19:45
by doktor5000
mzurhorst wrote:Sorry for the delay, I was waiting for a email notification ;)

Sadly that's not the forum default and has to be enabled explicitly per-user, for users that have created their account before the default was switched.
Please check viewtopic.php?f=7&t=210 and the linked bugreport for more details.

mzurhorst wrote:4) I cannot find the -D switch for the fancontrol bash script in the man page: http://linux.die.net/man/8/fancontrol
What is this supposed to do? (the switch is accepted, but I tried some other letters, and it seems that the script is not doing any error checking at all)

Probably supposed to daemonize fancontrol, that is fork it and keep it running in background. Actually it was only mentioned in the fedora forum post.
I've quickly glanced over the script and it doesn't support anything except for the first argument ($1) which it expects to be a file. And yes, no error checking/handling is in place apart from checking some things related to the config file.
mzurhorst wrote:5) The status output is this:

Seems it starts too early or a required kernel module is not loaded yet. You may need to enable debugging in the scrippt to find out why it doesn't start.
See the previously mentioned arch linux link on how to fix such timing issues.

Re: systemd service for fancontrol not working

PostPosted: Jan 14th, '15, 20:17
by winstonteacox
Hi!

I am the one, who described fancontol in the other post and I am watching this thread, because systemd is also unknown territory for me.

But there will be another problem:

lm-sensors detects the sensors in a certain order i.e. assigns a number to each sensor. pwmconfig relies on that numbers. These numbers may change - not often - but mostly after kernel-updates. Then fancontrol won't work anymore, because it doesn't find the sensors.

So - if there is a systemd autostart solution, there will be the problem sometimes, that fancontrol suddenly doesn't work anymore. This is not a systemd problem then. The solution is easy - just run the pwmconfig script again and reboot or start fancontrol manually this time.

cheers,
Bernd

Re: systemd service for fancontrol not working

PostPosted: Jan 14th, '15, 22:05
by doktor5000
winstonteacox wrote:lm-sensors detects the sensors in a certain order i.e. assigns a number to each sensor. pwmconfig relies on that numbers. These numbers may change - not often - but mostly after kernel-updates. Then fancontrol won't work anymore, because it doesn't find the sensors.

Fix seems to be explained here, no? https://bbs.archlinux.org/viewtopic.php?id=80012

edit doktor5000: Also later versions of lm_sensors seem to support absolute device paths, amon other things:
http://lists.lm-sensors.org/pipermail/l ... 38971.html

Re: systemd service for fancontrol not working

PostPosted: Jan 14th, '15, 23:24
by mzurhorst
I have not yet found the time to dig too much deeper.
All I can say is that I have some appealing silence here because I switched the start type to "simple".

Re: systemd service for fancontrol not working

PostPosted: Jan 14th, '15, 23:41
by mzurhorst
Ah, maybe this was too optimistic.
I killed the fancontrol process to test whether or not systemd would restart the script.
This does not happen with "simple".

Is my assumption that systemd restarts the service valid at all?
-- Or is this beyond its responsiblity?

Re: systemd service for fancontrol not working

PostPosted: Jan 15th, '15, 00:34
by doktor5000
That is not defined via the "Type" option. See the man page for the "Restart" option: http://www.freedesktop.org/software/sys ... rvice.html
It defaults to no so that services are not restarted.

Re: systemd service for fancontrol not working

PostPosted: Jan 23rd, '15, 23:09
by mzurhorst
I managed to solve this topic ultimately.
Thank you, doktor5000, my assumption was just wrong.

Following your link, I specified the restart behaviour and now it is working properly.
The final unit file looks like this:
Code: Select all
[Unit]
Description=Fancontrol service

[Service]
Type=simple
ExecStart=/sbin/fancontrol
Restart=on-failure

[Install]
WantedBy=multi-user.target

I was never dealing with unit files before, but my first experience is quite positive.
It seems simple, while offering plenty of optional complexities if required.

Regards,
Marcus