Re: [gentoo-user] systemd unit executing but not persistent later in boot

2024-04-06 Thread Andrew Udvare
On Sat, 6 Apr 2024 at 21:32, Daniel Frey  wrote:
> What's even stranger is if I manually start it and restart lircd it works!

Have you tried adding Before=lircd.service in the [Unit] section?



[gentoo-user] systemd unit executing but not persistent later in boot

2024-04-06 Thread Daniel Frey

Hi all,

Still new to systemd and am struggling with a custom unit file.

Some background:

I have a HTPC that requires loading a custom keymap in order for the 
remote to work. It sets up an alternate protocol that the driver 
supports but not defaults to.


In short:

# ir-keytable
Found /sys/class/rc/rc0/ with:
Name: iMON Remote (15c2:0038)
Driver: imon
Default keymap: rc-imon-pad
Input device: /dev/input/event8
LIRC device: /dev/lirc0
Supported kernel protocols: rc-6 imon
-->Enabled kernel protocols: imon
bus: 3, vendor/product: 15c2:0038, version: 0x0001
Repeat delay = 500 ms, repeat period = 125 ms


This protocol needs to change to rc-6. This is done by a simple command:

/usr/bin/ir-keytable -c -p rc-6 -w /etc/rc_keymaps/imon_mce.toml

So my thought was to create a custom Unit:

[Unit]

Description=Add custom keymap to iMon remote

[Service]

ExecStart=/bin/bash -c "exec /usr/bin/ir-keytable -c -p rc-6 -w 
/etc/rc_keymaps/imon_mce.toml"


I've called it ir-key-map.service.

I can see through the status that it is indeed running and applying the 
keymaps and protocol changes:


# systemctl status ir-key-map
○ ir-key-map.service - Add custom keymap to iMon remote
 Loaded: loaded (/etc/systemd/system/ir-key-map.service; enabled; 
preset: disabled)

 Active: inactive (dead) since Sat 2024-04-06 18:17:43 PDT; 6min ago
   Duration: 46ms
   Main PID: 292 (code=exited, status=0/SUCCESS)
CPU: 12ms

Apr 06 18:17:43 htpclivingrm systemd[1]: Started Add custom keymap to 
iMon remote.

   Apr 06 18:17:43 htpclivingrm bash[292]: Read imon_mce table
   Apr 06 18:17:43 htpclivingrm bash[292]: Old keytable cleared
   Apr 06 18:17:43 htpclivingrm bash[292]: Wrote 76 keycode(s) to driver
--> Apr 06 18:17:43 htpclivingrm bash[292]: Protocols changed to rc-6
   Apr 06 18:17:43 htpclivingrm systemd[1]: ir-key-map.service: 
Deactivated successfully.


As the output says, it ran successfully.

lircd also is running after this unit like it's supposed to (snipped 
from `journalctl --unit lircd`:


Apr 06 18:17:43 htpclivingrm systemd[1]: Starting Flexible IR remote 
input/output application support...


However, the remote does not work.

When I log in and check:

# ir-keytable
Found /sys/class/rc/rc0/ with:
Name: iMON Remote (15c2:0038)
Driver: imon
Default keymap: rc-imon-pad
Input device: /dev/input/event8
LIRC device: /dev/lirc0
Supported kernel protocols: rc-6 imon
ARGH -->Enabled kernel protocols: imon
bus: 3, vendor/product: 15c2:0038, version: 0x0001
Repeat delay = 500 ms, repeat period = 125 ms

It's like the unit is running in an isolated environment or something 
which is not at all helpful.


What's even stranger is if I manually start it and restart lircd it works!

`systemctl start ir-key-map`
`systemctl restart lircd`

...and it is set up normally and the remote works:

# systemctl start ir-key-map
# systemctl restart lircd
# ir-keytable
Found /sys/class/rc/rc0/ with:
Name: iMON Remote (15c2:0038)
Driver: imon
Default keymap: rc-imon-pad
Input device: /dev/input/event8
LIRC device: /dev/lirc0
Supported kernel protocols: rc-6 imon
YAY -->Enabled kernel protocols: rc-6
bus: 3, vendor/product: 15c2:0038, version: 0x0001
Repeat delay = 500 ms, repeat period = 125 ms

So why does this not work at boot time? Are these units spawned in an 
environment on their own and thusly not modifying the main system?


I'm quite confused.

In openrc I just edited /etc/init.d/lircd and put the ir-keytable 
command in it before lircd was started and it was working fine.


Can someone give some pointers?

Dan