snapshot: Lock instances before making snapshot
This commit is contained in:
parent
f1c5d518c2
commit
5e7c5b2d23
11 changed files with 167 additions and 0 deletions
|
|
@ -58,6 +58,7 @@ func (i info) Run(context wisski_distillery.Context) error {
|
|||
context.Printf("GraphDB Password: %v\n", instance.GraphDBPassword)
|
||||
|
||||
context.Printf("Running: %v\n", info.Running)
|
||||
context.Printf("Locked: %v\n", info.Locked)
|
||||
context.Printf("Last Rebuild: %v\n", info.LastRebuild.String())
|
||||
|
||||
context.Printf("Skip Prefixes: %v\n", info.NoPrefixes)
|
||||
|
|
|
|||
67
cmd/instance_lock.go
Normal file
67
cmd/instance_lock.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/core"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
// InstanceLock is then 'instance_lock' command
|
||||
var InstanceLock wisski_distillery.Command = instanceLock{}
|
||||
|
||||
type instanceLock struct {
|
||||
Lock bool `short:"l" long:"lock" description:"Lock the provided WissKI instance"`
|
||||
Unlock bool `short:"u" long:"unlock" description:"Unlock the provided WissKI instance"`
|
||||
Positionals struct {
|
||||
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to lock or unlock"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (instanceLock) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: core.Requirements{
|
||||
NeedsDistillery: true,
|
||||
},
|
||||
Command: "instance_lock",
|
||||
Description: "Locks or unlocks a WissKI instance",
|
||||
}
|
||||
}
|
||||
|
||||
var errLockUnlockExcluded = exit.Error{
|
||||
Message: "Exactly one of `--lock` and `--unlock` must be provied",
|
||||
ExitCode: exit.ExitCommandArguments,
|
||||
}
|
||||
|
||||
func (l instanceLock) AfterParse() error {
|
||||
if l.Lock == l.Unlock {
|
||||
return errLockUnlockExcluded
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var errNotUnlock = exit.Error{
|
||||
Message: "Unable to unlock instance: Not locked",
|
||||
ExitCode: exit.ExitCommandArguments,
|
||||
}
|
||||
|
||||
func (l instanceLock) Run(context wisski_distillery.Context) error {
|
||||
instance, err := context.Environment.Instances().WissKI(l.Positionals.Slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if l.Unlock {
|
||||
if !instance.Unlock() {
|
||||
return errNotUnlock
|
||||
}
|
||||
context.Println("unlocked")
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := instance.TryLock(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
context.Println("locked")
|
||||
return nil
|
||||
}
|
||||
|
|
@ -102,6 +102,12 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
// remove the filesystem
|
||||
logging.LogMessage(context.IOStream, "Remove lock data", instance.FilesystemBase)
|
||||
if !instance.Unlock() {
|
||||
context.EPrintln("instance was not locked")
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Instance %s has been purged", slug)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ func init() {
|
|||
// instance management
|
||||
wdcli.Register(cmd.Ls)
|
||||
wdcli.Register(cmd.Info)
|
||||
wdcli.Register(cmd.InstanceLock)
|
||||
|
||||
// instance tasks
|
||||
wdcli.Register(cmd.Shell)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue