rclone / rclone

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
https://rclone.org
MIT License
47.29k stars 4.23k forks source link

mount: improve implementation of --daemon mode #5664

Open ivandeex opened 3 years ago

ivandeex commented 3 years ago

References

This ticket:

Also related to a number of console password input tickets - see Password prompts in a comment below.

What problem are you are trying to solve?

Looking at the rclone initialization code from the --daemon point of view I can see stuff that should run in the child only and not in parent:

This calls for refactoring, esp. initConfig can be split into a function common to all commands to be used in cobra.OnInitialize and into another function to contain child-only steps. Most commands would inherit it from rootCmd.PersistentPreRun. Daemonizing commands would disable it by PersistentPreRun: func(){return nil} and then call from child... just an idea

How do you think rclone should be changed to solve that?

We might refactor backgrounding to have rughly 3 stages :

As a consequence, we have to:

Another idea is to keep the StartDaemon where it was already butuse a sort of sync mechanism between the parent process and the child process (pipe?).

How to use GitHub

ivandeex commented 3 years ago

A recent --daemon patch https://github.com/rclone/rclone/commit/8b8a943dd82bd16ea749e92645ba0941c82c456a introduced the fs.IsDaemon function which is true in the child. Now we need fs.IsParent to detect early whether daemonizing was requested.

Another approach is to let some facilities activate early in the parent but then shutdown them right before we spawn a child. Just another idea :)

ivandeex commented 3 years ago

Password prompts in Backgound process

Interactive input from user on stdin/stdout is used by rclone core to get config key and by many backends to update such stuff as 2-factor authentication or storage pins.

The child process lacks stdin so it could request passwords piped from parent's stdin then return status code to parent, but the child might need secrets after parent exits, so..

Generally daemonization calls for a common rclone API and configuration options to allow for obtaining secrets from a wider range of sources:

The API patch is expected to be intrusive - it will affect code in a lot of backends.

References:

CyberPoison commented 2 years ago

I'm having some issue whenre runing the --daemon flag as i see in the Patch the is a new flag --daemon-wait but my question is how can i mount a google drive with rclone mount such as i described here #6173 i have some issues when running daemon flag there is any work arround on this ?

My rclone version is rclone: Version "v1.58.1" And does i need to upgrade or downgrade to some version to get it working or just i need to run some specfic new flag ?

CyberPoison commented 2 years ago

For those who have the same issue this is how i deployed my rclone as daemon.

echo "Starting Mounts ..." && sleep 5 && bash -c 'setsid sudo rclone mount --allow-other --dir-cache-time 24h --vfs-read-chunk-size 124M --vfs-read-chunk-size-limit 4G --buffer-size 512M --vfs-cache-mode writes Cloud\ Storage\ Server\ 1\ Uncrypt:/ /mnt/Cloud\ Storage/Cloud\ Storage\ Server\ 1/ </dev/null &>/dev/null & jobs -p %1' && echo "Done..." && sleep 5
psb777 commented 1 year ago

It all must be a lot simpler than some would have it, fixing this problem. When I run mount from the command line and run it in the background "&" using a "--log-file=x" option rclone mount works fine.

There are well documented standard techniques for running any program as a daemon, and there exist Unix/Linux utilities to do this. There is no need to have a --daemon flag at all. One such tool is this

https://linux.die.net/man/1/daemonize

It's always pleasant to fix a bug by removing code, and here is such an opportunity. Let's lose the --daemon flag. It's an o/s specific problem and the o/s should handle it, or a simple o/s specific utility will. Next we'll be embedding output pagination in rclone like they do in systemd, rather than using less/more/pg.

ncw commented 1 year ago

Maybe we should document using daemonize as an alternative to the --daemon flag? That might be a good first step.

Fancy sending a PR to that effect @psb777 ?

psb777 commented 1 year ago

Well, maybe, except that the use of daemonize to turn any process into a daemon is the same for any process, and the doc on how so to do is man daemonize. I note there exist other similar utilities like such as the predictably named daemon. And my technique, of using a logfile and putting rclone into the background using the /bin/[zkcr]sh command line suffix & just works. So, whereas I have installed daemonize reading the manual is just too much work I'm not even using it.

nathanshearer commented 1 year ago

I have run into a problem where rclone mount is processing the vfs and queuing up changes. While this is happening, something times out and the process is killed:

DEBUG : Daemon timed out. Terminating daemon pid

As a temporary workaround, I am running rclone in the foreground and backgrounding that process:

RCLONE_ARGS=(
    --log-file="$LOGFILE"
    --cache-dir /mnt/local01/rclonecache
    mount
    googledrive:/
    --bwlimit 8M
    --drive-impersonate "$ACCOUNT"
    --drive-use-trash=false
    #--fast-list # --fast-list does nothing on a mount
    --vfs-cache-mode full
    --vfs-cache-poll-interval 10m
    --vfs-cache-max-size 8G
    --vfs-cache-max-age 10h
    --vfs-write-back 1h
    --allow-other
    --umask 0
    #-vv
    /mnt/googledrive
)
rclone "${RCLONE_ARGS[@]}" 2>&1 >> "$LOGFILE" &

I have an unusual setup where I keep items in the cache for a long period. I have sparse block devices stacked on top of my rclone mount (it works great!), but the block devices and arbitrary filesystem background tasks can cause a lot of IO, so I have a large 1TB local cache to prevent thrashing the google server. The read+write to/from google is minimal and serialized.

Masterxilo commented 1 year ago

I have the same issue here, mounting a Google Drive.

Using --daemon gives

<7>DEBUG : Daemon timed out. Terminating daemon pid 79084
Fatal error: mount not ready

while it works just fine without --daemon... the feature is broken; rclone v1.63.1

ncw commented 1 year ago

Try adjusting --daemon-wait - if you use --daemon-wait 0 then I think rclone won't wait for the mount to come up at all so it will come up in the background.

Masterxilo commented 1 year ago

thanks @ncw, adding both "--daemon" and --daemon-wait 0 restored the behavior I observed with older rclone versions, the mount comes up just fine now and the program runs in the background