mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -05:00
expiry: Remove auto-expiry.
Move the logic outside and use scripting, cronjob to delete files. Fixes #1019
This commit is contained in:
parent
15924a8f05
commit
454d71cafa
@ -1,41 +0,0 @@
|
|||||||
package fs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AutoExpiryThread - auto expiry thread
|
|
||||||
func (fs Filesystem) AutoExpiryThread(expiry time.Duration) {
|
|
||||||
expireFiles := func(fp string, fl os.FileInfo, err error) error {
|
|
||||||
if fp == fs.path {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if fl.Mode().IsRegular() || fl.Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
||||||
if time.Now().Sub(fl.ModTime()) > expiry {
|
|
||||||
if err := os.Remove(fp); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ErrDirNotEmpty
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ticker := time.NewTicker(3 * time.Hour)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
// TODO - add a way to stop the timer thread
|
|
||||||
case <-ticker.C:
|
|
||||||
err := WalkUnsorted(fs.path, expireFiles)
|
|
||||||
if err != nil {
|
|
||||||
if !os.IsNotExist(err) && err != ErrDirNotEmpty {
|
|
||||||
ticker.Stop()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -146,9 +146,6 @@ func getNewCloudStorageAPI(conf cloudServerConfig) CloudStorageAPI {
|
|||||||
fatalIf(err.Trace(), "Initializing filesystem failed.", nil)
|
fatalIf(err.Trace(), "Initializing filesystem failed.", nil)
|
||||||
|
|
||||||
fs.SetMinFreeDisk(conf.MinFreeDisk)
|
fs.SetMinFreeDisk(conf.MinFreeDisk)
|
||||||
if conf.Expiry > 0 {
|
|
||||||
go fs.AutoExpiryThread(conf.Expiry)
|
|
||||||
}
|
|
||||||
return CloudStorageAPI{
|
return CloudStorageAPI{
|
||||||
Filesystem: fs,
|
Filesystem: fs,
|
||||||
AccessLog: conf.AccessLog,
|
AccessLog: conf.AccessLog,
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
@ -44,7 +43,6 @@ var serverCmd = cli.Command{
|
|||||||
USAGE:
|
USAGE:
|
||||||
minio {{.Name}} [OPTION VALUE] PATH
|
minio {{.Name}} [OPTION VALUE] PATH
|
||||||
|
|
||||||
OPTION = expiry VALUE = NN[h|m|s] [DEFAULT=Unlimited]
|
|
||||||
OPTION = min-free-disk VALUE = NN% [DEFAULT: 10%]
|
OPTION = min-free-disk VALUE = NN% [DEFAULT: 10%]
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
@ -60,9 +58,6 @@ EXAMPLES:
|
|||||||
4. Start minio server with minimum free disk threshold to 5%
|
4. Start minio server with minimum free disk threshold to 5%
|
||||||
$ minio {{.Name}} min-free-disk 5% /home/shared/Pictures
|
$ minio {{.Name}} min-free-disk 5% /home/shared/Pictures
|
||||||
|
|
||||||
5. Start minio server with minimum free disk threshold to 15% with auto expiration set to 1h
|
|
||||||
$ minio {{.Name}} min-free-disk 15% expiry 1h /home/shared/Documents
|
|
||||||
|
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,9 +72,8 @@ type cloudServerConfig struct {
|
|||||||
SecretAccessKey string // Secret access key.
|
SecretAccessKey string // Secret access key.
|
||||||
|
|
||||||
/// FS options
|
/// FS options
|
||||||
Path string // Path to export for cloud storage
|
Path string // Path to export for cloud storage
|
||||||
MinFreeDisk int64 // Minimum free disk space for filesystem
|
MinFreeDisk int64 // Minimum free disk space for filesystem
|
||||||
Expiry time.Duration // Set auto expiry for filesystem
|
|
||||||
|
|
||||||
/// TLS service
|
/// TLS service
|
||||||
TLS bool // TLS on when certs are specified
|
TLS bool // TLS on when certs are specified
|
||||||
@ -297,11 +291,8 @@ func serverMain(c *cli.Context) {
|
|||||||
// Default
|
// Default
|
||||||
minFreeDisk = 10
|
minFreeDisk = 10
|
||||||
|
|
||||||
var expiration time.Duration
|
|
||||||
expirationSet := false
|
|
||||||
|
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
for len(args) >= 2 {
|
for len(args) >= 1 {
|
||||||
switch args.First() {
|
switch args.First() {
|
||||||
case "min-free-disk":
|
case "min-free-disk":
|
||||||
if minFreeDiskSet {
|
if minFreeDiskSet {
|
||||||
@ -313,16 +304,6 @@ func serverMain(c *cli.Context) {
|
|||||||
fatalIf(err.Trace(args.First()), "Invalid minium free disk size "+args.First()+" passed.", nil)
|
fatalIf(err.Trace(args.First()), "Invalid minium free disk size "+args.First()+" passed.", nil)
|
||||||
args = args.Tail()
|
args = args.Tail()
|
||||||
minFreeDiskSet = true
|
minFreeDiskSet = true
|
||||||
case "expiry":
|
|
||||||
if expirationSet {
|
|
||||||
fatalIf(probe.NewError(errInvalidArgument), "Expiration should be set only once.", nil)
|
|
||||||
}
|
|
||||||
args = args.Tail()
|
|
||||||
var err error
|
|
||||||
expiration, err = time.ParseDuration(args.First())
|
|
||||||
fatalIf(probe.NewError(err), "Invalid expiration time "+args.First()+" passed.", nil)
|
|
||||||
args = args.Tail()
|
|
||||||
expirationSet = true
|
|
||||||
default:
|
default:
|
||||||
cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
@ -341,7 +322,6 @@ func serverMain(c *cli.Context) {
|
|||||||
SecretAccessKey: conf.Credentials.SecretAccessKey,
|
SecretAccessKey: conf.Credentials.SecretAccessKey,
|
||||||
Path: path,
|
Path: path,
|
||||||
MinFreeDisk: minFreeDisk,
|
MinFreeDisk: minFreeDisk,
|
||||||
Expiry: expiration,
|
|
||||||
TLS: tls,
|
TLS: tls,
|
||||||
CertFile: certFile,
|
CertFile: certFile,
|
||||||
KeyFile: keyFile,
|
KeyFile: keyFile,
|
||||||
|
Loading…
Reference in New Issue
Block a user