-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (33 loc) · 1.2 KB
/
main.go
File metadata and controls
41 lines (33 loc) · 1.2 KB
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
package main
import (
"path/filepath"
"time"
"github.com/utmstack/UTMStack/agent/self/config"
"github.com/utmstack/UTMStack/agent/self/update"
"github.com/utmstack/UTMStack/agent/self/utils"
)
func main() {
path := utils.GetMyPath()
utils.InitLogger(filepath.Join(path, "logs", config.SERV_LOG))
utils.SelfLogger.Info("Updating %s...", config.SERV_NAME)
if isRunning, err := utils.CheckIfServiceIsActive(config.SERV_NAME); err != nil {
utils.SelfLogger.Fatal("error checking %s service: %v", config.SERV_NAME, err)
} else if isRunning {
err = utils.StopService(config.SERV_NAME)
if err != nil {
utils.SelfLogger.Fatal("error stopping %s service: %v", config.SERV_NAME, err)
}
utils.SelfLogger.Info("%s stopped correctly", config.SERV_NAME)
}
time.Sleep(10 * time.Second)
err := update.RunUpdate()
if err != nil {
utils.SelfLogger.Fatal("error updating new %s service: %v", config.SERV_NAME, err)
}
utils.SelfLogger.Info("New %s downloaded correctly", config.SERV_NAME)
err = utils.RestartService(config.SERV_NAME)
if err != nil {
utils.SelfLogger.Fatal("error restarting %s service: %v", config.SERV_NAME, err)
}
utils.SelfLogger.Info("%s updated correctly", config.SERV_NAME)
}