How to do a script for QNAP NAS that would automatically mount remotes in Plex at Startup

Yep :slight_smile: that is what I am totally missing on this end :slight_smile:

By the way, I was able to mount all the remotes by following step by step this guide: https://bytesized-hosting.com/pages/rclone-gdrive

It was done for people using the bytesized hosting VPS but most of the commands are identical. If you look at the bottom of the page, it will also show you how to setup a startup script but I am not sure if that script will work in my case too.

here comes @thestigma, i can feel it, any second now

It may be completely normal for the file to be empty. This may just mean that this file is only meant to start custom user programs.

I just wanted to know if there was any sort of special formatting to it, but there may not be. I will see if I can look it up, but it is probably just straight bash commands.

you raaaang master?...

Yeah I confirm that the autorun.sh is totally empty and apparently I do not see any formatting. What are exactly bash commands? guys please! patience with me, you gotta learn somehow :slight_smile:

bash is the linux equivalent of Windows (if that's what you are most familiar with) commandline (called batch or cmd).

So it's just some commands in a few lines of text that tel the system to do something. This may be all we need to put in there. Anything that you could type into a terminal window is a valid bash command.

You may want to try to just putting the mounting command directly in that file - then restart the system. Feel free to share the mounting command here if you want us to look over it.

I am googling a bit in the mean-time to see if I can find an actual example of how the autorun.sh should look when it has stuff in it.

From my googling it looks to just be a perfectly standard bash-script that just is set up to run on every bootup:
https://forum.qnap.com/viewtopic.php?t=112970

So yes - all you need to do is put your mounting command into it directly - exactly the same as what you did to start it manually. Then just save the file and reboot.

If you need more than one mount at the same time we may need to alter the command slightly though... you can put multiple lines in there but we have to make them run concurrently.

ok how about this:

#!/bin/bash
echo "Starting Rclone"
/sbin/start-stop-daemon -S -u $USER -d $HOME --exec /usr/bin/screen -- -dmS gdrive rclone mount gcrypt: ~/mnt/gdrive --allow-other --allow-non-empty --cache-db-purge --buffer-size 256M --dir-cache-time 72h --drive-chunk-size 32M --timeout 1h --vfs-cache-mode minimal --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit 1G &

That is the long command line that was used in the bytesized page tutorial link I have sent before. Would this work in my case as well? just copying it and pasting it inside the autorun.sh would do that job? What do you think? I just didn´t do it before because, not knowing what I was doing, I did not want to mess things up

The format here would be correct.

However all the spesifics may not be appropriate to you.
I'd much rather you shared with us the command you used to get them running when you did it manually.

We can then use that as a base and just add any other options to it as we need.
I just don't know all the specifics of where you installed rclone ect. to say that "yes this would work". I am also not super experienced in Linux in general. I work mostly in windows and my Linux-spesific knowledge is fairly basic.

ok so this is the command I have used in order to mount gdrive:

rclone mount gdrive: /share/CACHEDEV1_DATA/gdrive

Should I just put that command into autorun.sh? that´s it?

That should work yes.
of course, then you are mostly using default settings, but default are a good place to start if you aren't sure what options you need to use.

What flags/options we use are determined by your spesific use-case and needs. Most of that big example command you posted are just options for rclone, and I don't want you to just add them blindly without understanding them. That is pointless.

Although you can probably add this flag right away:
--allow-other
(to the end of your command)

I assume the autorun.sh is run by the ROOT user, and without this flag then only ROOT would be ballowed to use it, so you'd likely have trouble accessing it. Even if you don't end up needing this it won't do you any harm at least.

ok cool, let me give it a try, be back in 10 mins

you might want to add the the location of the rclone config file

(note the edit I did to my last post)

If you can tell me what your primary use-case is (is it plex?) + what cloud provider you use then I can link some documentation pages for you to read through so you can get an idea of what flags might be interesting for you to use (then you can ask from there as needed).

And also probably suggest the most "no-brainer" options that have big benefits but few drawbacks.

yes stigma I am using it primarily for Plex+Gdrive so that I can use the unlimited space I have on Gdrive with Plex libraries.

Can you tell me really quick how to check the content of the rclone.conf file?

Yes absolutely.

By default, the location of the config varies with the user.
So if you tested manually with a normal user and made your config on that - then try to get autorun.sh to do the command for you (presumably run by ROOT?) then ROOT will not have a config file in it's location and will fail.

If you did your manual testing on ROOT it's fine though.
Otherwise you need to either:

  • Copy your config to the corresponding location for ROOT
    or
  • set a flag that nails down the location of the config file to use ( --config "location" )
    or
  • create/copy your config to the same folder that rclone.exe is in. If you do this rclone will always use this config by default no matter the user - unless you specifically set it to something else with the config flag.

guys now I am lost :slight_smile: How do I know where the rclone config file is?

From documentation:
Normally the config file is in your home directory as a file called .config/rclone/rclone.conf

It is just text - so open it like you would open any other text-file.
vi nameoffile - is something all linux systems should be able to do without any special software.

Note as I said above - this location (because of the home folder) is relative to the user you are currently utilizing. If you use multiple users you cna have multiple configurations, so don't get confused by that :slight_smile:

how can I see the directory structure of the NAS??

Eeeh, now now are talking about relly basic Linux stuff, so what interface are you using... text-based terminal window?