Save std{out,err} of last run, add reshctl debug

reshctl debug reads all the last_run files
pull/18/head
Simon Let 6 years ago
parent b8c00b6c73
commit 77d94c9e12
  1. 2
      Makefile
  2. 44
      cmd/control/cmd/debug.go
  3. 2
      cmd/control/cmd/root.go
  4. 16
      scripts/shellrc.sh

@ -90,7 +90,7 @@ install: build submodules/bash-preexec/bash-preexec.sh scripts/shellrc.sh conf/c
grep '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\
echo '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' >> ~/.zshrc
# Restarting resh daemon ...
[ ! -f ~/.resh/resh.pid ] || kill -SIGTERM $$(cat ~/.resh/resh.pid)
-[ ! -f ~/.resh/resh.pid ] || kill -SIGTERM $$(cat ~/.resh/resh.pid)
nohup resh-daemon &>/dev/null & disown
# Final touch
touch ~/.resh_history.json

@ -0,0 +1,44 @@
package cmd
import (
"fmt"
"io/ioutil"
"os/user"
"path/filepath"
"github.com/curusarn/resh/cmd/control/status"
"github.com/spf13/cobra"
)
// completionCmd represents the completion command
var debugCmd = &cobra.Command{
Use: "debug",
Short: "Shows logs and output from last runs of resh",
Long: "Shows logs and output from last runs of resh",
Run: func(cmd *cobra.Command, args []string) {
files := []string{
"daemon_last_run_out.txt",
"collect_last_run_out.txt",
"postcollect_last_run_out.txt",
}
usr, _ := user.Current()
dir := usr.HomeDir
reshdir := filepath.Join(dir, ".resh")
for _, fpath := range files {
fpath := filepath.Join(reshdir, fpath)
debugReadFile(fpath)
}
exitCode = status.Success
},
}
func debugReadFile(path string) {
fmt.Println("============================================================")
fmt.Println(" filepath:", path)
fmt.Println("============================================================")
dat, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println("ERROR while reading file:", err)
}
fmt.Println(string(dat))
}

@ -26,6 +26,8 @@ func Execute() status.Code {
rootCmd.AddCommand(completionCmd)
completionCmd.AddCommand(completionBashCmd)
completionCmd.AddCommand(completionZshCmd)
rootCmd.AddCommand(debugCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
return status.Fail

@ -40,7 +40,7 @@ __resh_run_daemon() {
if [ -n "$ZSH_VERSION" ]; then
setopt LOCAL_OPTIONS NO_NOTIFY NO_MONITOR
fi
nohup resh-daemon &>/dev/null & disown
nohup resh-daemon &>~/.resh/daemon_last_run_out.txt & disown
}
# __resh_session_init() {
@ -219,7 +219,7 @@ __resh_preexec() {
-osReleaseIdLike "$__RESH_OS_RELEASE_ID_LIKE" \
-osReleaseName "$__RESH_OS_RELEASE_NAME" \
-osReleasePrettyName "$__RESH_OS_RELEASE_PRETTY_NAME" \
&>~/.resh/client_last_run_out.txt || echo "resh-collect ERROR: $(head -n 1 ~/.resh/client_last_run_out.txt)"
&>~/.resh/collect_last_run_out.txt || echo "resh-collect ERROR: $(head -n 1 ~/.resh/collect_last_run_out.txt)"
fi
}
@ -233,22 +233,22 @@ __resh_precmd() {
__RESH_GIT_REMOTE_AFTER="$(git remote get-url origin 2>/dev/null)"
__RESH_GIT_REMOTE_EXIT_CODE_AFTER=$?
if [ -n "${__RESH_COLLECT}" ]; then
if [ "$__RESH_VERSION" != "$(resh-collect -version)" ]; then
if [ "$__RESH_VERSION" != "$(resh-postcollect -version)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
if [ "$__RESH_VERSION" != "$(resh-collect -version)" ]; then
if [ "$__RESH_VERSION" != "$(resh-postcollect -version)" ]; then
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh version: $(resh-collect -version); resh version of this terminal session: ${__RESH_VERSION})"
else
echo "RESH INFO: New RESH shellrc script was loaded - if you encounter any issues please restart this terminal session."
fi
elif [ "$__RESH_REVISION" != "$(resh-collect -revision)" ]; then
elif [ "$__RESH_REVISION" != "$(resh-postcollect -revision)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
if [ "$__RESH_REVISION" != "$(resh-collect -revision)" ]; then
if [ "$__RESH_REVISION" != "$(resh-postcollect -revision)" ]; then
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-collect -revision); resh revision of this terminal session: ${__RESH_REVISION})"
fi
fi
if [ "$__RESH_VERSION" = "$(resh-collect -version)" ] && [ "$__RESH_REVISION" = "$(resh-collect -revision)" ]; then
if [ "$__RESH_VERSION" = "$(resh-postcollect -version)" ] && [ "$__RESH_REVISION" = "$(resh-postcollect -revision)" ]; then
resh-postcollect -requireVersion "$__RESH_VERSION" \
-requireRevision "$__RESH_REVISION" \
-cmdLine "$__RESH_CMDLINE" \
@ -262,7 +262,7 @@ __resh_precmd() {
-gitRemoteExitCodeAfter "$__RESH_GIT_REMOTE_EXIT_CODE_AFTER" \
-realtimeAfter "$__RESH_RT_AFTER" \
-timezoneAfter "$__RESH_TZ_AFTER" \
&>~/.resh/client_last_run_out.txt || echo "resh-postcollect ERROR: $(head -n 1 ~/.resh/client_last_run_out.txt)"
&>~/.resh/postcollect_last_run_out.txt || echo "resh-postcollect ERROR: $(head -n 1 ~/.resh/postcollect_last_run_out.txt)"
fi
fi
unset __RESH_COLLECT

Loading…
Cancel
Save