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
821c0fab
Commit
821c0fab
authored
Oct 26, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Refactoring POSIX-only code for build tags
parent
5b196230
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
76 deletions
+114
-76
caddy/helpers.go
caddy/helpers.go
+28
-35
caddy/restart.go
caddy/restart.go
+2
-41
caddy/restart_windows.go
caddy/restart_windows.go
+25
-0
caddy/sigtrap.go
caddy/sigtrap.go
+33
-0
caddy/sigtrap_posix.go
caddy/sigtrap_posix.go
+26
-0
No files found.
caddy/helpers.go
View file @
821c0fab
...
...
@@ -3,52 +3,17 @@ package caddy
import
(
"bytes"
"fmt"
"log"
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"
"strings"
"syscall"
"github.com/mholt/caddy/caddy/letsencrypt"
"github.com/mholt/caddy/server"
)
func
init
()
{
letsencrypt
.
OnRenew
=
func
()
error
{
return
Restart
(
nil
)
}
// Trap signals
go
func
()
{
shutdown
,
reload
:=
make
(
chan
os
.
Signal
,
1
),
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
shutdown
,
os
.
Interrupt
,
os
.
Kill
)
// quit the process
signal
.
Notify
(
reload
,
syscall
.
SIGUSR1
)
// reload configuration
for
{
select
{
case
<-
shutdown
:
var
exitCode
int
serversMu
.
Lock
()
errs
:=
server
.
ShutdownCallbacks
(
servers
)
serversMu
.
Unlock
()
if
len
(
errs
)
>
0
{
for
_
,
err
:=
range
errs
{
log
.
Println
(
err
)
}
exitCode
=
1
}
os
.
Exit
(
exitCode
)
case
<-
reload
:
err
:=
Restart
(
nil
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
}
}
}()
}
// isLocalhost returns true if the string looks explicitly like a localhost address.
...
...
@@ -72,3 +37,31 @@ func checkFdlimit() {
}
}
}
// caddyfileGob maps bind address to index of the file descriptor
// in the Files array passed to the child process. It also contains
// the caddyfile contents. Used only during graceful restarts.
type
caddyfileGob
struct
{
ListenerFds
map
[
string
]
uintptr
Caddyfile
[]
byte
}
// isRestart returns whether this process is, according
// to env variables, a fork as part of a graceful restart.
func
isRestart
()
bool
{
return
os
.
Getenv
(
"CADDY_RESTART"
)
==
"true"
}
// CaddyfileInput represents a Caddyfile as input
// and is simply a convenient way to implement
// the Input interface.
type
CaddyfileInput
struct
{
Filepath
string
Contents
[]
byte
}
// Body returns c.Contents.
func
(
c
CaddyfileInput
)
Body
()
[]
byte
{
return
c
.
Contents
}
// Path returns c.Filepath.
func
(
c
CaddyfileInput
)
Path
()
string
{
return
c
.
Filepath
}
caddy/restart.go
View file @
821c0fab
// +build !windows
package
caddy
import
(
...
...
@@ -5,18 +7,9 @@ import (
"io/ioutil"
"log"
"os"
"runtime"
"syscall"
)
// caddyfileGob maps bind address to index of the file descriptor
// in the Files array passed to the child process. It also contains
// the caddyfile contents. Used only during graceful restarts.
type
caddyfileGob
struct
{
ListenerFds
map
[
string
]
uintptr
Caddyfile
[]
byte
}
// Restart restarts the entire application; gracefully with zero
// downtime if on a POSIX-compatible system, or forcefully if on
// Windows but with imperceptibly-short downtime.
...
...
@@ -31,18 +24,6 @@ func Restart(newCaddyfile Input) error {
caddyfileMu
.
Unlock
()
}
if
runtime
.
GOOS
==
"windows"
{
err
:=
Stop
()
if
err
!=
nil
{
return
err
}
err
=
Start
(
newCaddyfile
)
if
err
!=
nil
{
return
err
}
return
nil
}
if
len
(
os
.
Args
)
==
0
{
// this should never happen, but just in case...
os
.
Args
=
[]
string
{
""
}
}
...
...
@@ -110,23 +91,3 @@ func Restart(newCaddyfile Input) error {
// Child process is listening now; we can stop all our servers here.
return
Stop
()
}
// isRestart returns whether this process is, according
// to env variables, a fork as part of a graceful restart.
func
isRestart
()
bool
{
return
os
.
Getenv
(
"CADDY_RESTART"
)
==
"true"
}
// CaddyfileInput represents a Caddyfile as input
// and is simply a convenient way to implement
// the Input interface.
type
CaddyfileInput
struct
{
Filepath
string
Contents
[]
byte
}
// Body returns c.Contents.
func
(
c
CaddyfileInput
)
Body
()
[]
byte
{
return
c
.
Contents
}
// Path returns c.Filepath.
func
(
c
CaddyfileInput
)
Path
()
string
{
return
c
.
Filepath
}
caddy/restart_windows.go
0 → 100644
View file @
821c0fab
package
caddy
func
Restart
(
newCaddyfile
Input
)
error
{
if
newCaddyfile
==
nil
{
caddyfileMu
.
Lock
()
newCaddyfile
=
caddyfile
caddyfileMu
.
Unlock
()
}
wg
.
Add
(
1
)
// barrier so Wait() doesn't unblock
err
:=
Stop
()
if
err
!=
nil
{
return
err
}
err
=
Start
(
newCaddyfile
)
if
err
!=
nil
{
return
err
}
wg
.
Done
()
// take down our barrier
return
nil
}
caddy/sigtrap.go
0 → 100644
View file @
821c0fab
package
caddy
import
(
"log"
"os"
"os/signal"
"github.com/mholt/caddy/server"
)
func
init
()
{
// Trap quit signals (cross-platform)
go
func
()
{
shutdown
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
shutdown
,
os
.
Interrupt
,
os
.
Kill
)
<-
shutdown
var
exitCode
int
serversMu
.
Lock
()
errs
:=
server
.
ShutdownCallbacks
(
servers
)
serversMu
.
Unlock
()
if
len
(
errs
)
>
0
{
for
_
,
err
:=
range
errs
{
log
.
Println
(
err
)
}
exitCode
=
1
}
os
.
Exit
(
exitCode
)
}()
}
caddy/sigtrap_posix.go
0 → 100644
View file @
821c0fab
// +build !windows
package
caddy
import
(
"log"
"os"
"os/signal"
"syscall"
)
func
init
()
{
// Trap POSIX-only signals
go
func
()
{
reload
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
reload
,
syscall
.
SIGUSR1
)
// reload configuration
for
{
<-
reload
err
:=
Restart
(
nil
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
}
}()
}
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