@marcel91200 / caddy Mirror · read-only / commits / 1e0cdc54
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 15:30 UTC

core: Windows service integration (#4790)

Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>

WingLim committed Jul 30, 2022 at 04:06 UTC 1e0cdc54f86cb29eca14af13aaa3ccfb07d46a20
15 files changed +105 -24
caddyconfig/caddyfile/formatter_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package caddyfile
18
caddyconfig/caddyfile/lexer_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package caddyfile
18
caddyconfig/httpcaddyfile/addresses_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package httpcaddyfile
18
cmd/removebinary.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build !windows
16 -// +build !windows
16
17 package caddycmd
18
duration_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package caddy
18
go.mod
+1 -1
@@ -121,7 +121,7 @@ require (
121 go.uber.org/atomic v1.9.0 // indirect
122 go.uber.org/multierr v1.6.0 // indirect
123 golang.org/x/mod v0.4.2 // indirect
124 - golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
124 + golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e
125 golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b // indirect
126 golang.org/x/tools v0.1.7 // indirect
127 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
listeners_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package caddy
18
modules/caddyhttp/templates/frontmatter_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package templates
18
notify/notify_linux.go
+2
@@ -12,6 +12,8 @@
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 +// Package notify provides facilities for notifying process managers
16 +// of state changes, mainly for when running as a system service.
17 package notify
18
19 import (
notify/notify_other.go
+4 -13
@@ -12,19 +12,10 @@
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 -//go:build !linux
16 -// +build !linux
15 +//go:build !linux && !windows
16
17 package notify
18
20 -func notifyReadiness() error {
21 - return nil
22 -}
23 -
24 -func notifyReloading() error {
25 - return nil
26 -}
27 -
28 -func notifyStopping() error {
29 - return nil
30 -}
19 +func notifyReadiness() error { return nil }
20 +func notifyReloading() error { return nil }
21 +func notifyStopping() error { return nil }
notify/notify_windows.go new
+49
@@ -0,0 +1,49 @@
1 +// Copyright 2015 Matthew Holt and The Caddy Authors
2 +//
3 +// Licensed under the Apache License, Version 2.0 (the "License");
4 +// you may not use this file except in compliance with the License.
5 +// You may obtain a copy of the License at
6 +//
7 +// http://www.apache.org/licenses/LICENSE-2.0
8 +//
9 +// Unless required by applicable law or agreed to in writing, software
10 +// distributed under the License is distributed on an "AS IS" BASIS,
11 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 +// See the License for the specific language governing permissions and
13 +// limitations under the License.
14 +
15 +package notify
16 +
17 +import "golang.org/x/sys/windows/svc"
18 +
19 +// globalStatus store windows service status, it can be
20 +// use to notify caddy status.
21 +var globalStatus chan<- svc.Status
22 +
23 +func SetGlobalStatus(status chan<- svc.Status) {
24 + globalStatus = status
25 +}
26 +
27 +func notifyReadiness() error {
28 + if globalStatus != nil {
29 + globalStatus <- svc.Status{
30 + State: svc.Running,
31 + Accepts: svc.AcceptStop | svc.AcceptShutdown,
32 + }
33 + }
34 + return nil
35 +}
36 +
37 +func notifyReloading() error {
38 + if globalStatus != nil {
39 + globalStatus <- svc.Status{State: svc.StartPending}
40 + }
41 + return nil
42 +}
43 +
44 +func notifyStopping() error {
45 + if globalStatus != nil {
46 + globalStatus <- svc.Status{State: svc.StopPending}
47 + }
48 + return nil
49 +}
replacer_fuzz.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build gofuzz
16 -// +build gofuzz
16
17 package caddy
18
service_windows.go new
+49
@@ -0,0 +1,49 @@
1 +// Copyright 2015 Matthew Holt and The Caddy Authors
2 +//
3 +// Licensed under the Apache License, Version 2.0 (the "License");
4 +// you may not use this file except in compliance with the License.
5 +// You may obtain a copy of the License at
6 +//
7 +// http://www.apache.org/licenses/LICENSE-2.0
8 +//
9 +// Unless required by applicable law or agreed to in writing, software
10 +// distributed under the License is distributed on an "AS IS" BASIS,
11 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 +// See the License for the specific language governing permissions and
13 +// limitations under the License.
14 +
15 +package caddy
16 +
17 +import (
18 + "github.com/caddyserver/caddy/v2/notify"
19 + "golang.org/x/sys/windows/svc"
20 +)
21 +
22 +func init() {
23 + isService, err := svc.IsWindowsService()
24 + if err != nil || isService {
25 + return
26 + }
27 + go func() {
28 + _ = svc.Run("", runner{})
29 + }()
30 +}
31 +
32 +type runner struct{}
33 +
34 +func (runner) Execute(args []string, request <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) {
35 + notify.SetGlobalStatus(status)
36 + status <- svc.Status{State: svc.StartPending}
37 +
38 + for {
39 + req := <-request
40 + switch req.Cmd {
41 + case svc.Interrogate:
42 + status <- req.CurrentStatus
43 + case svc.Stop, svc.Shutdown:
44 + status <- svc.Status{State: svc.StopPending}
45 + exitProcessFromSignal("SIGINT")
46 + return false, 0
47 + }
48 + }
49 +}
sigtrap_nonposix.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build windows || plan9 || nacl || js
16 -// +build windows plan9 nacl js
16
17 package caddy
18
sigtrap_posix.go
-1
@@ -13,7 +13,6 @@
13 // limitations under the License.
14
15 //go:build !windows && !plan9 && !nacl && !js
16 -// +build !windows,!plan9,!nacl,!js
16
17 package caddy
18