forked from caddyserver/caddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: Windows service integration (caddyserver#4790)
Co-authored-by: Matthew Holt <[email protected]>
- Loading branch information
Showing
15 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package caddyfile | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package caddyfile | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package httpcaddyfile | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package caddycmd | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package caddy | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package caddy | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package templates | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2015 Matthew Holt and The Caddy Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package notify | ||
|
||
import "golang.org/x/sys/windows/svc" | ||
|
||
// globalStatus store windows service status, it can be | ||
// use to notify caddy status. | ||
var globalStatus chan<- svc.Status | ||
|
||
func SetGlobalStatus(status chan<- svc.Status) { | ||
globalStatus = status | ||
} | ||
|
||
func notifyReadiness() error { | ||
if globalStatus != nil { | ||
globalStatus <- svc.Status{ | ||
State: svc.Running, | ||
Accepts: svc.AcceptStop | svc.AcceptShutdown, | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func notifyReloading() error { | ||
if globalStatus != nil { | ||
globalStatus <- svc.Status{State: svc.StartPending} | ||
} | ||
return nil | ||
} | ||
|
||
func notifyStopping() error { | ||
if globalStatus != nil { | ||
globalStatus <- svc.Status{State: svc.StopPending} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
// limitations under the License. | ||
|
||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package caddy | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2015 Matthew Holt and The Caddy Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package caddy | ||
|
||
import ( | ||
"github.com/caddyserver/caddy/v2/notify" | ||
"golang.org/x/sys/windows/svc" | ||
) | ||
|
||
func init() { | ||
isService, err := svc.IsWindowsService() | ||
if err != nil || isService { | ||
return | ||
} | ||
go func() { | ||
_ = svc.Run("", runner{}) | ||
}() | ||
} | ||
|
||
type runner struct{} | ||
|
||
func (runner) Execute(args []string, request <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) { | ||
notify.SetGlobalStatus(status) | ||
status <- svc.Status{State: svc.StartPending} | ||
|
||
for { | ||
req := <-request | ||
switch req.Cmd { | ||
case svc.Interrogate: | ||
status <- req.CurrentStatus | ||
case svc.Stop, svc.Shutdown: | ||
status <- svc.Status{State: svc.StopPending} | ||
exitProcessFromSignal("SIGINT") | ||
return false, 0 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters