File Permissions on Recordings

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

Post Reply
nello
Junior
Posts: 27
Joined: Sun Mar 08, 2015 7:33 pm
United States of America

File Permissions on Recordings

Post by nello »

I'm running MythTV with a post-processing ("User Job") script under the mythtv user to transcode and do other things to recordings. Once the processing is done, I want the script delete the original recording; here's an example of a recording file showing its permissions:

Code: Select all

-rw-r--r-- 1 root mythtv 2560860424 Apr 29 07:30 1111_20150429120000.mpg
My script is unable to delete the original recording (using rm), apparently because the user mythtv doesn't have write permission.

Can someone tell me how to change the permissions with which recordings are written?

I presume that recordings are written by the user mythtv (though that doesn't explain why root is the owner).

Here's the mythtv home directory:

Code: Select all

$ ls -al ~/
total 129
drwxrwxr-x 7 mythtv mythtv 17 Apr 28 20:42 .
drwxr-xr-x 8 root wheel 8 Apr 23 18:21 ..
-rwxrwxr-x 1 mythtv mythtv 102 Apr 23 18:22 .Xauthority
-rwxrwxr-x 1 mythtv mythtv 3200 Apr 23 18:22 .bash_history
-rw-r--r-- 1 mythtv mythtv 116 Apr 28 20:42 .bash_profile
-rwxr-xr-x 1 mythtv mythtv 270 Apr 23 21:00 .bashrc
drwxrwxr-x 2 mythtv mythtv 3 Apr 23 18:22 .config
-rwxrwxr-x 1 mythtv mythtv 965 Apr 23 18:22 .cshrc
drwxrwxr-x 2 mythtv mythtv 3 Apr 23 18:22 .dvdcss
-rwxrwxr-x 1 mythtv mythtv 35804 Apr 23 18:22 .history
-rwxrwxr-x 1 mythtv mythtv 148 Apr 23 18:22 .k5login
-rwxrwxr-x 1 mythtv mythtv 296 Apr 23 18:22 .login
-rwxrwxr-x 1 mythtv mythtv 1160 Apr 23 18:22 .mysql_history
drwxrwxr-x 11 mythtv mythtv 13 Apr 23 18:22 .mythtv
-rwxrwxr-x 1 mythtv mythtv 300 Apr 28 18:10 .profile
drwxrwxr-x 3 mythtv mythtv 6 Apr 23 18:22 .subversion
drwxrwxr-x 2 mythtv mythtv 2 Apr 23 18:22 .xmltv
I've tried entering umask 113 (to produce -rw-rw-r--) in the following files:

Code: Select all

~/.profile
~/.bashrc
~/.bash_profile
But permissions on new files don't change; they are always -rw-r--r-- as you can see from this file I created from the mythtv user in nano:

Code: Select all

-rw-r--r-- 1 mythtv mythtv 26 Apr 28 20:43 abc.txt
And yes, I logged out of mythtv and logged back in using this command from root:

Code: Select all

su mythtv
How can I change the permissions with which recordings are written? If it involves umask, where to I enter it?

Thank you for your time and attention.

- nello
nello
Junior
Posts: 27
Joined: Sun Mar 08, 2015 7:33 pm
United States of America

Re: File Permissions on Recordings

Post by nello »

Okay, I guess the real issue is that the mthybackend is running as root instead of mythtv:

Code: Select all

root@mythtv:~ # ps aux | grep mythtv
root   6211  0.0  0.4 483508 117360 ??  INsJ  7:28PM 22:28.51 /usr/local/bin/mythbackend -d --logpath /var/log/mythtv
root  54434  0.0  0.0  16332   1908  0  RL+J  2:00PM  0:00.00 grep mythtv
root@mythtv:~ # 
These pages all give similar instructions, but I can't find the configuration file they specify on FreeNAS:
Gentoo Linux
http://ommolketab.ir/aaf-lib/djmavexl8w ... kpui8v.pdf (page 111)
/etc/conf.d/mythbackend
MYTH_USER=mythtv

Arch Linux
https://wiki.archlinux.org/index.php/MythTV
MBE_USER='mythtv'
/etc/conf.d/mythbackend

Arch Linux
https://github.com/haboque/archlinuxarm ... backend.rc
mythbackend.rc
MBE_USER='mythtv'

Fedora
https://www.mythtv.org/wiki/Fedora_init.d_mythbackend
/etc/rc.d/init.d/mythbackend
MBE_USER='root'

Can anyone tell me how FreeNAS sets the user associated with running mythbackend?
User avatar
dekarl
Developer
Posts: 228
Joined: Thu Feb 06, 2014 11:01 pm
Germany

Re: File Permissions on Recordings

Post by dekarl »

nello wrote:Okay, I guess the real issue is that the mthybackend is running as root instead of mythtv:

Code: Select all

root@mythtv:~ # ps aux | grep mythtv
root   6211  0.0  0.4 483508 117360 ??  INsJ  7:28PM 22:28.51 /usr/local/bin/mythbackend -d --logpath /var/log/mythtv
root  54434  0.0  0.0  16332   1908  0  RL+J  2:00PM  0:00.00 grep mythtv
root@mythtv:~ # 
These pages all give similar instructions, but I can't find the configuration file they specify on FreeNAS:
...
Can anyone tell me how FreeNAS sets the user associated with running mythbackend?
I'm not sure if that is a PC BSD PBI (can't find the source) or a FreeBSD port that you are runnning on FreeNAS...
But the FreeBSD port appears to run mythbackend as root by default... you can change that in /etc/rc.conf by setting mythbackend_user="mythtv".
nello
Junior
Posts: 27
Joined: Sun Mar 08, 2015 7:33 pm
United States of America

Re: File Permissions on Recordings

Post by nello »

I'm running FreeNAS ver 9.3x

The file I was looking for is:

Code: Select all

/usr/local/etc/rc.d/mythbackend
In the following line from this script, I changed root to mythtv

Code: Select all

: ${mythbackend_user="root"}
Also, based on the content of the mythbackend script, I made the following ownership/permission changes

Code: Select all

root@mythtv:/var/log # chown mythtv:wheel mythtv
root@mythtv:/var/log # chmod 755 mythtv
After stopping and starting the Jail mythbackend is now running under mythtv:

Code: Select all

root@mythtv:~ # ps aux | grep mythtv
mythtv 71337  0.0  0.2 392244  79272 ??  SsJ  7:41PM 0:00.55 /usr/local/bin/mythbackend -d --logpath /var/log
mythtv 71619  0.0  0.2 365160  71760 ??  IsJ  7:41PM 0:00.66 /usr/local/bin/mythlogserver --daemon --verbose
root   73209  0.0  0.0  16332   1940  0  S+J  7:42PM 0:00.00 grep mythtv
root@mythtv:~ #
Last edited by nello on Sun May 03, 2015 3:33 pm, edited 1 time in total.
User avatar
bill6502
Developer
Posts: 2323
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: File Permissions on Recordings

Post by bill6502 »

Hi,

Seems odd that /usr/local/bin/mythlogserver is running unless you're
on 0.26. 0.27 should use ./configure --disable-mythlogserver ... See:
https://www.mythtv.org/wiki/Mythlogserver .

I wouldn't use rm in your User Job. That leaves stale metatddata. Try:
curl --data ChanId=<chanid> --data StartTime=<starttime> <BE>:6544/Dvr/RemoveRecorded
or go to the Wiki and look for the Python bindings. Like deleteRecording on this page:
https://www.mythtv.org/wiki/0.25_Python ... n_Handlers
nello
Junior
Posts: 27
Joined: Sun Mar 08, 2015 7:33 pm
United States of America

Re: File Permissions on Recordings

Post by nello »

bill6502 wrote:Seems odd that /usr/local/bin/mythlogserver is running unless you're
on 0.26. 0.27 should use ./configure --disable-mythlogserver ... See:
https://www.mythtv.org/wiki/Mythlogserver .
I installed MythTV on FreeNAS 9.3.x using:

Code: Select all

pkg install mythtv
I thought the distro included version .27 but I'm not sure.

How do I check the version of what I've installed?


bill6502 wrote:I wouldn't use rm in your User Job. That leaves stale metatddata. Try:
curl --data ChanId=<chanid> --data StartTime=<starttime> <BE>:6544/Dvr/RemoveRecorded
or go to the Wiki and look for the Python bindings. Like deleteRecording on this page:
https://www.mythtv.org/wiki/0.25_Python ... n_Handlers
You make a good point about keeping the database and the files in sync. I didn't know about these curl commands; thank you for introducing them to me.

In my particular case, the User Job script that I wrote creates a new video file; the commercials are stripped (using mythcommflag, mythutil, and mythtranscode) and it's transcoded to H264 (using HandBrakeCLI). I'm already updating the file name and size in the database to correspond to the transcoded file. Is there any other metadata that I need to update before removing the original video file? I haven't figured out, for example, how to change the recording's "Length" (play time duration) displayed in the list of Recorded Programs (http://<mythtv-ip-address>/tv/recorded)

Thank you again for your reply.
nello
Junior
Posts: 27
Joined: Sun Mar 08, 2015 7:33 pm
United States of America

Re: File Permissions on Recordings

Post by nello »

Yes, you are correct. By default the mythbackend runs as root. However, my User Job is running as mythtv. I don't know why the User Job isn't running under the same user as mythbackend. I followed these instructions for setup:

https://forums.freenas.org/index.php?th ... htv.19131/

In any case, unless both mythbackend and User Jobs run under the same user, there are ownership/permission problems with any User Job script that tries to modify the recordings.
User avatar
bill6502
Developer
Posts: 2323
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: File Permissions on Recordings

Post by bill6502 »

To find the version, type: mythbackend --version (I see in the
web page you cited, the 0.26 is mentioned and if that's the case,
it would explain why mythlogserver is running.) If it's 0.27, then
the configure option mentioned above wasn't used and it should
have been (0.28-pre builds with the logserver off by default.)

If you're doing an rm on a file that's been replaced by one
that went under commflag/xcode etc. that's OK. I may have
read too much into the comment about using rm.

It's common to start the backend as a root user, but in
the mythbackend command line use the --user mythtv switch.
That way the backend and anything else it starts (e.g. User
Jobs) will run as mythtv. Your 2nd post says you're not doing
that today. [I don't use FreeNAS, so can't offer any info about
it.]
nello
Junior
Posts: 27
Joined: Sun Mar 08, 2015 7:33 pm
United States of America

Re: File Permissions on Recordings

Post by nello »

bill6502 wrote:To find the version, type: mythbackend --version (I see in the
web page you cited, the 0.26 is mentioned and if that's the case,
it would explain why mythlogserver is running.)
Yes, you are correct that the tutorial specified version 0.26. However, I was pretty sure that I went for the latest versions of all the software I installed, e.g., MythTV, MySQL, Apache, etc. And apparently I did pick up MythTV 0.27:

Code: Select all

root@mythtv:/ # mythbackend --version                                           
Please attach all output as a file in bug reports.                              
MythTV Version : 5a5e1cd                                                        
MythTV Branch : fixes/0.27                                                      
Network Protocol : 77                                                           
Library API : 0.27.20140103-1                                                   
QT Version : 4.8.6                                                              
Options compiled in:                                                            
 freebsd profile use_hidesyms using_oss using_backend using_bindings_perl using_
bindings_python using_bindings_php using_dvb using_frontend using_hdhomerun usin
g_ceton using_hdpvr using_ivtv using_libcrypto using_lirc using_mheg using_openg
l using_opengl_video using_qtwebkit using_qtscript using_taglib using_v4l2 using
_v4l1 using_x11 using_xrandr using_xv using_profiletype using_mythlogserver usin
g_bindings_perl using_bindings_python using_bindings_php using_mythtranscode usi
ng_opengl using_vdpau using_ffmpeg_threads using_mheg                           
root@mythtv:/ #    


If it's 0.27, then the configure option mentioned above wasn't used and it should
have been (0.28-pre builds with the logserver off by default.)
So if I'm running 0.27, what should I do to get rid of logserver?

It's common to start the backend as a root user, but in
the mythbackend command line use the --user mythtv switch.
That way the backend and anything else it starts (e.g. User
Jobs) will run as mythtv. Your 2nd post says you're not doing
that today. [I don't use FreeNAS, so can't offer any info about
it.]
I didn't know about this switch; thank you for pointing it out to me.

But, at this point, since I changed the user in /usr/local/etc/rc.d/mythbackend I don't think I need to use this switch, right?
User avatar
bill6502
Developer
Posts: 2323
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: File Permissions on Recordings

Post by bill6502 »

Two options to prevent mythlogserver from running. The best is to
tell your packager to rebuild with ./configure --disable-mythlogserver ...
and the 2nd is for you to run with the --nologserver switch but all logs
will then go to the console ONLY so you'd have to redirect the output
yourself (I don't really like that option.) To be clear, this isn't the cause
of your permissions issue, just something I noted. See the mythlogserver
Wiki above for the why and more detail.

And, no, if the rc.local solution is working, no need to change again. You
should see all of your recordings owned by mythtv:mythtv and processes
spawned should do the same.
Post Reply