Discussion:
[gentoo-user] systemd unit executing but not persistent later in boot
(too old to reply)
Andrew Udvare
2024-04-07 01:40:01 UTC
Permalink
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?
Daniel Frey
2024-04-07 16:10:01 UTC
Permalink
Post by Andrew Udvare
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?
I did, it made no difference.

From what I can tell it is running before lircd.

I have disabled lircd. Ran daemon-reload and rebooted.

For some reason, systemctl is saying it has run and exited successfully
according to the timestamps:

# 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 Sun 2024-04-07 08:56:18 PDT; 1min
36s ago
Duration: 48ms
Process: 295 ExecStart=/usr/bin/ir-keytable -c -p rc-6 -w
/etc/rc_keymaps/imon_mce.toml (code=exited, status=0/SUCCESS)
Main PID: 295 (code=exited, status=0/SUCCESS)
CPU: 19ms

Apr 07 08:56:18 htpclivingrm systemd[1]: Started Add custom keymap to
iMon remote.
Apr 07 08:56:18 htpclivingrm ir-keytable[295]: Read imon_mce table
Apr 07 08:56:18 htpclivingrm ir-keytable[295]: Old keytable cleared
Apr 07 08:56:18 htpclivingrm ir-keytable[295]: Wrote 76 keycode(s) to driver
Apr 07 08:56:18 htpclivingrm ir-keytable[295]: Protocols changed to rc-6
Apr 07 08:56:18 htpclivingrm systemd[1]: ir-key-map.service: Deactivated
successfully.


But, it doesn't actually change the protocol. It says it has
"ir-keytable[295]: Protocols changed to rc-6" but when you check
manually as root it really hasn't:

# 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

...and I have no idea why. Until this works, lircd will not work.

If you run it manually, it will update it. It shows in the log and more
importantly, if you check with ir-keytable you can see it was successful.

It's bizarre.

I even tried adding User= and Group= in the [Service] context and it
made no difference.

Dan
Daniel Frey
2024-04-07 20:00:01 UTC
Permalink
Post by Andrew Udvare
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?
OK, I have finally sorted out the IR keymap/lircd/irexec/LCDd problems.

It turns out the systemd units as shipped just simply do not work, at
least for my hardware.

The custom unit I made to apply a new keytable and protocol change was
working fine. After a lot of reading about systemd units and also poring
through logs, I discovered udev was triggering something related to the
LCD/IR module - my custom unit was running before this happened but the
udev trigger reset it to defaults (for whatever reason.)

In order to fix that, I had to change my unit to this:

[Unit]
Description=Add custom keymap to iMon remote
Requires=systemd-udevd.service systemd-udev-settle.service
systemd-udev-trigger.service
After=systemd-udevd.service systemd-udev-settle.service
systemd-udev-trigger.service
Before=lircd.service inputlircd.service irexec.service

[Service]
RemainAfterExit=true
ExecStart=/usr/bin/ir-keytable -c -p rc-6 -w /etc/rc_keymaps/imon_mce.toml

[Install]
WantedBy=multi-user.target
RequiredBy=lircd.service irexec.service


This made the keymap change work reliably.

After this lircd was working normally.

I use lircd so I can use irexec to listen for the power button and just
shut the computer off. Kodi is too finicky and just wouldn't turn off or
it would just logout, even with the polkit policy in the wiki applied.

Now, starting irexec didn't work the the shipped systemd unit either, it
would just exit and not stay running. I fixed that with this custom unit:

[Unit]
Documentation=man:irexec(1)
Documentation=http://lirc.org/html/configure.html
Documentation=http://lirc.org/html/configure.html#lircrc_format
Description=Handle events from IR remotes decoded by lircd(8)
After=lircd.service
Requires=lircd.service

[Service]
; user=lirc
; group=lirc

; Hardening opts, see systemd.exec(5). Doesn't add much unless
; not running as root. If these are applicable or not depends on
; what commands irexec.lircrc invokes.
;
; NoNewPrivileges=true
; MemoryDenyWriteExecute=true
; PrivateTmp=true
; ProtectHome=true
; ProtectSystem=full


Type=forking
ExecStart=/usr/bin/irexec --daemon /etc/lirc/irexec.lircrc

[Install]
WantedBy=multi-user.target


So irexec would start and actually stay running. I did also tell it to
start after lircd (although I'm not 100% sure this matters - it may not.)

Of course the LCD unit wouldn't start and stay running either, again the
systemd unit shipped didn't work so I customized it:

[Unit]
Description=LCDProc (LCDd)
After=network-online.target lircd.service
Requires=lircd.service

[Service]
ExecStart=/usr/sbin/LCDd -c /etc/LCDd.conf
Type=forking

[Install]
WantedBy=multi-user.target

After all this, then Kodi wouldn't start up. I figured out quickly this
was caused by lightdm starting before the network was ready, fixed with
this custom unit:

[Unit]
Description=Light Display Manager
Documentation=man:lightdm(1)
After=systemd-user-sessions.service
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/sbin/lightdm
Restart=always
IgnoreSIGPIPE=no
BusName=org.freedesktop.DisplayManager

[Install]
Alias=display-manager.service


Hopefully this may be helpful to others with HTPCs switching to systemd
from openrc. In openrc nearly all of this customization isn't needed - I
only modified /etc/init.d/lircd in openrc in order to load the keymap
before lircd started.

Dan

Loading...