Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart gracefully with in-process restart #807

Merged
merged 1 commit into from
May 7, 2016
Merged

Conversation

tpng
Copy link

@tpng tpng commented May 6, 2016

This patch allows Caddy to restart in-process gracefully without the -restart=inproc flag, replacing the current default Restart on POSIX system.

)

// File descriptors for in-process restart
var restartFds map[string]*os.File = make(map[string]*os.File)
Copy link
Member

@mholt mholt May 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any race condition here? (Edit: On second thought, probably not, since Start() gets called in same goroutine as the signal trap. I'll double-check anyway.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No race condition.

Follow-up though, could we revise this line to remove the lint notice:

caddy\restartinproc.go:9:16: should omit type map[string]*os.File from declaration of var restartFds; it will be inferred from the right-hand side

So, change to:

var restartFds = make(map[string]*os.File)

@mholt
Copy link
Member

mholt commented May 6, 2016

Woah. I have yet to try this, but if this works and is free of races, let's drop the "new process" restart altogether and just use this (and drop the -restart option)!

@mholt
Copy link
Member

mholt commented May 6, 2016

This works wonderfully. The race detector does not detect any races.

@tpng I really love this. Going to merge in after I or others have a chance to review more closely!

@mholt mholt added the under review 🧐 Review is pending before merging label May 6, 2016
@mholt
Copy link
Member

mholt commented May 6, 2016

Wait, does this also work on Windows?

@tpng
Copy link
Author

tpng commented May 7, 2016

Actually I don't know how to trigger a Caddy restart on Windows since the USR1 is only available on POSIX system. If there are other conditions to trigger a restart on Windows I can test it to see if it works.

@tpng
Copy link
Author

tpng commented May 7, 2016

It seems Go doesn't implement the FileListener function on WIndows, so it will not work on Windows, will need to use the original method on Windows.

@mholt
Copy link
Member

mholt commented May 7, 2016

For triggering a restart on Windows, I was just thinking of a test that calls the Restart() function.

But since FileListener isn't implemented on Windows (I knew that once, but since forgot), we will still have the regular "Windows" restart that we have now. But all other restarts can be switched to this. 👍

@tpng
Copy link
Author

tpng commented May 7, 2016

OK, so I need to update the pull request to do the following?
1. Move the original restart logic back to restart_windows.go
2. Update restart.go to use the new logic
3. Remove restartinproc.go
4. Remove -restart flag

@captncraig
Copy link

What if the "windows restart" was the current improc one and we note in
docs that Windows has occasional (very brief) downtime when it renews certs?

On Friday, May 6, 2016, Benny Ng notifications@github.com wrote:

OK, so I need to update the pull request to do the following?

  1. Move the original restart logic back to restart_windows.go
  2. Update restart.go to use the new logic.
  3. Remove restartinproc.go
  4. Remove -restart flag


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#807 (comment)

@tpng
Copy link
Author

tpng commented May 7, 2016

Yes, Windows will use the current inproc one.

@tpng tpng force-pushed the graceful-inproc-restart branch from 0caab31 to 088930e Compare May 7, 2016 02:02
@tpng tpng changed the title Restart gracefully for in-process restart Restart gracefully with in-process restart May 7, 2016
@tpng tpng force-pushed the graceful-inproc-restart branch from 088930e to fbb72ab Compare May 7, 2016 02:23
@@ -322,17 +292,6 @@ func Wait() {
// are no other errors, this function always returns at least the
// default Caddyfile.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have this godoc comment updated too, removing the part about piping in as part of a restart.

@mholt
Copy link
Member

mholt commented May 7, 2016

Benny, this is looking beautiful. I think I'm gonna cry. 😂

@tpng tpng force-pushed the graceful-inproc-restart branch from fbb72ab to 9705f34 Compare May 7, 2016 05:40
@mholt mholt removed the under review 🧐 Review is pending before merging label May 7, 2016
@mholt mholt merged commit 1f29c52 into master May 7, 2016
@mholt
Copy link
Member

mholt commented May 7, 2016

Great work @tpng, thank you!!

@tpng tpng deleted the graceful-inproc-restart branch May 7, 2016 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants