Repository navigation
Run rclone as a mount helper program - #5594
Conversation
|
@ncw I don't yet call for review as I still need to put user notes from this PR's top post in the mount docs. When reviewing, please skip the #5593 commit as it will annihilate when we merge #5593. |
|
I had a quick skim of the code and it seems to do the right things :-) I don't know if you saw my prototype for this? 78ffe37 Not sure there is anything you can learn from that, but I thought I'd put it out there. It directly modifies |
I wanted to keep a backup of original arguments just for debugging purposes. |
Not yet. Noted... |
I'd say let's modify os.Args directly - we can always put a debug in with the old and the new values or something. |
9eef890 to
949c854
Compare
done |
ncw
left a comment
There was a problem hiding this comment.
I think this code looks great - thank you.
However it could do with some docs - you wrote some nice ones in the PR - maybe cut and paste into cmd/mountlib/help.go? (Though I think that file is getting too long and we should probably break it out into its own docs page say docs/content/mount.md at some point...)
ivandeex
left a comment
There was a problem hiding this comment.
two small questions...
There was a problem hiding this comment.
@ncw
Thank you very much for review.
Do you mind if I put mountlib documentation in a separate commit?
Also I'd like to note that the early --verbose=x parser in fs/config.go isn't directly connected with mount helper cli translator and may be split into yet another commit.
Do you agree? Or better keep it squashed?
Thank you
0f10ef8 to
506a4a5
Compare
506a4a5 to
cbbc587
Compare
7b2c1a6 to
ee87622
Compare
ee87622 to
bd82c19
Compare
|
Please be aware that I documented rclone mount helper in a dedicated commit bd82c19 (a065fb2 on master) partially including the Also updated the related wiki article https://github.com/rclone/rclone/wiki/rclone-mount-helper-script |
|
Thank looks great, thank you. |
|
Cool. |
What is the purpose of this change?
This PR will make rclonefs wrappers moot!
The PRedecessor #5593 solve(d) most problems that prevented rclone from running the mount in background i.e. working like a generic unix mount program (
sshfs,mount.glusterfsand others can do it out of the box), namely:The last incompatibility left is the way mount arguments are passed.
The core
/bin/mountprogram will (in the basic scenario) get the-t FSTYPEargument then run the/sbin/mount.FSTYPEhelper program passing it mount options. Automountd and systemd generally follow the same logic...But rclone expects GNU-styled flags like
--key valwhile mount options are passed as-o key=val,...(or--opt=...)!This patch fills the last gap.
Usage
Please symlink the rclone binary to
/sbin/mount.rclone(and optionally/usr/bin/rclonefs) and justconfig=...,cache-dir=...as mounts run withoutHOME!)/etc/fstaba line likeAutomountd!P.S. There was a ticket #2805 requesting the new
rclone mount --idle=Xflag but now we can do it in a standard way making it mostly moot (except on windows)...Implementation
This patch introduces new slicefs.Argswhich is by default a copy ofos.Argsbut can be rewritten if rclone executable was invoked asmount.rcloneorrclonefs.UPDATE
This patch rewrites
os.Argsinplace in an early init() block if rclone executable was invoked asmount.rcloneorrclonefs.We use
os.Args[0]rather thanos.Executableto detect the name since the latter might resolve symlink while we want it unresolved.Mount helpers usually lack the
HOMEorRCLONE_CONFIGenvironment variables, so config setup code infs/configwill requirefs.Argsto find a correct (probably converted)--config FILErunning very early (most probably called from init blocks). Consequently the command line transformer also runs super early in theinitblock of the corefspackage and avoids using other packages to prevent import loops. Utility functionsIsDaemonandIsMountHelperwere put directly infsfor this very reason.Basically the conversion splits
-oargument(s) by comma, replaces_by-and prepends--to transform-ooptions into Cobra flags. Options containing commas or spaces can be wrapped in single or double quotes (any quotes inside outer quotes should be doubled). The parser algorithm is based on the connection string parser with a few command-line specific modifications.The option syntax additionally includes a few pseudo mount options treated specially:
env.NAME=VALUEwill set an environment variable for this rclone instance and its children.This helps with Automountd and Systemd.mount which don't let set custom environment for mount helpers.
Typically you will use
env.HTTPS_PROXY=proxy.host:3128orenv.HOME=/rootcommand=cmountcan be used to run any other command rather than defaultmountin the helper modeargs2envwill pass mount options to the daemonized mount helper viaRCLONE_Xenvironment variables instead of CLI flags. This allows to hide secrets frompsorpgrep.-o vv...will be transformed into--verbose=N, just for conveniencex-systemd.automount,_netdev,nosuidand alike are intended for automountd or systemd and ignored by rcloneWas the change discussed in an issue or in the forum before?
Based on #5593 (this PR includes preliminary patch of #5593 expected to annihilate at merge time)
Fixes #992
Checklist