add Shutdown action
This commit is contained in:
@@ -47,6 +47,10 @@ func NewSingleAction(config internal.ActionConfig, c chan bool) (Action, error)
|
|||||||
return NewTimeOut(config, c)
|
return NewTimeOut(config, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Type == "Shutdown" {
|
||||||
|
return NewShutdown(config, c)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("Error parsing config: Action with type %s does not exists", config.Type)
|
return nil, fmt.Errorf("Error parsing config: Action with type %s does not exists", config.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,5 +96,6 @@ func GetDocumenters() []internal.Documenter {
|
|||||||
return []internal.Documenter{
|
return []internal.Documenter{
|
||||||
Printer{},
|
Printer{},
|
||||||
TimeOut{},
|
TimeOut{},
|
||||||
|
Shutdown{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
actions/shutdown.go
Normal file
38
actions/shutdown.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package actions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"unknown.com/gokill/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Shutdown struct {
|
||||||
|
ActionChan chan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Shutdown) Execute() {
|
||||||
|
if err := exec.Command("shutdown", "-h", "now").Run(); err != nil {
|
||||||
|
fmt.Println("Failed to initiate shutdown:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Shutdown executed...")
|
||||||
|
|
||||||
|
c.ActionChan <- true
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewShutdown(config internal.ActionConfig, c chan bool) (Action, error) {
|
||||||
|
return Shutdown{c}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Shutdown) GetName() string {
|
||||||
|
return "Shutdown"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Shutdown) GetDescription() string {
|
||||||
|
return "When triggered shuts down the machine"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Shutdown) GetOptions() []internal.ConfigOption {
|
||||||
|
return []internal.ConfigOption{}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user