You are not logged in.

#1 2012-10-31 13:29:44

maggie
Member
Registered: 2011-02-12
Posts: 255

Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

I have 12 lines in my old /etc/rc.local that set up powersaving features and make symlinks mainly.  Before systemd we just needed to put stuff like that in /etc/rc.local to do it. I read from falconindy that we should now be using tmpfiles to do this but I can't find the thread where he said that. On the wiki it says to use a service file to emulate rc.local. Is this the accepted way to do it?

https://wiki.archlinux.org/index.php/Sy … 2Frc.local

Last edited by maggie (2012-11-01 20:17:24)

Offline

#2 2012-10-31 13:35:12

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

You could use an rc.local file if you please.  I think it would be just as wrong now as it was before, so I see no harm if you are comfortable with it.  But really it has always been kind of a hack or cheat to enable laziness.

For power saving you may use /etc/tmpfiles.d .  Just see the man page for more info.  Also, these things can pretty easily be done with /etc/udev/rules.d/ though it may take a few minutes longer to learn how to write a udev rule.  I personally use udev rules, and they work great.  Also, udev rules seem to be used for a quite a bit, so learning them was certainly worht the effort.

Offline

#3 2012-10-31 18:42:07

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

I read the man page for tmpfiles.d but I dont see how to cause a tmpfile to execute something. They seem to be used to make or remove or symlink. How would I use it to execute this:

echo min_power > /sys/class/scsi_host/host0/link_power_management_policy

Offline

#4 2012-10-31 18:51:20

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

WonderWoofy wrote:

Also, these things can pretty easily be done with /etc/udev/rules.d/ though it may take a few minutes longer to learn how to write a udev rule.  I personally use udev rules, and they work great.

I'm curious what things you are doing with udev rules?  Can you describe and post a few examples?

Offline

#5 2012-10-31 20:19:19

ColdPie
Member
Registered: 2007-09-18
Posts: 47

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

maggie wrote:

I read the man page for tmpfiles.d but I dont see how to cause a tmpfile to execute something. They seem to be used to make or remove or symlink. How would I use it to execute this:

echo min_power > /sys/class/scsi_host/host0/link_power_management_policy

I think you want to use the "w" action. So you'd create, say, /etc/tmpfiles.d/boot.conf that contains:

w /sys/class/scsi_host/host0/link_power_management_policy - - - - min_power

But I get stuck there. I'm not sure how to trigger that file to be run at boot and only at boot. Out of time, but hopefully that can help get you started...

Last edited by ColdPie (2012-10-31 20:19:42)

Offline

#6 2012-10-31 20:35:10

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

@ColePie - I thought that tmpfiles are managed to run at boot by default and presumably taken down at shutdown. It isn't clear from the man page to me.

manpage wrote:

DESCRIPTION
systemd-tmpfiles uses the configuration files from the above directories to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as /run or /tmp.

... if these are indeed created in /tmp or /run (tmpfs), I don't see why they need to be removed at reboot/shutdown since they are volatile anyway.

Last edited by graysky (2012-10-31 20:37:09)

Offline

#7 2012-10-31 21:01:56

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

ColdPie wrote:

I think you want to use the "w" action. So you'd create, say, /etc/tmpfiles.d/boot.conf that contains:

w /sys/class/scsi_host/host0/link_power_management_policy - - - - min_power

I tried this, rebooted, but it did not seem to work for me. In /etc/tmpfiles.d/boot.conf

w /sys/class/scsi_host/host0/link_power_management_policy ---- min_power

But when I reboot I get

cat /sys/class/scsi_host/host0/link_power_management_policy
max_performance

Offline

#8 2012-10-31 21:08:53

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,725
Website

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

graysky wrote:
WonderWoofy wrote:

Also, these things can pretty easily be done with /etc/udev/rules.d/ though it may take a few minutes longer to learn how to write a udev rule.  I personally use udev rules, and they work great.

I'm curious what things you are doing with udev rules?  Can you describe and post a few examples?

Can't comment on WonderWoofy's set up, but I use udev rules to set my SSDs' elevators to noop:

$ cat /etc/udev/rules.d/10-ssd.rules 
ACTION=="add|change", KERNEL=="sda", SUBSYSTEM=="block", ATTR{size}=="234441648", ATTR{queue/scheduler}="noop"
ACTION=="add|change", KERNEL=="sdb", SUBSYSTEM=="block", ATTR{size}=="234441648", ATTR{queue/scheduler}="noop"

I would imagine that setting the values of other devices attributes (i.e. to enable power-saving modes or whatever) could be done in a similar way.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#9 2012-10-31 21:14:06

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

maggie wrote:
w /sys/class/scsi_host/host0/link_power_management_policy ---- min_power

Your problem is your syntax: you need to add spaces to the block of dashes.

Offline

#10 2012-11-01 05:46:40

Seifur
Member
Registered: 2012-08-10
Posts: 2

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

You could read the manpage: 'man 5 tmpfiles.d' or http://0pointer.de/public/systemd-man/tmpfiles.d.html

Offline

#11 2012-11-01 20:17:40

maggie
Member
Registered: 2011-02-12
Posts: 255

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

Thank you everyone!

Offline

#12 2012-11-03 14:25:27

boomshalek
Member
Registered: 2007-10-12
Posts: 113

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

WorMzy wrote:
$ cat /etc/udev/rules.d/10-ssd.rules 
ACTION=="add|change", KERNEL=="sda", SUBSYSTEM=="block", ATTR{size}=="234441648", ATTR{queue/scheduler}="noop"
ACTION=="add|change", KERNEL=="sdb", SUBSYSTEM=="block", ATTR{size}=="234441648", ATTR{queue/scheduler}="noop"

# this set a noop scheduler for non-rotating devices (SSDs etc), good because you should not use noop for normal storage discs
ACTION=="add", SUBSYSTEM=="block", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop"

Offline

#13 2012-11-03 15:22:02

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

graysky wrote:

I'm curious what things you are doing with udev rules?  Can you describe and post a few examples?

Sorry I missed this past for a few days graysky.  I use udev rules for my scheduler (though I now no longer have rotational disks in my computer):

% cat 60-scheduler.rules
## set deadline scheduler for non-rotating disks
ACTION=="add", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop"

# set deadline scheduler for non-rotating disks
ACTION=="add", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"

I also use one for my backlight.  I had a tmpfile for this, but it stopped working 100% of the time.  So I whipped this up, and it always seems to work.  Not sure why my tmpfile stopped, or if it would work again, or if I did something stooopid to make it not work.  Bua anyway:

% cat 44-backlight.rules
ACTION=="add", KERNEL=="acpi_video0", SUBSYSTEM=="backlight", SUBSYSTEMS=="pci", DRIVERS=="i915", ATTR{brightness}="2"

My trackpoint was super slow.  So I made this.  It takes a while for this actual path to show up.  In fact, I think that it doesn't actually show up until X is started.  So I had to use a udev rule here.  Also if I don't have the graphical target enabled, it just fails, as it will only wait for so long.  So here you go:

% cat 98-trackpoint.rules
KERNEL=="serio2", SUBSYSTEM=="serio", DRIVER=="psmouse", WAIT_FOR="/sys/devices/platform/i8042/serio1/serio2/sensitivity", ATTR{sensitivity}="190"

I also don't use wake on lan.  So I made this:

 cat 52-eth0wol.rules
ACTION=="add", KERNEL=="eth0", SUBSYSTEM=="net", RUN+="/usr/sbin/ethtool -s eth0 wol d"

Offline

#14 2012-11-08 20:16:48

Jurassic
Member
Registered: 2006-10-31
Posts: 54

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

Did the OP get an answer to his question?
I have just one simple line in /etc/tmpfiles.d/fix-apple-kb-fn-keys.conf and it doesn't work.
Do these files require any special permissions?

w /sys/module/hid_apple/parameters/fnmode - - - - 2

Arch linux

Offline

#15 2012-11-08 20:21:58

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

@Jurassic, maybe if you put the module that controls the keyboard into your intramfs, the path might exist earlier?  Also, in the tmpfiles.d man page, there is the option 'f' which says that it will creat a file if it does not yet exist and optionally write a parameter to it.

Offline

#16 2012-11-08 20:45:24

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

the hid_apple module has a parameter for this, so you may just want to set the option via a /etc/modprobe.d/ file. If the module is loaded in initramfs, you will have to add the modprobe.d file to FILES in /etc/mkinitcpio.conf and rebuild the initramfs.

$ modinfo hid_apple | grep fnmode

Offline

#17 2012-11-13 03:01:29

Jurassic
Member
Registered: 2006-10-31
Posts: 54

Re: Help with systemd /etc/tmpfiles.d to run commands on startup [FIXED]

Yeah, eventually I found the arch wiki and followed it. Was just curious why it didn't work with temp files, perhaps because the path didn't exist as WonderWoofy pointed out? Thanks guys.


Arch linux

Offline

Board footer

Powered by FluxBB