[actions/shutdown] add time option to control delay
This commit is contained in:
@@ -3,23 +3,24 @@ package actions
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"encoding/json"
|
||||
|
||||
"unknown.com/gokill/internal"
|
||||
)
|
||||
|
||||
type Shutdown struct {
|
||||
Timeout string `json:"time"`
|
||||
ActionChan ActionResultChan
|
||||
}
|
||||
|
||||
func (s Shutdown) DryExecute() {
|
||||
fmt.Printf("shutdown -h %s\n", s.Timeout)
|
||||
fmt.Println("Test Shutdown executed...")
|
||||
|
||||
s.ActionChan <- nil
|
||||
|
||||
}
|
||||
|
||||
func (s Shutdown) Execute() {
|
||||
if err := exec.Command("shutdown", "-h", "now").Run(); err != nil {
|
||||
if err := exec.Command("shutdown", "-h", s.Timeout).Run(); err != nil {
|
||||
fmt.Println("Failed to initiate shutdown:", err)
|
||||
}
|
||||
|
||||
@@ -29,7 +30,16 @@ func (s Shutdown) Execute() {
|
||||
}
|
||||
|
||||
func (s Shutdown) Create(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||
return Shutdown{c}, nil
|
||||
var result Shutdown
|
||||
err := json.Unmarshal(config.Options, &result)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Parsing Shutdown options failed.")
|
||||
return Shutdown{}, err
|
||||
}
|
||||
|
||||
result.ActionChan = c
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p Shutdown) GetName() string {
|
||||
@@ -44,10 +54,20 @@ func (p Shutdown) GetExample() string {
|
||||
return `
|
||||
{
|
||||
"type": "Shutdown",
|
||||
"options": {
|
||||
"time": "+5" //wait 5 minutes before shutdown
|
||||
}
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
func (p Shutdown) GetOptions() []internal.ConfigOption {
|
||||
return []internal.ConfigOption{}
|
||||
return []internal.ConfigOption{
|
||||
{
|
||||
Name: "time",
|
||||
Type: "string",
|
||||
Description: "TIME parameter passed to shutdown as follows ```shutdown -h TIME```",
|
||||
Default: "now",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user