Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
98cf2637
Commit
98cf2637
authored
Jun 08, 2016
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #873 from mholt/fix-restart
Fix restart on USR1 not loading new Caddyfile
parents
6492592b
ff820571
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
30 deletions
+16
-30
caddy.go
caddy.go
+14
-29
caddyhttp/httpserver/plugin.go
caddyhttp/httpserver/plugin.go
+2
-1
No files found.
caddy.go
View file @
98cf2637
...
...
@@ -65,7 +65,7 @@ type Instance struct {
caddyfileInput
Input
// wg is used to wait for all servers to shut down
wg
sync
.
WaitGroup
wg
*
sync
.
WaitGroup
// servers is the list of servers with their listeners...
servers
[]
serverListener
...
...
@@ -89,12 +89,14 @@ func (i *Instance) Stop() error {
}
// splice instance list to delete this one
instancesMu
.
Lock
()
for
j
,
other
:=
range
instances
{
if
other
==
i
{
instances
=
append
(
instances
[
:
j
],
instances
[
j
+
1
:
]
...
)
break
}
}
instancesMu
.
Unlock
()
return
nil
}
...
...
@@ -119,6 +121,9 @@ func (i *Instance) shutdownCallbacks() []error {
func
(
i
*
Instance
)
Restart
(
newCaddyfile
Input
)
(
*
Instance
,
error
)
{
log
.
Println
(
"[INFO] Reloading"
)
i
.
wg
.
Add
(
1
)
defer
i
.
wg
.
Done
()
// run restart callbacks
for
_
,
fn
:=
range
i
.
onRestart
{
err
:=
fn
()
...
...
@@ -142,7 +147,7 @@ func (i *Instance) Restart(newCaddyfile Input) (*Instance, error) {
}
// create new instance; if the restart fails, it is simply discarded
newInst
:=
&
Instance
{
serverType
:
newCaddyfile
.
ServerType
()}
newInst
:=
&
Instance
{
serverType
:
newCaddyfile
.
ServerType
()
,
wg
:
i
.
wg
}
// attempt to start new instance
err
:=
startWithListenerFds
(
newCaddyfile
,
newInst
,
restartFds
)
...
...
@@ -150,15 +155,8 @@ func (i *Instance) Restart(newCaddyfile Input) (*Instance, error) {
return
i
,
err
}
// success! bump the old instance out so it will be garbage-collected
instancesMu
.
Lock
()
for
j
,
other
:=
range
instances
{
if
other
==
i
{
instances
=
append
(
instances
[
:
j
],
instances
[
j
+
1
:
]
...
)
break
}
}
instancesMu
.
Unlock
()
// success! stop the old instance
i
.
Stop
()
log
.
Println
(
"[INFO] Reloading complete"
)
...
...
@@ -365,7 +363,7 @@ func (i *Instance) Caddyfile() Input {
// This function blocks until all the servers are listening.
func
Start
(
cdyfile
Input
)
(
*
Instance
,
error
)
{
writePidFile
()
inst
:=
&
Instance
{
serverType
:
cdyfile
.
ServerType
()}
inst
:=
&
Instance
{
serverType
:
cdyfile
.
ServerType
()
,
wg
:
new
(
sync
.
WaitGroup
)
}
return
inst
,
startWithListenerFds
(
cdyfile
,
inst
,
nil
)
}
...
...
@@ -405,13 +403,10 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r
return
err
}
if
restartFds
==
nil
{
// run startup callbacks since this is not a restart
for
_
,
startupFunc
:=
range
inst
.
onStartup
{
err
:=
startupFunc
()
if
err
!=
nil
{
return
err
}
for
_
,
startupFunc
:=
range
inst
.
onStartup
{
err
:=
startupFunc
()
if
err
!=
nil
{
return
err
}
}
...
...
@@ -532,7 +527,6 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
return
err
}
file
.
Close
()
delete
(
restartFds
,
addr
)
}
}
...
...
@@ -552,15 +546,6 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
inst
.
servers
=
append
(
inst
.
servers
,
serverListener
{
server
:
s
,
listener
:
ln
})
}
// Close the remaining (unused) file descriptors to free up resources
// and stop old servers that aren't used anymore
for
key
,
old
:=
range
restartFds
{
if
err
:=
old
.
server
.
Stop
();
err
!=
nil
{
log
.
Printf
(
"[ERROR] Stopping %s: %v"
,
old
.
server
.
Address
(),
err
)
}
delete
(
restartFds
,
key
)
}
// Log errors that may be returned from Serve() calls,
// these errors should only be occurring in the server loop.
go
func
()
{
...
...
caddyhttp/httpserver/plugin.go
View file @
98cf2637
...
...
@@ -51,7 +51,8 @@ var contexts []*httpContext
func
newContext
()
caddy
.
Context
{
context
:=
&
httpContext
{
keysToSiteConfigs
:
make
(
map
[
string
]
*
SiteConfig
)}
contexts
=
append
(
contexts
,
context
)
// put the new context at start to allow setup of directives on new instance
contexts
=
append
([]
*
httpContext
{
context
},
contexts
...
)
return
context
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment