-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathreboot.go
43 lines (39 loc) · 954 Bytes
/
reboot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/WeTrustPlatform/blockform/model"
"github.com/WeTrustPlatform/blockform/sshcmd"
"goji.io/pat"
)
// RebootNode reboots the VM where the node is hosted
func rebootNode(ctx context.Context, node model.Node, callback func()) {
_, _, err := sshcmd.Exec(
os.Getenv("PRIV_KEY"),
os.Getenv("PASSPHRASE"),
"blockform",
node.DomainName,
"sudo reboot",
)
if err != nil {
log.Println(err)
}
callback()
}
func handleReboot(w http.ResponseWriter, r *http.Request) {
ID := pat.Param(r, "id")
node := model.Node{}
db.Find(&node, ID)
log.Println("Rebooting node", node.Name)
go rebootNode(context.Background(), node, func() {
db.Create(&model.Event{
NodeID: node.ID,
Type: model.Fine,
Title: "The node has been manually rebooted",
})
log.Println("Done rebooting node " + node.Name)
})
http.Redirect(w, r, "/node/"+ID+"/activity", http.StatusSeeOther)
}