Jump to content

Dealing with paths going away and coming back (Cloud/NAS/etc)


Go to solution Solved by Animosity022,

Recommended Posts

Animosity022
Posted

I'm trying to get my work flow setup properly as I had my first Amazon Cloud Drive (ACD) blip last night when my mounted filesystem went unavailable.

 

I have the normal scheduled tasks that came out of the box for the "Scan Media Library", "Clean Database" ,etc as I have not touched them.

 

My 2 integrations kick off scans when something is downloaded via the API (Sonarr/Radarr) and that seems to do the scan task.

 

When my drive is up, all is good. Things work as expected and life is good.

 

Last night when my mount became inaccessible, I woke up and remedied the issue by remounting it. Since it looks like a 'scan' ran' and maybe the clean via the scheduled tasks, all my remote media seems to need to be rescanned back in again. If things were local, not a big deal. My challenge is that I have about 20TB of data in the cloud currently and this scan takes maybe 30-48 hours to do as it's quite a number of items.

 

So my question is more related as to is this something that can already be handled and my workflow/task schedule is something that's breaking it as in I shouldn't be running something if a path disappears and comes back after a scan? 

 

Or is there a different way I should be dealing with it.

 

The concept in Plex is that if a file goes away, it just marks it as unavailable until the next scan. Upon next scan assuming you haven't "Emptied your trash", it just relinks it as if all the size/timestamp/etc is good and goes on.

 

Hopefully that workflow makes sense as I have to avoid doing a full ffprobe on every media file if a path goes away briefly or it becomes unusable with a remote mount like this. 

 

 

Posted

In your situation, you probably want to disable the automatic discovery and the regular schedule for the scan task and only run that when you are sure the drive is available.

Animosity022
Posted

Hmm. Yeah, that breaks some of the automation in the setup as if I get a new TV show or movie, I have to manually scan it so it shows up.

 

Not a superb solution.

 

Is there a CLI method to kick off a scan from the local server? I can just check to see if 'x' is mounted and check for a few files or something. That would be very workable.

Posted

Emby works on an HTTP API as opposed to command line interface.  There is a way to do it via an API request.

Animosity022
Posted

Maybe @@Luke could toss me a lifeline and let me know if there is a simple way to do this?

I was thinking just a curl request along with an API key or something very simple. I'm not a programmer by any means and was hoping to find something doing a search but didn't turn up any results.

 

I was hoping to just do something like along "curl http://localhost:8096/refreshLibrary"like Couchpotato does:

Code: <CouchPotatoIP>:<Port>/api/<api key>/renamer.scan
Example: 192.168.1.1:8081/api/c49dafa5333146dcaf0745fc50e4f64f/renamer.scan
Posted

Try a POST to:

[IPAddress:port]/Emby/Library/Refresh?api_key=xxxxxxxxxxxx
Animosity022
Posted

I opened a feature request on github in relation to that idea as well.

 

Short term, I was just hoping to do something like this to validate I have a mount, it's writeable and then scan. Just a quick and dirty script that I was going to use via the custom actions in Sonarr/Radarr when something is added.

#!/bin/bash
if grep -qs '/media' /proc/mounts; then
        echo "It's mounted."
        FILE=/media/exists_and_writeable

        if [[ -r $FILE && -w $FILE ]]
        then
                echo "File exists and is writeable"
                echo "Update Library"
        else
                echo "/media is not writeable" | mail -s "/media not writeable" someone@[member="gmail"].com
        fi
else
        echo "It's not mounted." | mail -s "/media not mounted" someone@[member="gmail"].com
fi

I have a "/media" mount on my server which is my ACD drive. I'm sure it can be cleaned up a bit and made better, but that's just a quick example to validate you have a path, it's writable and then kick off a scan.

Animosity022
Posted

 

Try a POST to:

[IPAddress:port]/Emby/Library/Refresh?api_key=xxxxxxxxxxxx

 

I'll try a bit more, but I kept getting 302s on my posts.

curl --request POST 'http://localhost:8096' --data "path=/Emby/Library/Refresh?api_key=APIKEY"

curl --request POST 'http://localhost:8096' --data-binary "path=/Emby/Library/Refresh?api_key=APIKEY"

curl --request POST 'http://localhost:8096' --data-urlencode "path=/Emby/Library/Refresh?api_key=APIKEY"

Server output:

2017-04-12 10:35:23.8407 Info HttpServer: HTTP POST http://localhost:8096/. UserAgent: curl/7.38.0
2017-04-12 10:35:23.8407 Info HttpServer: HTTP Response 302 to 127.0.0.1. Time: 0ms. http://localhost:8096/




2017-04-12 10:36:04.8850 Info HttpServer: HTTP POST http://localhost:8096/. UserAgent: curl/7.38.0
2017-04-12 10:36:04.8850 Info HttpServer: HTTP Response 302 to 127.0.0.1. Time: 0ms. http://localhost:8096/



2017-04-12 10:37:36.4895 Info HttpServer: HTTP POST http://localhost:8096/. UserAgent: curl/7.38.0
2017-04-12 10:37:36.4895 Info HttpServer: HTTP Response 302 to 127.0.0.1. Time: 0ms. http://localhost:8096/


Animosity022
Posted

So I did some searching and compared some of the CouchPotato update and ended up with this from the CLI and it works.

curl -X POST -H "Content-Type: application/json" -d '{"X-MediaBrowser-Token":"APIKEY"}' http://localhost:8096/Emby/Library/Refresh?api_key=APIKEY
2017-04-12 11:13:02.5981 Info HttpServer: HTTP POST http://localhost:8096/Emby/Library/Refresh. UserAgent: curl/7.38.0
2017-04-12 11:13:02.5987 Info TaskManager: Queueing task RefreshMediaLibraryTask
2017-04-12 11:13:02.5987 Info TaskManager: Executing Scan media library
2017-04-12 11:13:02.5987 Info HttpServer: HTTP Response 204 to 127.0.0.1. Time: 1ms. http://localhost:8096/Emby/Library/Refresh
2017-04-12 11:13:02.5987 Info App: Validating media library
  • Like 1
  • Solution
Animosity022
Posted (edited)

So my final solution/script to mark this as solved was to just use the following:

 

- Disable the task for Library Scan

- Use a custom script for "Download/Upgrade" in Connections in Sonarr/Radarr. 

#!/bin/bash
if grep -qs '/media' /proc/mounts; then
    	#echo "It's mounted."
	FILE=/media/exists_and_writeable

	if [[ -r $FILE && -w $FILE ]]
	then
		#echo "File exists and is writeable"
		# Run Emby Library Scan
		curl -X POST -H "Content-Type: application/json" -d '{"X-MediaBrowser-Token":"YOURAPIKEY"}' http://localhost:8096/Emby/Library/Refresh?api_key=YOURAPIKEY
	else
		echo "/media is not writeable" | mail -s "/media not writeable" someone@[member="gmail"].com
	fi
else
    	echo "It's not mounted." | mail -s "/media not mounted" someone@[member="gmail"].com
fi
Edited by Animosity022

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...