🌱🏠🧑‍💻 command line greenhouse client application: an interface to the greenhouse daemon https://greenhouse.server.garden/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

94 lines
2.3 KiB

package main
import (
"fmt"
"os"
"strings"
"time"
)
func status(args []string) {
if len(args) > 0 {
fmt.Printf("\nError: unknown extra arguments '%s' provided to the status command\n", strings.Join(args, " "))
displayHelpAndExit("status")
return
}
status, err := getStatus(true)
if err != nil {
fmt.Printf("\nError: %s\n\n", err)
os.Exit(1)
return
}
if status.NeedsAPIToken {
fmt.Print("\nGreenhouse Daemon is not registered to a Greenhouse account yet. Run the following command to register your account:\n\ngreenhouse register GREENHOUSE_API_TOKEN [SERVER_NAME]\n\n")
os.Exit(0)
return
} else {
serviceStatusString := func(status *ChildProcessStatus) string {
if status.CrashLoop {
return " Crashing over and over"
}
suffix := ""
if status.PID != 0 && status.Enabled {
healthCheckResult := "not implemented yet"
// if status.Healthy {
// healthCheckResult = "passing"
// }
uptimeDuration := time.Since(status.Started)
uptimeDurationSeconds := time.Duration((int64(uptimeDuration) / int64(time.Second)) * int64(time.Second))
suffix = fmt.Sprintf(` PID: %d
Up for %s
Health Check: %s`, status.PID, uptimeDurationSeconds, healthCheckResult)
}
return fmt.Sprintf(` Enabled: %t
Running: %t
%s`, status.Enabled, status.PID != 0, suffix)
}
clientStates := []string{}
for tenantIdNodeId, v := range status.TenantInfo.ClientStates {
split := strings.Split(tenantIdNodeId, ".")
clientStates = append(clientStates, fmt.Sprintf(
"%s:\n Current: %s\n Previous: %s",
split[1], v.CurrentState, v.LastState,
))
}
fmt.Printf(`
Greenhouse Daemon:
Server Name: %s
Configured Tunnels: %d
Caddy Server Status:
%s
Threshold Tunnel Client Status:
%s
Greenhouse Account:
Email Address: %s
Allocated Port Range: %d-%d
Authorized Domains:
- %s
Client States:
%s
`,
status.ServerName,
len(status.GUITunnels),
serviceStatusString(status.Caddy),
serviceStatusString(status.Threshold),
status.TenantInfo.EmailAddress,
status.TenantInfo.PortStart, status.TenantInfo.PortEnd,
strings.Join(status.TenantInfo.AuthorizedDomains, "\n - "),
strings.Join(clientStates, "\n "),
)
}
}