Skip to content

daemonize after mount #2968

Closed
Closed

Description

@comio

What is your current rclone version (output from rclone version)?

rclone v1.46
- os/arch: linux/amd64
- go version: go1.11.5

What problem are you are trying to solve?

using mount + --daemon, rclone forks to early. Rclone should daemonize after the mount action in order to avoid sleeps after that.

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

  1. mount the mount point
  2. Daemonize on success

Of course: Thanks for this impressive tools.

Activity

  1. ncw commented on Feb 12, 2019

    @ncw
    Member

    What are the bad consequences of the way it works at the moment?

    Do you want to send in a fix?

  2. added this to the Help Wanted milestone on Feb 12, 2019
  3. comio commented on Feb 12, 2019

    @comio
    Author

    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.

    luigi

  4. comio commented on Feb 13, 2019

    @comio
    Author

    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.

  5. ncw commented on Feb 14, 2019

    @ncw
    Member

    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.

    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.

  6. ncw commented on Feb 14, 2019

    @ncw
    Member

    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.

  7. ivandeex commented on Oct 25, 2020

    @ivandeex
    Member

    This issue duplicates (or amends) #992

  8. ivandeex commented on Oct 26, 2020

    @ivandeex
    Member

    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.

  9. ivandeex commented on Oct 26, 2020

    @ivandeex
    Member

    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()

    @ncw
    [Nitpick mode on]: in the Linux world it's expressed as fork() + immediate exec() ;)

  10. self-assigned this
    on Oct 26, 2020
  11. 33 remaining items

  12. modified the milestones: v1.57, Soon on May 26, 2021
  13. modified the milestones: Soon, v1.57 on Sep 10, 2021
  14. ivandeex commented on Sep 10, 2021

    @ivandeex
    Member

    @comio
    Submitted patch #5593 should fix this issue, hopefully in 1.57
    For now you can play with the latest iva build from https://github.com/ivandeex/rclone/releases

  15. ivandeex commented on Sep 11, 2021

    @ivandeex
    Member

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions