go-daemon icon indicating copy to clipboard operation
go-daemon copied to clipboard

Should be able to pass additional FDs

Open akamensky opened this issue 5 years ago • 5 comments

Right now there is not way to get additional FDs to be passed from parent to daemon.

My goal is to open TCP socket, then get FD (using TCPListener.File()), then pass that FD to the daemon and convert it back to Listener (using net.FileListener())

I think this should be totally doable and not hard to implement, so I don't see why it was not there from the start. There are more uses to this functionality than just this.

akamensky avatar Feb 03 '19 05:02 akamensky

@akamensky Hey man, did you get a implement now? I want the feature you mentioned too

sherlockblaze avatar Mar 06 '19 07:03 sherlockblaze

@sherlockblaze Nope, to get that working I would need to rewrite large part of this package.

akamensky avatar Mar 06 '19 09:03 akamensky

@akamensky I think I got it already. When you use the lib to start a daemon thread, you should set Args for it.

cntxt := &daemon.Context{
		PidFileName: "pid",
		PidFilePerm: 0644,
		LogFileName: "log",
		LogFilePerm: 0640,
		WorkDir:     "./",
		Umask:       027,
		Args:        []string{"[go-daemon sample]", "test"},
	}

And the Args just like the command line you use. Like nginx start, arg[0] is ngxin and arg[1] is start and like. So, you just need to set the args with your command by using a golang slice, you can achieve your goal.

sherlockblaze avatar Mar 06 '19 12:03 sherlockblaze

@sherlockblaze command line arguments have nothing to do with file descriptors...

akamensky avatar Mar 06 '19 12:03 akamensky

@akamensky sorry man, I misunderstood your purpose

sherlockblaze avatar Mar 06 '19 13:03 sherlockblaze