Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
acme_server: switch to bbolt storage (#3868)
* acme_server: switch to bbolt storage There have been some issues with the badger storage engine being used by the embedded acme_server. This will replace the storage engine with bbolt * Switch database path back to acme_server/db and remove if directory
Ian committed
Nov 23, 2020 at 12:03 UTC
06ba006f9bb7fe4fe8fb97bbda594f3c438cb6ad
1 file changed
+18
-3
modules/caddypki/acmeserver/acmeserver.go
+18
-3
@@ -32,6 +32,7 @@ import (
32
"github.com/smallstep/certificates/authority/provisioner"
33
"github.com/smallstep/certificates/db"
34
"github.com/smallstep/nosql"
35
+ "go.uber.org/zap"
36
)
37
38
func init() {
@@ -77,6 +78,7 @@ func (Handler) CaddyModule() caddy.ModuleInfo {
78
79
// Provision sets up the ACME server handler.
80
func (ash *Handler) Provision(ctx caddy.Context) error {
81
+ logger := ctx.Logger(ash)
82
// set some defaults
83
if ash.CA == "" {
84
ash.CA = caddypki.DefaultCAID
@@ -99,7 +101,8 @@ func (ash *Handler) Provision(ctx caddy.Context) error {
101
return fmt.Errorf("no certificate authority configured with id: %s", ash.CA)
102
}
103
102
- dbFolder := filepath.Join(caddy.AppDataDir(), "acme_server", "db")
104
+ dbFolder := filepath.Join(caddy.AppDataDir(), "acme_server")
105
+ dbPath := filepath.Join(dbFolder, "db")
106
107
// TODO: See https://github.com/smallstep/nosql/issues/7
108
err = os.MkdirAll(dbFolder, 0755)
@@ -107,6 +110,18 @@ func (ash *Handler) Provision(ctx caddy.Context) error {
110
return fmt.Errorf("making folder for ACME server database: %v", err)
111
}
112
113
+ // Check to see if previous db exists
114
+ var stat os.FileInfo
115
+ stat, err = os.Stat(dbPath)
116
+ if stat != nil && err == nil {
117
+ // A badger db is found and should be removed
118
+ if stat.IsDir() {
119
+ logger.Warn("Found an old badger database and removing it",
120
+ zap.String("path", dbPath))
121
+ _ = os.RemoveAll(dbPath)
122
+ }
123
+ }
124
+
125
authorityConfig := caddypki.AuthorityConfig{
126
AuthConfig: &authority.AuthConfig{
127
Provisioners: provisioner.List{
@@ -122,8 +137,8 @@ func (ash *Handler) Provision(ctx caddy.Context) error {
137
},
138
},
139
DB: &db.Config{
125
- Type: "badger",
126
- DataSource: dbFolder,
140
+ Type: "bbolt",
141
+ DataSource: dbPath,
142
},
143
}
144