aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2025-07-27 17:14:27 +0200
committerThomas Voss <mail@thomasvoss.com> 2025-07-27 17:14:27 +0200
commit50bd8ef6d4f48a48f623564e6b63f346904e6421 (patch)
treee4385989b7a92bb484fdffb4c21ded4a9d9493f8 /main.go
parentc9b91a8bb1d9249c0617bfa52f0129a9d5d123c5 (diff)
Improve on debug mode
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/main.go b/main.go
index ff1ced3..f73567b 100644
--- a/main.go
+++ b/main.go
@@ -5,10 +5,13 @@ package main
import (
"flag"
+ "fmt"
+ "log"
"os"
"os/signal"
"path/filepath"
"syscall"
+ "time"
"git.thomasvoss.com/euro-cash.eu/pkg/atexit"
. "git.thomasvoss.com/euro-cash.eu/pkg/try"
@@ -41,6 +44,17 @@ func main() {
"database name or ‘:memory:’ for an in-memory database")
flag.Parse()
+ defer func() {
+ if p := recover(); p != nil {
+ if *debugp {
+ log.Print(p)
+ time.Sleep(1 * time.Second)
+ app.Restart()
+ }
+ email.Send("URGENT: Server Panicked", fmt.Sprint(p))
+ }
+ }()
+
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
@@ -50,11 +64,7 @@ func main() {
}()
if *debugp {
- path := Try2(os.Executable())
- go watch.File(path, func() {
- atexit.Exec()
- Try(syscall.Exec(path, os.Args, os.Environ()))
- })
+ go watch.File(Try2(os.Executable()), app.Restart)
}
i18n.Init()