This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the local store directory to be configurable
Introduce the `--storeDir` flag to allow the local store directory to be configurable. Update README with example on how to set it via a mounted volume.
- Loading branch information
Showing
5 changed files
with
84 additions
and
21 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
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 |
---|---|---|
@@ -1,38 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/filecoin-project/motion" | ||
"github.com/filecoin-project/motion/blob" | ||
"github.com/ipfs/go-log/v2" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var logger = log.Logger("motion/cmd") | ||
|
||
func main() { | ||
// TODO: add flags, options and all that jazz | ||
if _, set := os.LookupEnv("GOLOG_LOG_LEVEL"); !set { | ||
_ = log.SetLogLevel("*", "INFO") | ||
} | ||
m, err := motion.New() | ||
if err != nil { | ||
logger.Fatalw("Failed to instantiate Motion", "err", err) | ||
} | ||
ctx := context.Background() | ||
app := cli.App{ | ||
Name: "motion", | ||
Usage: "Propelling data onto FileCoin", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "storeDir", | ||
Usage: "The path at which to store Motion data", | ||
DefaultText: "OS Temporary directory", | ||
Value: os.TempDir(), | ||
EnvVars: []string{"MOTION_STORE_DIR"}, | ||
}, | ||
}, | ||
Action: func(cctx *cli.Context) error { | ||
storeDir := cctx.String("storeDir") | ||
logger.Infow("Using local blob store", "storeDir", storeDir) | ||
m, err := motion.New( | ||
motion.WithBlobStore(blob.NewLocalStore(storeDir)), | ||
) | ||
if err != nil { | ||
logger.Fatalw("Failed to instantiate Motion", "err", err) | ||
} | ||
ctx := cctx.Context | ||
|
||
if err := m.Start(ctx); err != nil { | ||
logger.Fatalw("Failed to start Motion", "err", err) | ||
if err := m.Start(ctx); err != nil { | ||
logger.Fatalw("Failed to start Motion", "err", err) | ||
} | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
<-c | ||
logger.Info("Terminating...") | ||
if err := m.Shutdown(ctx); err != nil { | ||
logger.Warnw("Failure occurred while shutting down Motion.", "err", err) | ||
return err | ||
} | ||
logger.Info("Shut down Motion successfully.") | ||
return nil | ||
}, | ||
} | ||
|
||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
<-c | ||
logger.Info("Terminating...") | ||
if err := m.Shutdown(ctx); err != nil { | ||
logger.Warnw("Failure occurred while shutting down Motion.", "err", err) | ||
} else { | ||
logger.Info("Shut down Motion successfully.") | ||
if err := app.Run(os.Args); err != nil { | ||
logger.Error(err) | ||
} | ||
} |
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