longer timeouts, various improvements

pull/174/head
Simon Let 4 years ago
parent 45c66208a1
commit 3d18e16015
No known key found for this signature in database
GPG Key ID: D650C65DD46D431D
  1. 13
      cmd/daemon/main.go
  2. 5
      cmd/daemon/run-server.go
  3. 8
      cmd/daemon/status.go
  4. 5
      cmd/inspect/main.go
  5. 5
      pkg/collect/collect.go
  6. 2
      pkg/httpclient/httpclient.go
  7. 6
      pkg/signalhandler/signalhander.go
  8. 5
      scripts/reshctl.sh
  9. 5
      scripts/widgets.sh

@ -38,7 +38,7 @@ func main() {
f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatal("Error opening file:", err)
log.Fatalf("Error opening file: %v\n", err)
}
defer f.Close()
@ -47,7 +47,7 @@ func main() {
var config cfg.Config
if _, err := toml.DecodeFile(configPath, &config); err != nil {
log.Println("Error reading config", err)
log.Printf("Error reading config: %v\n", err)
return
}
if config.Debug {
@ -57,7 +57,8 @@ func main() {
res, err := isDaemonRunning(config.Port)
if err != nil {
log.Println("Error while checking if the daemon is runnnig", err)
log.Printf("Error while checking if the daemon is runnnig"+
" - it's probably not running: %v\n", err)
}
if res {
log.Println("Daemon is already running - exiting!")
@ -69,18 +70,18 @@ func main() {
// kill daemon
err = killDaemon(pidfilePath)
if err != nil {
log.Println("Error while killing daemon", err)
log.Printf("Error while killing daemon: %v\n", err)
}
}
err = ioutil.WriteFile(pidfilePath, []byte(strconv.Itoa(os.Getpid())), 0644)
if err != nil {
log.Fatal("Could not create pidfile", err)
log.Fatalf("Could not create pidfile: %v\n", err)
}
runServer(config, reshHistoryPath, bashHistoryPath, zshHistoryPath)
log.Println("main: Removing pidfile ...")
err = os.Remove(pidfilePath)
if err != nil {
log.Println("Could not delete pidfile", err)
log.Printf("Could not delete pidfile: %v\n", err)
}
log.Println("main: Shutdown - bye")
}

@ -64,7 +64,10 @@ func runServer(config cfg.Config, reshHistoryPath, bashHistoryPath, zshHistoryPa
mux.Handle("/inspect", &inspectHandler{sesshistDispatch: sesshistDispatch})
mux.Handle("/dump", &dumpHandler{histfileBox: histfileBox})
server := &http.Server{Addr: "localhost:" + strconv.Itoa(config.Port), Handler: mux}
server := &http.Server{
Addr: "localhost:" + strconv.Itoa(config.Port),
Handler: mux,
}
go server.ListenAndServe()
// signalhandler - takes over the main goroutine so when signal handler exists the whole program exits

@ -6,6 +6,7 @@ import (
"net/http"
"strconv"
"github.com/curusarn/resh/pkg/httpclient"
"github.com/curusarn/resh/pkg/msg"
)
@ -28,10 +29,11 @@ func statusHandler(w http.ResponseWriter, r *http.Request) {
func isDaemonRunning(port int) (bool, error) {
url := "http://localhost:" + strconv.Itoa(port) + "/status"
resp, err := http.Get(url)
client := httpclient.New()
resp, err := client.Get(url)
if err != nil {
log.Println("Error while checking daemon status - "+
"it's probably not running!", err)
log.Printf("Error while checking daemon status - "+
"it's probably not running: %v\n", err)
return false, err
}
defer resp.Body.Close()

@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
"time"
"github.com/BurntSushi/toml"
"github.com/curusarn/resh/pkg/cfg"
@ -63,7 +64,9 @@ func SendInspectMsg(m msg.InspectMsg, port string) msg.MultiResponse {
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
client := http.Client{
Timeout: 3 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running - try restarting this terminal")

@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"github.com/curusarn/resh/pkg/httpclient"
"github.com/curusarn/resh/pkg/records"
)
@ -33,7 +34,7 @@ func SendRecallRequest(r records.SlimRecord, port string) (string, bool) {
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
client := httpclient.New()
resp, err := client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running - try restarting this terminal")
@ -68,7 +69,7 @@ func SendRecord(r records.Record, port, path string) {
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
client := httpclient.New()
_, err = client.Do(req)
if err != nil {
log.Fatal("resh-daemon is not running - try restarting this terminal")

@ -7,6 +7,6 @@ import (
func New() *http.Client {
return &http.Client{
Timeout: 100 * time.Millisecond,
Timeout: 500 * time.Millisecond,
}
}

@ -42,17 +42,17 @@ func sendSignals(sig os.Signal, subscribers []chan os.Signal, done chan string)
func Run(subscribers []chan os.Signal, done chan string, server *http.Server) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGQUIT)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
var sig os.Signal
for {
sig := <-signals
log.Println("signalhandler: Got signal " + sig.String())
log.Printf("signalhandler: Got signal '%s'\n", sig.String())
if sig == syscall.SIGTERM {
// Shutdown daemon on SIGTERM
break
}
log.Printf("signalhandler: Ignoring signal %s. Send SIGTERM to trigger shutdown.\n", sig.String())
log.Printf("signalhandler: Ignoring signal '%s'. Send SIGTERM to trigger shutdown.\n", sig.String())
}
log.Println("signalhandler: Sending shutdown signals to components")

@ -73,10 +73,9 @@ resh() {
elif [ $status_code = 130 ]; then
true
else
local tmp_file="$__RESH_XDG_CACHE_HOME/search_last_run_out.txt"
local tmp_file="$__RESH_XDG_CACHE_HOME/cli_last_run_out.txt"
echo "$buffer" >| "$tmp_file"
echo "resh-cli ERROR:"
cat "$tmp_file"
echo "resh-cli failed - check '$tmp_file' and '~/.resh/cli.log'"
fi
}

@ -35,8 +35,9 @@ __resh_widget_control_R() {
bind -x '"\u[32~": __resh_nop'
fi
else
echo "$BUFFER" >| ~/.resh/cli_last_run_out.txt
echo "# RESH SEARCH APP failed - sorry for the inconvinience (error output was saved to ~/.resh/cli_last_run_out.txt)"
local tmp_file="$__RESH_XDG_CACHE_HOME/cli_last_run_out.txt"
echo "$BUFFER" >| "$tmp_file"
echo "# RESH SEARCH APP failed - sorry for the inconvinience - check '$tmp_file' and '~/.resh/cli.log'"
BUFFER="$PREVBUFFER"
fi
CURSOR=${#BUFFER}

Loading…
Cancel
Save