<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 13, 2024, 9:31 p.m. Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz">stephen_agent@jsw.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, 13 Mar 2024 17:47:00 -0400, you wrote:<br>
<br>
>I have the mythfrontendpre.sh script setup fine and discovering my two<br>
>hdhomerun devices before starting the backend. However, I'm getting<br>
>permission denied on writing /var/log/mythtv/mythbackendpre.log file.<br>
><br>
>A lack of sleep has shot my Linux brain today. I figure I need to touch to<br>
>create an empty file. The other logs in the dir are syslog:adm but what's<br>
>the proper chmod?<br>
><br>
>[reaches for second coffee]<br>
<br>
The syslog:adm permissions on the log files works because the log<br>
messages are being sent to syslog (rsyslogd) on port 514 and the<br>
rsyslogd daemon receives the messages and sorts out where to write<br>
them to, in accordance with its /etc/rsyslog.conf and /etc/rsyslog.d/*<br>
config files.  So the actual file writing is being done by a program<br>
running under user syslog.<br>
<br>
Unfortunately, unless you do something to send messages to rsyslogd in<br>
your script instead of writing directly to a log file, the script<br>
needs access to the /var/log directories and the log file it is<br>
writing to under its own user or group.  This is a complex permissions<br>
problem, depending usually on group memberships.  Your frontend user<br>
will usually belong to the syslog and adm groups, which helps, but<br>
your mythtv user will not.<br>
<br>
So what user and group are being used to run mythfrontendpre.sh?  Is<br>
it run under user mythtv, or your frontend user?<br>
<br>
In practical terms, doing commands like this:<br>
<br>
sudo touch /var/log/mythtv/mylogfile.log<br>
sudo chown syslog:adm /var/log/mythtv/mylogfile.log<br>
sudo chmod a+w /var/log/mythtv/mylogfile.log<br>
<br>
normally works, but it is less than ideal as it allows universal write<br>
access to the log file.  Or running your script as root will always<br>
work.  Or putting your log files in /tmp.  Or writing an "sudoers"<br>
helper script that has the right permissions, and calling that script<br>
from your actual script.  I have done all of the above at various<br>
times for various reasons.  And also written scripts in Python instead<br>
of bash, so I can use Python's excellent logging capabilities, which<br>
includes the ability to send things to syslog.<br>
<br>
It is always possible to use ACLs (Access Control Lists) instead of<br>
the ordinary permissions mechanisms, which allows fine grained access.<br>
See the setfacl and getfacl commands and also "man acl".  Most Linux<br>
distros have ACLs enabled in the kernel now, and the system does use<br>
them in various places, but you normally do not notice as the usual<br>
listing tools like ls do not show the ACLs.  As an example, I run a<br>
mosquitto server (running under user mosquitto), which needs to use my<br>
Let's Encrypt certificates to allow encrypted connections.  So in the<br>
script I run when the certificates are automatically updated, I have<br>
this:<br>
<br>
setfacl -R -m u:mosquitto:rX /etc/letsencrypt/{live,archive}<br>
<br>
which gives the mosquitto user read access to the directory where the<br>
links to the current certificates are (live) and to the directory<br>
where the actual certificate files are (archive).  So to allow<br>
programs running as the mythtv user to write to a log file, this might<br>
work:<br>
<br>
sudo touch /var/log/mythtv/mylogfile.log<br>
sudo chown syslog:adm /var/log/mythtv/mylogfile.log<br>
sudo setfacl -m u:mythtv:rwx /var/log/mythtv/mylogfile.log<br>
<br>
I have not actually tried that setfacl command though - I might have<br>
missed something.<br><br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">HI Stephen, </div><div dir="auto"><br></div><div dir="auto">The script is from here:</div><div dir="auto"><a href="https://www.mythtv.org/wiki/Silicondust_HDHomeRun_setup">https://www.mythtv.org/wiki/Silicondust_HDHomeRun_setup</a><br></div><div dir="auto"><br></div><div dir="auto">It's used to ensure that the Homeruns are running before the backend is started so it's part of the systemd stuff:</div><div dir="auto"><br></div><div dir="auto">/etc/systemd/system/mythtv-backend.service.d/override.conf</div><div dir="auto"><br></div><div dir="auto">[Unit]</div><div dir="auto">After=network-online.target</div><div dir="auto">Wants=network-online.target</div><div dir="auto">[Service]</div><div dir="auto">ExecStartPre=/usr/local/bin/mythbackendpre.sh</div><div dir="auto"><br></div><div dir="auto">The script just does the checks for the HDHomerun(s) and logs it. Unfortunately the wiki entry just contains the vague instruction: "That log file will need write permissions set." </div><div dir="auto"><br></div><div dir="auto">So I guess it needs to be the user that runs systemd? </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
</blockquote></div></div></div>