MiniDLNA Automatic Scan - Fix

Status
Not open for further replies.

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I don't know what MiniDLNA can handle for files or folders.

What I was suggesting was you create another folder within the jail called /music, then you could create a mount point to that location and update subsonic to that same reference. This would leave /media available for videos. You don't even need to use /media, you could create /photos and /videos and /movies, whatever you like. This is just a clean way to separate your media instead of allowing minidlna to fail at some point all the time even though it does work right now. It was only a suggestion which you don't need to take.

Have a good weekend.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Major Update to code.

The code was updated in the first posting again with a major change. Due to the limitation observed by others with directory limitation I have written an alternate scanning method which will automatically switch between normal scanning (using wait_on) and the alternate scanning (actively comparing directories/files).

The downside the the alternate scanning method is if you like sleeping your drives, this will poll your drives and force them to spin up. So none of this may be for you but most people will not hit the limitation and some of those who do, may have their drives running all the time so it will not be an issue for them.

If the old code worked for you then the new code will work the same but it will give you the peace of mind that MiniDLNA will not cycle all the time if you ever do go over the problem limit but you don't need to change anything if it 's working fine for you.

I have another idea in mind to go back to the normal scanning method but I haven't tested it yet and that could be several weeks away or months as it isn't going as well as I expected. I'm getting stuck on one line of code. Does anyone know how to run two instances of the "csh -c" line in the code? Trying to run it twice within the same jail (one in one script and once in a duplicate script with some name changing) causes it to fail.

As usual, feed back, good or bad is always appreciated.
 

hervon

Patron
Joined
Apr 23, 2012
Messages
353
Hi joeschmuck, I'm away from home for a few days because of work. I'll test your updated version later this week and report back. Thanks again for your sustained effort!
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Hi joeschmuck, I'm away from home for a few days because of work. I'll test your updated version later this week and report back. Thanks again for your sustained effort!
I don't think it will provide any benefit to you based on your WDTV problem but it definitely will do no harm. I wish I could figure out a fix for that but if it creates files (hidden or not) then it will be detected.

One thing, I don't know if the alternate method will pick up hidden files so maybe this could work for you if you leave your drives running all the time. You would have to change the YellowAlert to 10 and RedAlert value to 5, this would force the alternate method all the time. You can play with the settings in the scanmedia_alternate() section, look for the two lines that start with "ls -RlT" and you need the -R but you could play with the other switches. Here is a link to the available options... http://www.unix.com/man-page/FreeBSD/1/ls/

Let me know what you find out if you go down this path.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
MiniDLNA Plugin Fix (8.3.0-Release and p-1)

EDIT: This problem has been corrected in the FreeNAS 8.3.1-Release version plugin.

There is a slight problem with the MiniDLNA plugin which prohibits it from turning off/on after boot/reboot of your system. This is already fixed in the source code but will not be available until the next FreeNAS version comes out, assuming the source is compiled again. I thought it would be in the 8.3.0-RELEASE-p1 but it was not. This problem is why I needed to use the 'pkill' command in the script in posting #1. Since I don't know what possible side effects there could be, if any, with using pkill, I am posting the fix to the minidlna plugin until the 8.3.1-Release comes out. There is no need to change the scanmedia script since minidlna will stop properly and when the pkill command is executed, it will just fail (blind to you) because the program isn't running. One thing to note, if you have to reinstall MiniDLNA 8.3.0, you will need to reapply this fix of course.

1) Go back into jail, I use SSH (you could use the shell or console) to get into the jail using the following command: jexec `jls jid` /bin/tcsh
2) Type 'cd /usr/local/etc/rc.d/'
3) Type 'ee minidlna'
4) Locate the lines
Code:
        echo -n 'Stopping minidlna.'
         if [ -f "${pidfile}" ]
         then
                kill -QUIT $(cat "${pidfile}")
                rm -f ${pidfile}
                res=$?
         else
                killall -QUIT minidlna
                res=$?
         fi

5) And remove the "-QUIT" from both lines above so it looks like this...

Code:
        echo -n 'Stopping minidlna.'
         if [ -f "${pidfile}" ]
         then
                kill $(cat "${pidfile}")
                rm -f ${pidfile}
                res=$?
         else
                killall minidlna
                res=$?
         fi

6) Press the ESCape key and save the file.
7) Type 'exit'.
8) If you're ready, type 'reboot'.

If you really want to you can adjust the scanmedia script to remove the 'pkill minidlna' line but it really isn't required. I did it in mine to just have a cleaned up script.

EDIT: Even though the fix for this was implemented well before 8.3.0-RELEASE-p1 came out, it appears the plugin was not rebuilt so it does not contain the corrected MiniDLNA plugin. So this fix still applies.
 

SMTasci

Cadet
Joined
Nov 27, 2012
Messages
3
Hi guys,

I'm pretty new to Freenas so please excuse me if this is a stupid question. How do I paste the script in to the shell? It wont let me use Ctrl + v or right click.

I've also tried using PuTTY to access via SSH but I'm unable to access the jail folder using the command jexec `jls jid` /bin/tcsh

What am I doing wrong?

Thanks

Sabri
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
While in Putty SSH type 'jls' and it will come back with a number and the jail name, for this example the number will be 1 (what it should be after a reboot on a basic system). Next type 'jexec 1 /bin/tcsh'. You should now be in the jail.

If you turn off and on the Plugins in the Services tab, it will increment the jail number for each time. So if you turned your Plugins off and on three times after a reboot, the jail will be a 4. You get the idea. The only thing I can think of why it isn't working is if you didn't copy and paste it and maybe got the letters wrong. here they are in uppercase JLS JID. Sometimes lowercase can be a headache.

As for cutting and pasting, in Putty to paste something you highlight it, that is all. To paste you need to have your cursor where you want the test to be placed and then right click your mouse and it will paste.
 

SMTasci

Cadet
Joined
Nov 27, 2012
Messages
3
Thanks I tried that and now its coming back with the following...

Welcome to FreeNAS
[Sabri@freenas] ~> jls
JID IP Address Hostname Path
4 - Software /mnt/Server/jail/Software
[Sabri@freenas] ~> jexec 4 /bin/tcsh
jexec: jail_attach(4): Operation not permitted
[Sabri@freenas] ~>

Any ideas?

Thanks!!
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
You need to be root.
 

SMTasci

Cadet
Joined
Nov 27, 2012
Messages
3
Thanks again!

I forgot to tick the box that said 'Login as root with password'. Sorted it now and everything seems to be working fine. Thanks for your time and effort, much appreciated!!

Sabri
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Thanks again!

I forgot to tick the box that said 'Login as root with password'. Sorted it now and everything seems to be working fine. Thanks for your time and effort, much appreciated!!

Sabri
Glad it's working for you.
 

Deaks2

Dabbler
Joined
Jun 30, 2012
Messages
12
This is a really nice script. Excellent instructions too. It is working like a charm on my v8.2.0 box.

Now if only a media scan didn't take 20 mins :p
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Thanks, I appreciate the feedback. I try to make the instruction "Sailor Proof" even though that is an impossible goal.

20 minutes, you must have quite a bit of stuff.
 

white_flag

Dabbler
Joined
Jul 18, 2012
Messages
16
anyone has idea Why (after I apply this patch) the minidlna is restarting all the time?
the plug ins are installed on USB stick of 8gb with 2 ZFS databases.

thx
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
anyone has idea Why (after I apply this patch) the minidlna is restarting all the time?
the plug ins are installed on USB stick of 8gb with 2 ZFS databases.

thx
Just returned from a trip. Unfortunately you do not give much information. You should read the thread again as I suspect you are writing to the area being monitored by the script which will force a restart of MiniDLNA. I understand that if you use WDTV that you cannot use this script due to the way it writes temp files to the system.
 

hervon

Patron
Joined
Apr 23, 2012
Messages
353
anyone has idea Why (after I apply this patch) the minidlna is restarting all the time?
the plug ins are installed on USB stick of 8gb with 2 ZFS databases.

thx

I think I experienced something similar with my WDTVLive because the WDTVLive SOMETIMES writes to a hidden folder to resumes movies. I stayed with a previous version from joeschmuck that looked at specific folders for modifications.

Here it is :
#!/bin/sh
# File name 'scanmedia'
# Place this file into /etc/rc.d
# Edit /etc/rc.conf to include scanmedia_enable="YES"

. /etc/rc.subr

name="scanmedia"
rcvar=scanmedia_enable

PATH="$PATH:/usr/local/bin"

start_cmd="${name}_start"
stop_cmd=":"

load_rc_config $name
eval "${rcvar}=\${${rcvar}:-'NO'}"

scanmedia_start()
{
while :; do
# Wait_on will trigger on any event which write to the directory listed. The default directory for
# the minidlna plugin is /media. Wait_on does not trigger on subdirectories so those need to be
# added if desired as follows: wait_on -w /folder1 /folder1/subfolder

wait_on -w 'media' '/media/Movies' '/media/Movies/1 New Movies!' '/media/Music' '/media/Movies/Alain'

# Since wait_on triggers on the start of a write event and not the ending, sleep long enough to
# ensure the changes have been written, if not this script will only repeat itself but we should
# try to minimize it. 5 Minutes is reasonable so 300 seconds=5 minutes. You pick your own time.
# For testing I suggest a value of 10 seconds.

sleep 300

# We must use pkill, to stop the minidlna service nothing else quite works properly.

pkill minidlna

# We wait 10 seconds to allow the service lots of time to stop.

sleep 10

# And now to start up the service again.

service minidlna start

done
}

run_rc_command "$1"
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Thanks for posting that. It made me realize that I might just need to retain the changes as versions within the thread vice replacing the script each time.
 

Ensconc3

Cadet
Joined
Dec 13, 2012
Messages
3
I am getting a red alert, because the script detects a folder name length of 805799. When i read the altscan1.dat file, it does not have a foldername length of even +300. Is that because the folder with problems does not get saved in the altscan file?
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I am getting a red alert, because the script detects a folder name length of 805799. When i read the altscan1.dat file, it does not have a foldername length of even +300. Is that because the folder with problems does not get saved in the altscan file?
No, it is not for a single folder name or file name, it's the length of all the paths to each folder being monitored. I suspect you have a lot of music files buried in a lot of folders. So the script will still work fine, you may want to adjust the alternate scan rate variable to meet your needs. Realize that if you want to have your drives sleep (spin down) when not in use, the Alternate Scan method will not allow for it as it's very much an active scan that occurs at the periodicity of AlternateScanRate (default is 30 minutes). If your dives are going to spin all the time then the default should be fine. Should you ever reorganize your files and the folder length drops below the RedAlert level, normal scanning will resume. Unfortunately lots of music files make it doubtful you will drop below this threshold. I have submitted a request to fix MiniDLNA so it will properly scan without spinning up the drives and maybe someday it will come, maybe not. Periodically I take another stab to find a work around to fix it myself but I don't have all the proper tools or knowledge to just recreate MiniDLNA myself.

I hope that explains it some, if not just ask again, try to rephrase the question.
 

Ensconc3

Cadet
Joined
Dec 13, 2012
Messages
3
Yes, that explains a lot :). I have changed the scanning period to 8 hours, because it appears mine is scanning for 2 hours long and i do not change everything a lot. Thanks!
 
Status
Not open for further replies.
Top