forked from rosa/hakurei
cmd/hakurei: terminate specified instance
This is theoretically susceptible to the PID race, but such an event is statistically impossible, and not exploitable in the intended use case, regardless. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Vendored
+6
@@ -36,6 +36,11 @@ _hakurei_show() {
|
|||||||
'files:files:__hakurei_files'
|
'files:files:__hakurei_files'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_hakurei_kill() {
|
||||||
|
_alternative \
|
||||||
|
'instances:domains:__hakurei_instances'
|
||||||
|
}
|
||||||
|
|
||||||
__hakurei_files() {
|
__hakurei_files() {
|
||||||
_files -g "*.(json|hakurei)"
|
_files -g "*.(json|hakurei)"
|
||||||
return $?
|
return $?
|
||||||
@@ -60,6 +65,7 @@ __hakurei_instances() {
|
|||||||
"run:Load and start container from configuration file"
|
"run:Load and start container from configuration file"
|
||||||
"exec:Configure and start a permissive container"
|
"exec:Configure and start a permissive container"
|
||||||
"show:Show live or local instance configuration"
|
"show:Show live or local instance configuration"
|
||||||
|
"kill:Terminate an active instance"
|
||||||
"ps:List active instances"
|
"ps:List active instances"
|
||||||
"version:Display version information"
|
"version:Display version information"
|
||||||
"license:Show full license text"
|
"license:Show full license text"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hakurei.app/check"
|
"hakurei.app/check"
|
||||||
@@ -372,6 +373,23 @@ func buildCommand(ctx context.Context, msg message.Msg, early *earlyHardeningErr
|
|||||||
Flag(&flagNoStore, "no-store", command.BoolFlag(false), "Do not attempt to match from active instances")
|
Flag(&flagNoStore, "no-store", command.BoolFlag(false), "Do not attempt to match from active instances")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.NewCommand("kill", "Terminate an active instance", func(args []string) error {
|
||||||
|
if len(args) != 1 {
|
||||||
|
log.Fatal("kill requires 1 argument")
|
||||||
|
}
|
||||||
|
|
||||||
|
var sc hst.Paths
|
||||||
|
env.CopyPaths().Copy(&sc, new(outcome.Hsu).MustID(nil))
|
||||||
|
entry := tryIdentifier(msg, args[0], outcome.NewStore(&sc))
|
||||||
|
if entry == nil {
|
||||||
|
log.Fatalf("%q does not match any active instance", args[0])
|
||||||
|
}
|
||||||
|
if err := syscall.Kill(entry.PID, syscall.SIGTERM); err != nil {
|
||||||
|
log.Fatalf("cannot terminate %s: %v", entry.ID.String(), err)
|
||||||
|
}
|
||||||
|
return errSuccess
|
||||||
|
})
|
||||||
|
|
||||||
{
|
{
|
||||||
var flagShort bool
|
var flagShort bool
|
||||||
c.NewCommand("ps", "List active instances", func(args []string) error {
|
c.NewCommand("ps", "List active instances", func(args []string) error {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ commands:
|
|||||||
run Load and start container from configuration file
|
run Load and start container from configuration file
|
||||||
exec Configure and start a permissive container
|
exec Configure and start a permissive container
|
||||||
show Show live or local instance configuration
|
show Show live or local instance configuration
|
||||||
|
kill Terminate an active instance
|
||||||
ps List active instances
|
ps List active instances
|
||||||
version Display version information
|
version Display version information
|
||||||
license Show full license text
|
license Show full license text
|
||||||
|
|||||||
Reference in New Issue
Block a user