I recently learned about the possibilities of /etc/tmpfiles.d of systemd and because I have to set some values in /sys/somewhere on bootup I wondered whether better to do that via /etc/tmpfiles.d or in an own service file (a oneshot which I have, anyway, because I have to execute a bashscript on bootup, so I could add setting the values without further problems).
Would you recommend to use /etc/tmpfiles.d or an own service-file and why? I'm trying to figure out in which situations better to use /etc/tmpfiles.d and in which better to write a service file.
Thanks in advance!
tmpfiles.d is preferred if it works, but with paths in /sys problems can occur (tmpfiles service is called before path is available)
Yes, I think you should probably be more specific about what it is you are actually trying to accomplish.
For example, I tried using tmpfiles.d to set my screen brightness. It worked for a bit, and then I noticed that it was inconsistent. It worked more often than not, but not every time. So I ended up using a udev rule to set teh value as soon as the appropriate "brightness" file in /sys was made available.
I want to set the sensitivity and speed of my trackpoint as well as the possibility to simulate a leftclick when tapping on it.
What I want to do exactely is:
cd /sys/devices/platform/i8024/serio1/serio2 echo -n 120 > speed echo -n 250 > sensitivity echo -n 1 > press_to_select
(in the service-file I do it without the cd-command, of course).
I sometimes noticed it not working in the unit-file, so I added an "After="-option to the service file. The same can happen concerning /sys using tmpfiles.d, so in my case, the unit-file should be preferred?
But /run is definitely available at the time of execution of tmpfiles.d? Is there a special reason for /sys not being available then sometimes? (The sometimes is of course explainable by systemd's parallelisation)
This is a situation in which a tmpfile will probably not work since these directories are really not created until X starts. So if you are manually starting X with startx, the necessary directories will not be present when systemd-tmpfiles runs.
In a service file, it is not a shell. So you either need to do "ExecStart=/bin/bash -c "echo -n 120 > /sys/devices/platform/i8124/serio1/serio2/speed" or you need to make a small script that does these things and then call that. I would make the script instead of calling three separate shells to perform these commands.
Edit: The reason why this is not there when it is called is because this functionality is not in use before a graphical interface is brought up and X is set up. I had a udev rule to do this, but it only worked if I had my system to bring up X right away (by booting into the graphical.target for which I don't use a display manager).
Last edited by WonderWoofy (2013-03-31 19:47:11)
Ok, thanks. I will then stick to the service-file, if I find a way to bind its execution to the starting of X (because I use startx for starting the graphical environement), otherwise I have to look for another possibility to execute root-commands on X-start.