Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux_json_api.sh no such file or directory with go #515

Open
cyrialize opened this issue Dec 21, 2023 · 1 comment
Open

linux_json_api.sh no such file or directory with go #515

cyrialize opened this issue Dec 21, 2023 · 1 comment

Comments

@cyrialize
Copy link

Hello!

I've been running into issues with the go server, and the other servers when attempting to start linux-dash from my home directory.

For example:

jonny@raspberrypi:~ $ sudo ./linux-dash/app/server/index -listen="0.0.0.0:853" -static="/home/jonny/linux-dash/app/"
Starting http server at: 0.0.0.0:853
Error executing 'current_ram': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'ram_intensive_processes': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'cpu_intensive_processes': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'disk_partitions': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'docker_processes': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'swap': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'load_avg': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
Error executing 'cpu_utilization': fork/exec ./linux_json_api.sh: no such file or directory
	Script output:
^C

I fixed this by restoring the -scripts flag:

package main

import (
    "bytes"
    "flag"
    "fmt"
    "net/http"
    "os"
    "os/exec"
)

var (
    listenAddress = flag.String("listen", "0.0.0.0:80", "Where the server listens for connections. [interface]:port")
    staticPath    = flag.String("static", "../", "Location of static files.")
    scriptPath    = flag.String("scripts", "./linux_json_api.sh", "Location of shell scripts used to gather stats.")
)

func init() {
    flag.Parse()
}

func main() {
    http.Handle("/", http.FileServer(http.Dir(*staticPath)))
    http.HandleFunc("/server/", func(w http.ResponseWriter, r *http.Request) {
        module := r.URL.Query().Get("module")
        if module == "" {
            http.Error(w, "No module specified, or requested module doesn't exist.", 406)
            return
        }

        // Execute the command
        cmd := exec.Command(*scriptPath, module)
        var output bytes.Buffer
        cmd.Stdout = &output
        err := cmd.Run()
        if err != nil {
            fmt.Printf("Error executing '%s': %s\n\tScript output: %s\n", module, err.Error(), output.String())
            http.Error(w, "Unable to execute module.", http.StatusInternalServerError)
            return
        }

        w.Write(output.Bytes())
    })

    fmt.Println("Starting http server at:", *listenAddress)
    err := http.ListenAndServe(*listenAddress, nil)
    if err != nil {
        fmt.Println("Error starting http server:", err)
        os.Exit(1)
    }
}

And here's the result:

jonny@raspberrypi:~ $ sudo ./linux-dash/app/server/index -listen="0.0.0.0:853" -static="/home/jonny/linux-dash/app/" -scripts="/home/jonny/linux-dash/app/server/linux_json_api.sh"
Starting http server at: 0.0.0.0:853

Some questions:

  1. Is there a better way I should be calling linux-dash? I'd like to use the command shown above in cron.
  2. What are the best ways to get this change committed? I have a local branch that I could push. I could also fork the codebase.

Let me know if you have any questions!

Thanks.

@cyrialize
Copy link
Author

cyrialize commented Dec 26, 2023

This command also works as well, for anyone else that comes across this. (This command will also launch it in the background).

cd /home/jonny/linux-dash/app/server && nohup /usr/bin/go run index.go -listen="0.0.0.0:853" -static="/home/jonny/linux-dash/app/" &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant