93bdd3ebd4
Previously if the `daemon.yml` of a host was changed it would first start up, load that new daemon.yml in, persist the new configuration for the host to garage using `update-garage-host`, pull that config back down and persist it to the bootstrap in `runDaemonPmuxOnce`, and restart all child processes so they get the new config. Now, once `daemon.yml` is loaded in we immediately merge it into and persist this host's bootstrap file, prior to ever starting child processes. This removes the necessity of restarting those process at start. This change also allows the bootstrap file to be the sole repository of information required to pick a garage node to connect to, since it is presumably always as up-to-date as it can possibly be. This allows for removing some more logic from `Env`.
119 lines
2.6 KiB
Go
119 lines
2.6 KiB
Go
package entrypoint
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
var subCmdGarageMC = subCmd{
|
|
name: "mc",
|
|
descr: "Runs the mc (minio-client) binary. The cryptic-net garage can be accessed under the `garage` alias",
|
|
checkLock: true,
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
flags := subCmdCtx.flagSet(true)
|
|
|
|
keyID := flags.StringP(
|
|
"key-id", "i", "",
|
|
"Optional key ID to use, defaults to that of the shared cryptic-net-global key",
|
|
)
|
|
|
|
keySecret := flags.StringP(
|
|
"key-secret", "s", "",
|
|
"Optional key secret to use, defaults to that of the shared cryptic-net-global key",
|
|
)
|
|
|
|
if err := flags.Parse(subCmdCtx.args); err != nil {
|
|
return fmt.Errorf("parsing flags: %w", err)
|
|
}
|
|
|
|
env := subCmdCtx.env
|
|
|
|
s3APIAddr := env.Bootstrap.ChooseGaragePeer().S3APIAddr()
|
|
|
|
if *keyID == "" || *keySecret == "" {
|
|
|
|
if *keyID == "" {
|
|
*keyID = env.Bootstrap.GarageGlobalBucketS3APICredentials.ID
|
|
}
|
|
|
|
if *keySecret == "" {
|
|
*keyID = env.Bootstrap.GarageGlobalBucketS3APICredentials.Secret
|
|
}
|
|
}
|
|
|
|
args := flags.Args()
|
|
|
|
if i := flags.ArgsLenAtDash(); i >= 0 {
|
|
args = args[i:]
|
|
}
|
|
|
|
args = append([]string{"mc"}, args...)
|
|
|
|
var (
|
|
binPath = env.BinPath("mc")
|
|
cliEnv = append(
|
|
os.Environ(),
|
|
fmt.Sprintf(
|
|
"MC_HOST_garage=http://%s:%s@%s",
|
|
*keyID, *keySecret, s3APIAddr,
|
|
),
|
|
|
|
// The garage docs say this is necessary, though nothing bad
|
|
// seems to happen if we leave it out *shrug*
|
|
"MC_REGION=garage",
|
|
)
|
|
)
|
|
|
|
if err := syscall.Exec(binPath, args, cliEnv); err != nil {
|
|
return fmt.Errorf(
|
|
"calling exec(%q, %#v, %#v): %w",
|
|
binPath, args, cliEnv, err,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var subCmdGarageCLI = subCmd{
|
|
name: "cli",
|
|
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running cryptic-net daemon",
|
|
checkLock: true,
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
env := subCmdCtx.env
|
|
|
|
var (
|
|
binPath = env.BinPath("garage")
|
|
args = append([]string{"garage"}, subCmdCtx.args...)
|
|
cliEnv = append(
|
|
os.Environ(),
|
|
"GARAGE_RPC_HOST="+env.Bootstrap.ChooseGaragePeer().RPCAddr(),
|
|
"GARAGE_RPC_SECRET="+env.Bootstrap.GarageRPCSecret,
|
|
)
|
|
)
|
|
|
|
if err := syscall.Exec(binPath, args, cliEnv); err != nil {
|
|
return fmt.Errorf(
|
|
"calling exec(%q, %#v, %#v): %w",
|
|
binPath, args, cliEnv, err,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var subCmdGarage = subCmd{
|
|
name: "garage",
|
|
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running cryptic-net daemon",
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
return subCmdCtx.doSubCmd(
|
|
subCmdGarageCLI,
|
|
subCmdGarageMC,
|
|
)
|
|
},
|
|
}
|