add option to run application as service

This commit is contained in:
Jonas Leder 2024-06-16 16:25:33 +02:00
commit b466a93432
2 changed files with 16 additions and 2 deletions

View file

@ -7,7 +7,7 @@ import (
)
var Log *logrus.Logger
var elog eventlog.Log
var evtlog *eventlog.Log
func Init() {
Log = logrus.New()
@ -16,8 +16,9 @@ func Init() {
panic(err)
}
Log.Hooks.Add(eventloghook.NewHook(elog))
evtlog = elog
}
func Close() {
elog.Close()
evtlog.Close()
}

13
main.go
View file

@ -1,6 +1,7 @@
package main
import (
"os"
"strconv"
"strings"
@ -12,6 +13,17 @@ import (
func main() {
log.Init()
log.Log.Info("Running Cloud-Init for Windows")
// if the applications runs as service, it should never exit
if len(os.Args) > 1 && os.Args[1] == "service" {
go application()
for {
}
} else {
application()
}
}
func application() {
rebootRequired := false
var cloudInitConfig cloudinit.CloudInit
@ -61,5 +73,6 @@ func main() {
log.Log.Warn("Reboot is required to apply the changes")
//TODO: add reboot
}
log.Log.Info("Done executing Cloud-Init")
log.Close()
}