mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-08 14:14:52 +00:00
fix: Caddy config regeneration due to non-deterministic container serialisation (fixes #111)
This commit is contained in:
1 parent
39181708dd
commit
6e9acefbe6
8 files changed
+298
-40
No files matched your search
@@ -34,21 +34,16 @@ func NewCaddyAdminClient(socketPath string) *CaddyAdminClient {
|
||||
}
|
||||
}
|
||||
|
||||
// IsAvailable checks if the local Caddy instance is running and responding to admin API requests.
|
||||
func (c *CaddyAdminClient) IsAvailable(ctx context.Context) bool {
|
||||
// Caddy doesn't serve a /ping endpoint. It's a random endpoint we can use to check if Caddy is running.
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "http://localhost/ping", nil)
|
||||
// IsAvailable checks if the local Caddy instance is listening on the admin socket.
|
||||
func (c *CaddyAdminClient) IsAvailable() bool {
|
||||
conn, err := net.DialTimeout("unix", c.socketPath, 1*time.Second)
|
||||
// A stale socket file left over from a crashed Caddy container returns ECONNREFUSED so this is correctly handled
|
||||
// as unavailable.
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
conn.Close()
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Any HTTP response means Caddy is running and accessible.
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user