You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are the bad consequences of the way it works at the moment?
Do you want to send in a fix?
Hi,
my goal is to have a reliable mount.rclone wrapper. My actual solution is to use a sleep (or loop finding at least a file).
I think that a sort of solution is to call StartBackgroundMode() from mount.Mount() just after the mount(f, mountpoint) call, when we are sure that filesystem is really mounted. I'm not a go developer and I haven't any patch atm. I'm sorry for this.
I would underline that your creature works fine(TM) and this issue is just a suggestion from my side.
I failed my attempts to move StartBackGroundMode() after mount(f, mountpoint)... I suppose that go-routines are not happy if we daemonize. Very strange.
Another solution is to keep the daemonize where already is and use a sort of sync mechanism between the parent process and the child process (pipe?). After the fork the parent waits on a pipe, the child, instead, will write on the pipe after the mount action.
I failed my attempts to move StartBackGroundMode() after mount(f, mountpoint)... I suppose that go-routines are not happy if we daemonize. Very strange.
Yes go routines are not threads or processes they are green threads.
Perhaps what we could do is use the pidfile to monitor the child - get the parent to start the child, wait for N seconds and if the pidfile isn't there then tell the user the child has died and to check the log.
PS Looking at the code I think the pidfile handling is wrong - it appears to close it immediately after startBackGroundMode has returned.
I just noticed that Reborn returns the PID of the child process so instead of fiddling about with the pid file, we can just see if it is alive after N seconds which would be reasonably simple.
The go-daemon issue sevlyar/go-daemon#19 is 3 years stale without activity (as well as 14 other issues), while most of it fits within 5 small functions in go-daemon/daemon_unix.go, and rclone barely uses 20% of its features (e.g. locks, signals, pidfile are unused)
@ncw
I think we'd better admit that go-daemon solves a different use-case, drop it at least on linux, and re-implement it in a new rclone/cmd/mountlib/daemon_linux.go, esp. in light of #992 (comment)
I failed my attempts to move StartBackGroundMode() after mount(f, mountpoint)... I suppose that go-routines are not happy if we daemonize.
@comio
I'm not sure about goroutines but I see other stuff that should run in child only and not in parent:
rc-server - if enabled, it will bind to port in parent and cause "cannot bind" in daemonized child
NewFsDir - it chains to backend-specific, unconstrained, generally fork-unsafe Fs.NewFs
and more
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
Another solution is to keep the daemonize where already is and use a sort of sync mechanism between the parent process and the child process (pipe?).
Yes! The child could request passwords piped from parent's stdin and return status code.
What it does is start a new process rather than call fork()
Activity
ncw commentedon Feb 12, 2019
What are the bad consequences of the way it works at the moment?
Do you want to send in a fix?
comio commentedon Feb 12, 2019
Hi,
my goal is to have a reliable mount.rclone wrapper. My actual solution is to use a sleep (or loop finding at least a file).
I think that a sort of solution is to call StartBackgroundMode() from mount.Mount() just after the mount(f, mountpoint) call, when we are sure that filesystem is really mounted. I'm not a go developer and I haven't any patch atm. I'm sorry for this.
I would underline that your creature works fine(TM) and this issue is just a suggestion from my side.
luigi
comio commentedon Feb 13, 2019
Hi Again,
I failed my attempts to move StartBackGroundMode() after mount(f, mountpoint)... I suppose that go-routines are not happy if we daemonize. Very strange.
Another solution is to keep the daemonize where already is and use a sort of sync mechanism between the parent process and the child process (pipe?). After the fork the parent waits on a pipe, the child, instead, will write on the pipe after the mount action.
ncw commentedon Feb 14, 2019
Yes go routines are not threads or processes they are green threads.
You might want to check out the help from the go-daemon library rclone uses.
What it does is start a new process rather than call fork() which the go runtime is allergic to.
There doesn't seem to be a way to pass data from child to parent yet.
Perhaps what we could do is use the pidfile to monitor the child - get the parent to start the child, wait for N seconds and if the pidfile isn't there then tell the user the child has died and to check the log.
PS Looking at the code I think the pidfile handling is wrong - it appears to close it immediately after startBackGroundMode has returned.
ncw commentedon Feb 14, 2019
I just noticed that Reborn returns the PID of the child process so instead of fiddling about with the pid file, we can just see if it is alive after N seconds which would be reasonably simple.
Maybe just calling os.FindProcess with the Pid from the os.Process that Reborn returns.
ivandeex commentedon Oct 25, 2020
This issue duplicates (or amends) #992
ivandeex commentedon Oct 26, 2020
The go-daemon issue sevlyar/go-daemon#19 is 3 years stale without activity (as well as 14 other issues), while most of it fits within 5 small functions in go-daemon/daemon_unix.go, and rclone barely uses 20% of its features (e.g. locks, signals, pidfile are unused)
@ncw
I think we'd better admit that go-daemon solves a different use-case, drop it at least on linux, and re-implement it in a new rclone/cmd/mountlib/daemon_linux.go, esp. in light of #992 (comment)
I will submit a PR.
ivandeex commentedon Oct 26, 2020
@comio
I'm not sure about goroutines but I see other stuff that should run in 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.OnInitializeand into another function to contain child-only steps. Most commands would inherit it fromrootCmd.PersistentPreRun. Daemonizing commands would disable it byPersistentPreRun: func(){return nil}and then call from child... just an ideaYes! The child could request passwords piped from parent's stdin and return status code.
@ncw
[Nitpick mode on]: in the Linux world it's expressed as fork() + immediate exec() ;)
33 remaining items
ivandeex commentedon Sep 10, 2021
@comio
Submitted patch #5593 should fix this issue, hopefully in 1.57
For now you can play with the latest
ivabuild from https://github.com/ivandeex/rclone/releasesivandeex commentedon Sep 11, 2021
The PR should solve the original request of this ticket but a number of posts still stand:
I will fork them into a separate ticket(s) and attach in the mount project