From 8b63561befea78c3a397304dd46dc048a4de5723 Mon Sep 17 00:00:00 2001 From: asandikci Date: Mon, 31 Jul 2023 14:11:11 +0300 Subject: [PATCH] restart capability --- .gitignore | 3 ++- go-daemon/godaemon1.go | 5 +---- go-daemon/service/restart.go | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 go-daemon/service/restart.go diff --git a/.gitignore b/.gitignore index 67a015d..bd09563 100644 --- a/.gitignore +++ b/.gitignore @@ -78,4 +78,5 @@ dkms.conf ### USER MODIFIED ### c-daemon/bin/ -go-daemon/bin/ \ No newline at end of file +go-daemon/bin/ +go-daemon/local-ref.sh \ No newline at end of file diff --git a/go-daemon/godaemon1.go b/go-daemon/godaemon1.go index 03468fa..99432a7 100644 --- a/go-daemon/godaemon1.go +++ b/go-daemon/godaemon1.go @@ -28,11 +28,8 @@ func main() { log.Print("- - - - - - - - - - - - - - -") log.Print("daemon started") - log.Print(d, err) - // process, err := os.FindProcess(1) - // daemon.SendCommands(process) - for true { + for { Info() time.Sleep(10 * time.Second) } diff --git a/go-daemon/service/restart.go b/go-daemon/service/restart.go new file mode 100644 index 0000000..2458616 --- /dev/null +++ b/go-daemon/service/restart.go @@ -0,0 +1,21 @@ +package service + +import ( + "log" + "os" + "syscall" +) + +func Restart() error { + log.Println("Restart Signal Caught") + + // TODO what you want to do before restarting daemon? + + self, err := os.Executable() + if err != nil { + return err + } + args := os.Args + env := os.Environ() + return syscall.Exec(self, args, env) +}