[mythtv-users] CTRL-ALT-BACKSPACE

Stephen Worthington stephen_agent at jsw.gen.nz
Sun Mar 10 02:38:47 UTC 2019


On Sat, 9 Mar 2019 14:17:50 -0800, you wrote:

>On Sat, Mar 9, 2019 at 1:20 PM Allen Edwards <allen.p.edwards at gmail.com>
>wrote:
>
>>
>>
>> On Fri, Mar 8, 2019 at 6:57 PM Stephen Worthington <
>> stephen_agent at jsw.gen.nz> wrote:
>>
>>> One alternative is to use lirc to assign a button on your remote to
>>> kill mythfrontend.real.  Lirc can be set up to run scripts using
>>> irexec.  The script would do a ps -e and find any running copies of
>>> mythbackend.real and kill them.  Then the mythfrontend script would
>>> see that mythfrontend.real had died and would restart it.
>>>
>>
>>
>Stephen
>I have tried this without success.  Here is what I did.
>1) I modified a key config action to escape
>2) I verified that the key was now the escape key
>3) I  modified the same key definition to run irexec and changed the config
>action to "killall mythfrontend.real"
>4) The key did nothing. Myth did not close and the pid did not change
>5) I copied the config action to a terminal and it killed mythfrontend
>
>By the way, myth does not restart when I kill it.
>
>This is not exactly what you told me to do but it seemed like it should
>work.

>Correction: What I did was verify that I could change a key and test it,
>then put an action that I verified would kill mythfrontend in and set the
>key to irexec. Didn't do anything.

Lirc runs irexec, not a key setting in MythTV.  In /home/<mythfrontend
user>, you should find a file .lircrc that looks something like this:

root at mypvr:/home/stephen# cat .lircrc
#Custom lircrc generated via mythbuntu-lirc-generator
#All application specific lircrc files are within ~/.lirc
include ~/.lirc/mythtv
include ~/.lirc/mplayer
include ~/.lirc/xine
include ~/.lirc/vlc
include ~/.lirc/xmame
include ~/.lirc/xmess
include ~/.lirc/totem
include ~/.lirc/elisa
include ~/.lirc/irexec

That is the file that lirc loads by default to set up all its
keystrokes.  By convention, a separate file is used for the setup for
each program that uses lirc, but the actual specification of the
programs is done on the "prog =" lines inside those files, so you can
mix setting for different programs in one lirc config file if you
like.  My remote is using the devinput driver, so for a lirc key
config to do anything, it needs a "remote = devinput" line.  Here are
the first three key configs in my /home/stephen/.lirc/mythtv file:

begin
    remote = devinput
    prog = mythtv
             # Guide key
    button = KEY_EPG
#    config = S
    config = Ctrl+Alt+G
    repeat = 0
    delay = 0
end

begin
    remote = devinput
    prog = mythtv
    button = KEY_EXIT
    config = Escape
    repeat = 0
    delay = 0
end

begin
    remote = devinput
    prog = mythtv
    button = KEY_OK
    config = Return
    repeat = 0
    delay = 0
end

begin
    remote = devinput
    prog = mythtv
    button = KEY_RIGHT
    config = Right
    repeat = 1
    delay = 1
end

So what the first one of those does is to say that when lirc receives
a KEY_EPG input from the devinput driver, then if the program with the
lirc name "mythtv" is attached to lirc at the time, it should send a
Ctrl-Alt-G keystroke to that program.  Then inside mythfrontend (which
is running with the lirc name "mythtv"), it will receive the
Ctrl-Alt-G keystroke, look up its keystroke configs from the database
and see that (in my setup) it should jump directly to the Programme
Guide:

MariaDB [mythconverg]> select * from jumppoints where keylist like
'%alt+g%';
+---------------+-------------+------------+----------+
| destination   | description | keylist    | hostname |
+---------------+-------------+------------+----------+
| Program Guide | NULL        | Ctrl+Alt+G | mypvr    |
+---------------+-------------+------------+----------+
1 row in set (0.00 sec)


Here is an example with irexec:

begin
    remote = devinput
    prog = irexec
    button = KEY_YELLOW
    config = echo "This is the Yellow key"
    repeat = 0
    delay = 0
end

What that does is when a KEY_YELLOW (teletext key) keystroke is
received from the devinput driver, then if irexec is running and
attached to lirc, then send irexec the keys in the "config =" line. So
irexec will receive a line of text containing the echo command, which
it will then execute.  For this to do anything, you need to be running
irexec in the background as the same user that mythfrontend runs from.
I think you said you are running Ubuntu 16.04, so the best way to run
irexxec there is from systemd.  But the lirc package in 16.04 does not
set that up for you.  In 18.04 the package installs a
/lib/systemd/system/irexec.service file for you to modify to make this
work:

root at mypvr:/lib/systemd/system# cat irexec.service
[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)

[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=simple
ExecStart=/usr/bin/irexec /etc/lirc/irexec.lircrc

[Install]
WantedBy=multi-user.target

So what you need to do is to install an irexec.service file for your
system.  The easy way to do that now (as long as the 16.04 systemd
version is late enough, which I think it is), is to run this command:

sudo systemctl --full edit irexec.service

I have never used the --full option before, so I do not know what it
will do if the original irexec.service file is not present, so if you
get an error with that command, remove the --full option.  The command
should open your default system editor with the correct irexec.service
file open, which should be empty in your case.  Paste in this text
with the name of your mythfrontend user subsituted in two places:

[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)

[Service]
user=<your mythfronted user>
group=mythtv

; 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=simple
ExecStart=/usr/bin/irexec /home/<your mythfrontend user>/.lirc/irexec

[Install]
WantedBy=multi-user.target

Save that and exit from the editor.  Then run these commands:

sudo systemctl enable irexec.service
sudo systemctl start irexec.service
sudo systemctl status irexec.service

The status command should show irexec has started and is running.  If
that has not worked, then you will need to fix whatever errors the log
output shows.

Then you can edit the /home/<your mythfrontend user>/.lirc/irexec file
to put in the commands you want to be able to run from remote buttons.
Each time you change that file, you need to do this command to restart
irexec so it re-reads the config file:

sudo systemctl restart irexec.service

If you want to save a little typing, ".service" is what systemctl
defaults to if the unit type is left off, so you can shorten the
systemctl commands like this:

sudo systemctl restart irexec

To test if irexec is working properly, set it up with a echo command
like my example, then open a terminal on X and press the remote button
to execute the irexec echo command.  You should see the echo text
appear in the terminal window.  Once that is working, you can try the
"killall mythfrontend.real" command.

The last time I have actually used irexec like this was in 14.04, so I
have never actually tested the above setup via systemd.  So there
could be a bug or two.


More information about the mythtv-users mailing list