Browse Source

probe servers for config issues

hmt 3 years ago
parent
commit
c1461b33a4
2 changed files with 28 additions and 6 deletions
  1. 8 5
      README.md
  2. 20 1
      app.ts

+ 8 - 5
README.md

@@ -1,4 +1,5 @@
 # Tinyscale
+
 A very simple load balancer for BigBlueButton running on Deno
 
 All this load balancer does is forward calls to a _real_ BBB-server if a meeting already exists. If you send a _create_ request for a new meeting and the meeting does not exist on any of the known BBB-servers it will cycle through the list of servers that are stored in `servers.json` and pick the next one. There is no advanced number checking of rooms or participants or if your server is actually capable of serving more people. It just tries to create new rooms evenly on all servers.
@@ -23,17 +24,19 @@ Then create a `servers.json` file like this here:
 ```
 
 Now you are ready to start the script with setting a port and a secret:
-    
-    TINYSCALE_SECRET=some_secret_string deno run --allow-net --allow-read --allow-env https://deno.land/x/tinyscale@v1.1.2/mod.ts
+
+    TINYSCALE_SECRET=some_secret_string deno run --allow-net --allow-read --allow-env https://deno.land/x/tinyscale@v1.2.0/mod.ts
 
 tinyscales then runs on port 3005 and you will have to set up your reverse proxy so that it can pick up requests or you leave it on that port. If you prefer a different port you can set one with another env-var: `PORT 3006`
 
-Next you replace your existing BBB settings with the new tinyscale url in your third party apps.
+When started, tinyscale will connect to each server and make a single call to check if your configuration is correct. If there is a problem tinyscale will abort. If your configuration works you can start using it in your environment by replacing your existing BBB settings with the new tinyscale url in your third party apps. Make sure to also replace the BBB secrets with your new `TINYSCALE_SECRET`.
 
 tinyscale has been tested to work with NextCloud and Moodle.
 
 If you want to use recordings they will work but you cannot get a list of all recordings. tinyscale will only respond with the next available server since it is a call to bbb without a `meetingID`. The same goes for the call to get infos on all meetings.
 
 MIT Licensed
-___
-__This project uses BigBlueButton and is not endorsed or certified by BigBlueButton Inc. BigBlueButton and the BigBlueButton Logo are trademarks of BigBlueButton Inc.__
+
+---
+
+**This project uses BigBlueButton and is not endorsed or certified by BigBlueButton Inc. BigBlueButton and the BigBlueButton Logo are trademarks of BigBlueButton Inc.**

+ 20 - 1
app.ts

@@ -1,4 +1,4 @@
-import { createError, opine, ErrorRequestHandler, Router, server } from "./deps.ts";
+import { createError, opine, ErrorRequestHandler, Router, server, createHash } from "./deps.ts";
 import { BBB } from './bbb.ts';
 
 // give your tinyscale server a secret so it looks like a BBB server
@@ -11,6 +11,25 @@ const servers: server[] = JSON.parse(file)
 // create an iterator so that we can treat all servers equally
 let iterator = servers[Symbol.iterator]();
 console.log(servers)
+console.log('Checking servers first …')
+// check servers for connectivity and if the secret is correct
+servers.forEach(async s => {
+  const hash = createHash("sha1");
+  hash.update(`getMeetings${s.secret}`)
+  try {
+    // throw an error if cannot connect or if secret fails
+    const res = await fetch(`${s.host}/bigbluebutton/api/getMeetings?checksum=${hash.toString()}`)
+    if (!res.ok) throw "Connection error. Please check your host configuration"
+    const body = await res.text()
+    const ok = body.includes('SUCCESS')
+    console.log(`${s.host} is ${ok ? 'ok':'misconfigured. Please check your secret in servers.json'}`)
+    if (!ok) throw "Configuration error. Exiting …"
+  } catch (e) {
+    // exit tinyscale if an error is encountered in servers.json
+    console.log(e)
+    Deno.exit(1);
+  }
+})
 
 // pick the next server, using an iterator to cycle through all servers available
 function get_available_server(): server {