aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main.go20
-rw-r--r--src/app.go16
-rw-r--r--src/templates.go6
3 files changed, 37 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()
diff --git a/src/app.go b/src/app.go
new file mode 100644
index 0000000..7b3d905
--- /dev/null
+++ b/src/app.go
@@ -0,0 +1,16 @@
+package app
+
+import (
+ "os"
+ "syscall"
+
+ "git.thomasvoss.com/euro-cash.eu/pkg/atexit"
+ . "git.thomasvoss.com/euro-cash.eu/pkg/try"
+)
+
+func Restart() {
+ path := Try2(os.Executable())
+ atexit.Exec()
+ Try(syscall.Exec(path, append([]string{path}, os.Args[1:]...),
+ os.Environ()))
+}
diff --git a/src/templates.go b/src/templates.go
index 20fcf79..353c755 100644
--- a/src/templates.go
+++ b/src/templates.go
@@ -46,6 +46,12 @@ func BuildTemplates(dir fs.FS, debugp bool) {
buildAndSetTemplate(dir, name)
if debugp {
go watch.FileFS(dir, name, func() {
+ defer func() {
+ if p := recover(); p != nil {
+ log.Print(p)
+ }
+ }()
+
buildAndSetTemplate(dir, name)
log.Printf("Template ā€˜%s’ updated\n", name)
})