Skip to content

Commit

Permalink
Merge pull request #117 from mgit-at/basic-cmdline-db-interface
Browse files Browse the repository at this point in the history
cmdline: add basic cmdline interface to at least look up objects by id
  • Loading branch information
chrisd8088 authored Mar 22, 2024
2 parents a66b730 + 202a367 commit 6125a0c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OID>`

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}
```
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6125a0c

Please sign in to comment.