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

Possibility to autoremove hanging servers from servers list #674

Closed
marcispauls opened this issue Nov 6, 2023 · 12 comments
Closed

Possibility to autoremove hanging servers from servers list #674

marcispauls opened this issue Nov 6, 2023 · 12 comments

Comments

@marcispauls
Copy link

Summary

First thank you for great tool - we cant wait for v2 and api support + some postgresql or mysql support on aws or any non s3 backend.

We are currently registering servers on container launch using nondocumented api.
All cool, but as its containerized happens that containers cycle etc and there would be awesome feature if we could:

  1. autoremove such servers based on ttl
    or
  2. have an api to list all servers and then we could use the api to remove server
@mikeTWC1984
Copy link

Speaking of mysql/postgres/custom engines, you can try those
https://github.com/cronicle-edge/cronicle-edge/tree/main/engines
Need to install knex orm package first, and then SQL driver of your choice.

@marcispauls
Copy link
Author

any way to do this? some surgery in db files etc?

@jhuckaby
Copy link
Owner

I have just pushed out Cronicle v0.9.39 which adds /api/app/get_servers. This will return all the current servers in the cluster.

You can remove servers with /api/app/remove_server. Pass in the hostname of the server you want to remove as param name hostname.

Both of these APIs are undocumented, and require admin-level API tokens to use.

I'm assuming since you are already registering servers on container launch, you figured out how to get admin-level API keys 😊

@marcispauls
Copy link
Author

marcispauls commented Nov 16, 2023 via email

@mikeTWC1984
Copy link

@jhuckaby does cornicle v1 support admin-level API keys?

@jhuckaby
Copy link
Owner

@mikeTWC1984 Not officially, but I've had a few people ask so I described how to do it in a discussion thread. You have to hack the DB a wee bit, but it works:

The process is described here: #479

At some point I'll just go ahead and add it to the UI, but I haven't had the time to really test it thoroughly.

(Orchestra supports this fully of course, and it's in the UI.)

@marcispauls
Copy link
Author

marcispauls commented Nov 23, 2023

@jhuckaby any way to get the status for the server as well in the call? I mean if its alive or not?
Also stupid question - can you share link to the Orchestra? :)

@jhuckaby
Copy link
Owner

@marcispauls If a server is offline it will have a disabled property set to true. Otherwise you can assume it's online.

Orchestra doesn't have a link yet, sorry. It's still unreleased. But coming soon!

@marcispauls
Copy link
Author

In /api/app/get_servers i cant see that info sadly :/

@jhuckaby
Copy link
Owner

It works fine for me.

http://mini.local:3012/api/app/get_servers?api_key=da323d6cb9c29a37a59bf95d1726920b&pretty=1
{
	"code": 0,
	"servers": {
		"mini.local": {
			"hostname": "mini.local",
			"ip": "192.168.3.46",
			"master": 1,
			"uptime": 95,
			"data": {
				"cpu": 5.7,
				"mem": 57663488
			},
			"disabled": 0
		},
		"joework.local": {
			"hostname": "joework.local",
			"ip": "192.168.3.40",
			"master": 0,
			"uptime": 0,
			"data": {},
			"disabled": true
		}
	}
}

Notice the "disabled": true on the joework.local server.

Please note that it takes up to a minute to "realize" that a server has gone offline.

@marcispauls
Copy link
Author

ehh, full moon :D works as you described. there was issue between chair and monitor

@marcispauls
Copy link
Author

marcispauls commented Nov 23, 2023

At the end i ended by creating job in cronicle itself:

#!/bin/sh

CRONICLE_API_KEY=apikeygoesthere
CRONICLE_HOST=http://127.0.0.1:3012

disabled_servers=$(curl -s "$CRONICLE_HOST/api/app/get_servers?api_key=$CRONICLE_API_KEY" | jq -r '.servers | with_entries(select(.value.disabled == true)) | keys[]')

if [ -n "$disabled_servers" ]; then
  echo "$disabled_servers" | while IFS= read -r disabled_server; do
    echo "Removing $disabled_server"
    curl -s "$CRONICLE_HOST/api/app/remove_server" -X DELETE -d "api_key=$CRONICLE_API_KEY&hostname=$disabled_server"
  done
fi

Big tnx @jhuckaby and waiting for Orchestra. Let me know if support is needed :)

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

3 participants