From 98021194b5299ecc519e5e49806b5f9f0f91a886 Mon Sep 17 00:00:00 2001 From: Michael Gebetsroither Date: Tue, 31 Oct 2023 16:24:48 +0100 Subject: [PATCH 1/2] cmdline: add basic cmdline interface to at least look up objects by id --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.go b/main.go index f331046..9eace67 100644 --- a/main.go +++ b/main.go @@ -63,11 +63,30 @@ func wrapHttps(l net.Listener, cert, key string) (net.Listener, error) { return tlsListener, nil } +func maincmd() { + // cmdline interface: cmd oid -> returns object from db or error + metaStore, err := NewMetaStore(Config.MetaDB) + if err != nil { + logger.Fatal(kv{"fn": "maincmd", "err": "Could not open the meta store: " + err.Error()}) + } + + oid := os.Args[2] + meta, err := metaStore.UnsafeGet(&RequestVars{Oid: oid}) + if err != nil { + logger.Fatal(kv{"fn": "maincmd", "err": "Could not find object: " + err.Error()}) + } + fmt.Printf("%+v\n", meta) +} + func main() { if len(os.Args) == 2 && os.Args[1] == "-v" { fmt.Println(version) os.Exit(0) } + if len(os.Args) > 2 && os.Args[1] == "cmd" { + maincmd() + os.Exit(0) + } var listener net.Listener From 202a36773e0bcd5cf50d9effc3366496c1ab66a7 Mon Sep 17 00:00:00 2001 From: Michael Gebetsroither Date: Fri, 22 Mar 2024 17:43:07 +0100 Subject: [PATCH 2/2] add documentation about cmdline OID lookup feature --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 37f02c1..92e1583 100644 --- a/README.md +++ b/README.md @@ -131,3 +131,21 @@ Check the managment page browser: https://localhost:9999/mgmt +## Debugging + +`lfs-test-server` supports a basic cmd to lookup `OID's` via the cmdline to help in debugging, eg. investigating client problems with a particular `OID` and it's properties. +In this mode `lfs-test-server` expects the same configuration as when running in daemon mode, but will just executing the requested cmd and then exit. + +This is especially helpful in server environments where it's not always possible to get to the web interface easily or where it's just too slow because of DB size. + +`lfs-test-server cmd ` + +Outputs the full OID record + +# Example + +``` +% . /etc/default/lfs-instancefoo # to source server config +% ./lfs-test-server cmd 7c9414fe21ad7b45ffb6e72da86f9a9e13dbb2971365ae7bcb8cc7fbbba7419c +&{Oid:7c9414fe21ad7b45ffb6e72da86f9a9e13dbb2971365ae7bcb8cc7fbbba7419c Size:3334144 Existing:false} +```