hlfw.ca

registry

Download patch

ref: 5ddcb59618def30c1e17a651b29c9722dca82df2
parent: 72be4982e5c3bd89c19e32769b6aa4b129739402
author: halfwit <michaelmisch1985@gmail.com>
date: Wed Oct 18 18:39:55 PDT 2023

Some small changes to get services monitoring ready

--- a/README.md
+++ b/README.md
@@ -39,8 +39,8 @@
 A service can be added by creating a directory. Services may be read by anyone, but can only be modified by the creator or registry owner. Write requests must come from users in the same authdom.
 
 Each service dir contains many of the following files: 
- - addr
- - auth
+ - address
+ - authdom (Still a TODO)
  - status (ok/down)
  - uptime
  - description
@@ -49,25 +49,15 @@
  - It may be beneficial to expose an events file that `services` can do a blocking read on, waiting for a service to be removed/added
  - `auth` is an optional address for the auth server to use
 
-## svc/services 
+## svc/monitor 
 
-Usage: `svc/services [-o] [-f servicesdb] [-s svcfs]`
+Usage: `svc/services [-o]  [-s svcfs]`
 
 - `-o` Alternate naming in services, `ipnet.sysname.svcname`
-- `-f` Read in services from db
 - `-s` Address of svcfs
 
-Services connects to a `svcfs`, by default checking for an entry in your local ipnet=. 
-Without `-f`, it checks for and parses `/cfg/$sysname/registry`. (`-f` and the default directroy are temporary stopgaps before services can be self-publishing)
-
-```
-## /cfg/mysystem/registry
-service=myservice
-    addr=tcp!myserver!19294
-    description='My shared service'
-```
-
-Services will populate your local /srv with an fd pointing to all records in the given `svcfs` as well as any local entries. 
+monitor connects to a `svcfs`, by default checking for an entry in your local ipnet=. 
+monitor will populate your local /srv with an fd pointing to all records in the given `svcfs`. 
 - If the status of a service changes from Ok, it will be automatically removed
 - multiple instances can be run, one per svcfs
 - on exit, all mounted services should be kept alive; so on start it should handle silently failing when an entry already exists
@@ -81,8 +71,14 @@
 
 ```
 $ svc/query speakers
-service=speakers addr=livingroom!12345 description='Living room speakers' uptime=1239021 status=ok
-service=speakers addr=bedroom!1234 description='Bedroom speakers' uptime=123811 status=ok
+service=speakers address=livingroom!12345 
+    description='Living room speakers'
+    uptime='4 days, 3 hour, 0 minutes'
+    status=ok
+service=speakers address=bedroom!1234
+    description='Bedroom speakers'  
+    uptime='55 days, 0 hours, 2 minutes'
+    status=ok
 ```
 
 ## svc/publish 
@@ -99,3 +95,4 @@
 
 ## Future
 - Integration into `cpurc`
+- Allow setting an Authdom for a services
--- /dev/null
+++ b/monitor
@@ -1,0 +1,51 @@
+#!/bin/rc
+
+$argv0 = $0
+
+fn usage {
+    echo 'Usage: '$argv0' [-o] [-s svcfs]' >[1=2]
+    exits 'usage'
+}
+
+svcfs=()
+order=1
+while(~ $1 -*){
+	switch($1){
+	case -o; order=2
+	case *
+		~ $#* 1 && usage
+		switch($1){
+		case -s; svcfs=(-s $2)
+		case *; usage
+		}
+		shift
+	}
+	shift
+}
+
+! ~ $#* 0 && usage
+
+# TODO: Authdom goes in first line of tuple, consider that as well
+fn update {
+	for(f in `{svc/query $svcfs . status ok grep service}){
+		name=`{echo f | sed 's/.*service=//;s/ address=.*//'}
+		address=`{echo f | sed 's/.*address=tcp!//;s/ .*//'}
+		entry=$name^'/'^$address
+		~ $order 2 && entry=$address^'.'^$name
+		test -f '/srv/'^$entry || srv $address $entry
+	}
+	for(f in `{svc/query $svcfs . status down | grep services}){
+		name=`{echo f | sed 's/.*service=//;s/ address=.*//'}
+		address=`{echo f | sed 's/.*address=tcp!//;s/ .*//'}
+		entry='/srv/'^$name^'.'^$address
+		~ $order 2 && entry='/srv/'^$address^'.'^$name
+		test -f $entry && rm $entry
+	}
+}
+
+fn watch {
+	while(1){
+		update
+		sleep 30 # Not the best way to watch for a service coming up. At worst it can take a full minute
+	}
+}
--- a/services
+++ /dev/null
@@ -1,57 +1,0 @@
-#!/bin/rc
-
-$argv0 = $0
-
-fn usage {
-    echo 'Usage:' $argv0 '[-o] [-f servicesdb] [-s svcfs]' >[1=2]
-    exits 'usage'
-}
-
-dbfile=()
-svcfs=()
-order=1
-while(~ $1 -*){
-	switch($1){
-	case -o; order=2
-	case *
-		~ $#* 1 && usage
-		switch($1){
-		case -f; dbfile=$2
-		case -s; svcfs=$2
-		case *; usage
-		}
-		shift
-	}
-	shift
-}
-
-! ~ $#* 0 && usage
-
-if(~ $svcfs "")
-	svcfs=`{ndb/ipquery sys $sysname registry | sed 's/registry=//'}
-if(~ $svcfs ""){
-	echo 'Unable to find Registry'
-	exits 'registry'
-}
-# Ours, we check later for the one associated with svcfs
-# With -s, parse the addr ipnet if exists and use that instead
-ipnet=`{ndb/ipquery sys $sysname ipnet | sed 's/ipnet=//'}
-
-fn mount {
-	# Mount up svcfs in our namespace
-	srv -c -m $svcfs^'!16675' services /mnt/services
-
-}
-
-fn publish {
-	# Try /cfg/sysname/services if not set
-	# Initial read + post everything
-	#  - if we posted the service, service.local
-}
-
-fn serve {
-
-}
-
-# Walk the dir, parse addr file + build /srv/service.sysname.ipnet
-# With -o, /srv/ipnet.sysname.service