Files
Chris Lu 37962e2445 admin: configure maintenance tasks via admin.toml (#9926)
* admin: configure maintenance tasks via admin.toml

Maintenance task settings could only be edited in the admin UI and live
under <dataDir>/conf, so they silently reverted to defaults whenever the
data directory was recreated. An optional admin.toml now declares vacuum,
balance, and erasure coding settings; keys set there are written through
to the persisted task configs at every startup, overriding UI edits, so
the configuration stays declarative. Generate an example with
"weed scaffold -config=admin".

* vacuum: round min volume age up to whole hours

MinVolumeAgeSeconds was truncated by integer division when converted to
the hour-granular protobuf field, so a sub-hour setting silently became
0 and disabled the age guard.

* admin: split and normalize preferred_tags from admin.toml

A comma-separated string, as set via environment variable, came through
viper as a single slice element. Split on commas and reuse
util.NormalizeTagList, matching the plugin config path.

* scaffold: clarify admin.toml wording
2026-06-11 11:04:52 -07:00

72 lines
1.9 KiB
Go

package command
import (
"fmt"
"path/filepath"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/command/scaffold"
)
func init() {
cmdScaffold.Run = runScaffold // break init cycle
}
var cmdScaffold = &Command{
UsageLine: "scaffold -config=[filer|notification|replication|security|master|volume|shell|credential|admin]",
Short: "generate basic configuration files",
Long: `Generate configuration files with all possible configurations for you to customize.
The options can also be overwritten by environment variables.
For example, the filer.toml mysql password can be overwritten by environment variable
export WEED_MYSQL_PASSWORD=some_password
Environment variable rules:
* Prefix the variable name with "WEED_".
* Uppercase the rest of the variable name.
* Replace '.' with '_'.
`,
}
var (
outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
config = cmdScaffold.Flag.String("config", "filer", "[filer|notification|replication|security|master|volume|shell|credential|admin] the configuration file to generate")
)
func runScaffold(cmd *Command, args []string) bool {
content := ""
switch *config {
case "filer":
content = scaffold.Filer
case "notification":
content = scaffold.Notification
case "replication":
content = scaffold.Replication
case "security":
content = scaffold.Security
case "master":
content = scaffold.Master
case "volume":
content = scaffold.Volume
case "shell":
content = scaffold.Shell
case "credential":
content = scaffold.Credential
case "admin":
content = scaffold.Admin
}
if content == "" {
println("need a valid -config option")
return false
}
if *outputPath != "" {
util.WriteFile(filepath.Join(util.ResolvePath(*outputPath), *config+".toml"), []byte(content), 0644)
} else {
fmt.Println(content)
}
return true
}