Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 32e9f36

Browse files
committed
fixes.
1 parent becf993 commit 32e9f36

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"log"
5+
"os"
56

67
"github.com/spf13/viper"
78
)
@@ -53,9 +54,11 @@ func LoadConfig() {
5354

5455
viper.AutomaticEnv()
5556

56-
if err := viper.ReadInConfig(); err != nil {
57-
log.Fatalf("can't load config: %s", err.Error())
58-
}
57+
if _, err := os.Stat(".env"); err == nil {
58+
if err := viper.ReadInConfig(); err != nil {
59+
log.Fatalf("can't load config: %s", err.Error())
60+
}
61+
}
5962

6063
if err := viper.Unmarshal(&config); err != nil {
6164
log.Fatalf("can't load config: %s", err.Error())

main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import (
77
"html/template"
88
"log"
99
"net/http"
10+
"os"
11+
"os/signal"
1012
"path"
1113
"slices"
14+
"syscall"
1215

1316
"github.com/fiatjaf/eventstore/badger"
1417
"github.com/fiatjaf/eventstore/bluge"
@@ -38,6 +41,7 @@ func main() {
3841
relay.Info.Icon = config.RelayIcon
3942
relay.Info.Contact = config.RelayContact
4043
relay.Info.PubKey = config.RelayPublicKey
44+
relay.Info.URL = config.RelayURL
4145
relay.Info.Version = StringVersion()
4246
relay.Info.Software = "https://github.com/dezh-tech/alienos"
4347

@@ -122,8 +126,14 @@ func main() {
122126
}
123127

124128
log.Printf("Serving on ws://%s\n", config.RelayBind+config.RelayPort)
125-
http.ListenAndServe(config.RelayBind+config.RelayPort, relay)
129+
go http.ListenAndServe(config.RelayBind+config.RelayPort, relay)
126130

131+
sigChan := make(chan os.Signal, 1)
132+
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
133+
134+
sig := <-sigChan
135+
136+
log.Print("Received signal: Initiating graceful shutdown", "signal", sig.String())
127137
badgerDB.Close()
128138
blugeDB.Close()
129139
}
Binary file not shown.

0 commit comments

Comments
 (0)