instance_pause: Add buttons to start/stop instance
This commit is contained in:
parent
092304f891
commit
1f7d92bea8
4 changed files with 67 additions and 0 deletions
47
cmd/instance_pause.go
Normal file
47
cmd/instance_pause.go
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InstancePause is the 'instance_pause' command
|
||||||
|
var InstancePause wisski_distillery.Command = instancepause{}
|
||||||
|
|
||||||
|
type instancepause struct {
|
||||||
|
Stop bool `short:"d" long:"stop" description:"stop instance"`
|
||||||
|
Start bool `short:"u" long:"start" description:"start (or restart) instance"`
|
||||||
|
Positionals struct {
|
||||||
|
Slug string `positional-arg-name:"slug" required:"1-1" description:"name of instance to purge"`
|
||||||
|
} `positional-args:"true"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instancepause) Description() wisski_distillery.Description {
|
||||||
|
return wisski_distillery.Description{
|
||||||
|
Requirements: cli.Requirements{
|
||||||
|
NeedsDistillery: true,
|
||||||
|
},
|
||||||
|
Command: "instance_pause",
|
||||||
|
Description: "stops or starts a single instance",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i instancepause) AfterParse() error {
|
||||||
|
if i.Stop == i.Start {
|
||||||
|
return errStopStartExcluded
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i instancepause) Run(context wisski_distillery.Context) error {
|
||||||
|
instance, err := context.Environment.Instances().WissKI(context.Context, i.Positionals.Slug)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if i.Stop {
|
||||||
|
return instance.Barrel().Stack().Down(context.Context, context.Stdout)
|
||||||
|
} else {
|
||||||
|
return instance.Barrel().Stack().Up(context.Context, context.Stdout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -39,6 +39,7 @@ func init() {
|
||||||
wdcli.Register(cmd.Ls)
|
wdcli.Register(cmd.Ls)
|
||||||
wdcli.Register(cmd.Info)
|
wdcli.Register(cmd.Info)
|
||||||
wdcli.Register(cmd.InstanceLock)
|
wdcli.Register(cmd.InstanceLock)
|
||||||
|
wdcli.Register(cmd.InstancePause)
|
||||||
|
|
||||||
// instance tasks
|
// instance tasks
|
||||||
wdcli.Register(cmd.Shell)
|
wdcli.Register(cmd.Shell)
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,15 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<code>{{ .Info.Running }}</code>
|
<code>{{ .Info.Running }}</code>
|
||||||
|
<div class="pure-button-group" role="group">
|
||||||
|
<button class="remote-action pure-button pure-button-action" data-action="start" data-param="{{ .Instance.Slug }}" data-buffer="1000" data-force-reload="true">
|
||||||
|
(Re)Start
|
||||||
|
</button>
|
||||||
|
<button class="remote-action pure-button pure-button-danger" data-action="stop" data-param="{{ .Instance.Slug }}" data-buffer="1000" data-force-reload="true">
|
||||||
|
Stop
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,16 @@ var socketInstanceActions = map[string]InstanceAction{
|
||||||
return instance.Drush().Cron(ctx, str)
|
return instance.Drush().Cron(ctx, str)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"start": {
|
||||||
|
HandleInteractive: func(ctx context.Context, _ *Admin, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
||||||
|
return instance.Barrel().Stack().Up(ctx, out)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"stop": {
|
||||||
|
HandleInteractive: func(ctx context.Context, _ *Admin, instance *wisski.WissKI, out io.Writer, params ...string) error {
|
||||||
|
return instance.Barrel().Stack().Down(ctx, out)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func (admin *Admin) serveSocket(conn httpx.WebSocketConnection) {
|
func (admin *Admin) serveSocket(conn httpx.WebSocketConnection) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue