201 lines
5.8 KiB
Markdown
201 lines
5.8 KiB
Markdown
# Syndicate utils
|
|
|
|
## Syndesizer
|
|
|
|
A Syndicate multitool. Includes a number of different actors that become active via configuration.
|
|
Whether you use a single instance for many protocols or many specialized instances is up to you.
|
|
|
|
### JSON Socket Translator
|
|
|
|
Communicate with sockets that send and receive lines of JSON using `<send …>` and `<recv …>` messages.
|
|
|
|
Do not send messages into the dataspace configure with `<json-socket-translator …>` until `<connected @socketPath string>` is asserted.
|
|
|
|
```
|
|
# MPV configuration example
|
|
<require-service <daemon mpv-server>>
|
|
|
|
<daemon mpv-server {
|
|
argv: [
|
|
"/run/current-system/sw/bin/mpv"
|
|
"--really-quiet"
|
|
"--idle=yes"
|
|
"--no-audio-display"
|
|
"--input-ipc-server=/run/user/1000/mpv.sock"
|
|
"--volume=75"
|
|
]
|
|
protocol: none
|
|
}>
|
|
|
|
let ?mpvSpace = dataspace
|
|
|
|
? <service-state <daemon mpv-server> ready> [
|
|
<require-service <daemon syndesizer>>
|
|
? <service-object <daemon syndesizer> ?cap> [
|
|
$cap <json-socket-translator {
|
|
dataspace: $mpvSpace
|
|
socket: "/run/user/1000/mpv.sock"
|
|
}>
|
|
]
|
|
]
|
|
|
|
$mpvSpace [
|
|
|
|
# announce the dataspace when the translator is connected
|
|
? <connected $socketPath> [
|
|
$config <mpv $mpvSpace>
|
|
$config <bind <ref { oid: "mpv" key: #x"" }> $mpvSpace #f>
|
|
]
|
|
|
|
# translate <play-file …> to an MPV command
|
|
?? <play-file ?file> [
|
|
! <send { "command": ["loadfile" $file "append-play"] }>
|
|
]
|
|
|
|
# clear the playlist on idle so it doesn't grow indefinitely
|
|
?? <recv {"event": "idle"}> [
|
|
! <send { "command": ["playlist-clear"] }>
|
|
]
|
|
]
|
|
```
|
|
|
|
### Webooks
|
|
|
|
Listens for webhook requests and sends request data to a dataspace as messages.
|
|
Request data is formated according to the http schema [defined in syndicate-protocols](https://git.syndicate-lang.org/syndicate-lang/syndicate-protocols/src/branch/main/schemas/http.prs), with the exception that messages bodies may be **bytes**, **string**, or **any** for the `content-type`s of `application/octet-stream`, `text/*`, and `application/json` respectively.
|
|
|
|
```
|
|
# Configuration example
|
|
<require-service <daemon syndesizer>>
|
|
? <service-object <daemon syndesizer> ?cap> [
|
|
$cap <webhooks {
|
|
listen: <tcp "0.0.0.0" 1048>
|
|
endpoints: {
|
|
|
|
# http://0.0.0.0:1048/my-endpoint
|
|
["my-endpoint"]: $target-dataspace
|
|
|
|
# http://0.0.0.0:1048/some/multi-element/path
|
|
["some", "multi-element", "path"]: $target-dataspace
|
|
|
|
}
|
|
}>
|
|
]
|
|
```
|
|
|
|
## cache_actor
|
|
|
|
An actor that observes patterns and reässerts the values they capture for a given lifetime. Takes the arguments `{ dataspace: #!any lifetime: double }`. The lifetime of a cache counts down from moment a value is asserted.
|
|
|
|
Example configuration:
|
|
```
|
|
? <nixspace ?nixspace> [
|
|
; Require the nix_actor during observations.
|
|
?nixspace> ? <Observe <rec eval _> _> [
|
|
$config <require-service <daemon nix_actor>> ]
|
|
?nixspace> ? <Observe <rec realise _> _> [
|
|
$config <require-service <daemon nix_actor>> ]
|
|
|
|
; Cache anything captured by observers in the $nixspace for an hour.
|
|
; The nix_actor is not required during caching.
|
|
$config ? <service-object <daemon cache_actor> ?cap> [
|
|
$cap { dataspace: $nixspace lifetime: 3600.0 } ]
|
|
]
|
|
```
|
|
|
|
## json_translator
|
|
|
|
Wrapper that executes a command, parses its JSON output, converts to Preserves record `<recv @jsonData any>`, and publishes and messages to its initial dataspace.
|
|
|
|
## mintsturdyref
|
|
|
|
A utility for minting [Sturdyrefs](https://synit.org/book/operation/builtin/gatekeeper.html#sturdyrefs).
|
|
|
|
## mount_actor
|
|
|
|
Actor for mounting filesystems on Linux.
|
|
|
|
Sample Syndicate server script:
|
|
```
|
|
# Assert a file-system we want to mount.
|
|
<mount "/dev/sda3" "/boot" "vfat">
|
|
|
|
# Transform mount assertions into mount status observations.
|
|
? <mount ?source ?target ?fs> [
|
|
? <mount $source $target $fs _> [ ]
|
|
]
|
|
|
|
# Assert mounting succeded.
|
|
? <mount _ ?target _ #t> [
|
|
<service-state <mountpoint $target> ready>
|
|
]
|
|
# Assert mount failed.
|
|
? <mount _ ?target _ <failure _>> [
|
|
<service-state <mountpoint $target> failed>
|
|
]
|
|
|
|
# Assert the details into the machine dataspace.
|
|
? <machine-dataspace ?machine> [
|
|
$config ? <mount ?source ?target ?fs ?status> [
|
|
$machine <mount $source $target $fs $status>
|
|
]
|
|
]
|
|
|
|
# Require the mount_actor daemon.
|
|
<require-service <daemon mount_actor>>
|
|
<daemon mount_actor {
|
|
argv: ["/home/emery/src/bin/mount_actor"]
|
|
protocol: application/syndicate
|
|
}>
|
|
|
|
# Pass the daemon the config dataspace.
|
|
? <service-object <daemon mount_actor> ?cap> [
|
|
$cap { dataspace: $config }
|
|
]
|
|
```
|
|
|
|
## msg
|
|
|
|
A utility that sends messages to `$SYNDICATE_ROUTE`.
|
|
|
|
|
|
## net_mapper
|
|
|
|
Publishes ICMP packet round-trip-times. See [net_mapper.prs](./net_mapper.prs) for a protocol description. [Source](./src/net_mapper.nim).
|
|
|
|
Example script:
|
|
```
|
|
? <machine-dataspace ?machine> [
|
|
$machine ? <rtt "10.0.33.136" ?min ?avg ?max> [
|
|
$log ! <log "-" { ping: { min: $min avg: $avg max: $max } }>
|
|
]
|
|
|
|
$config [
|
|
<require-service <daemon net_mapper>>
|
|
<daemon net_mapper {
|
|
argv: ["/bin/net_mapper"]
|
|
protocol: application/syndicate
|
|
}>
|
|
? <service-object <daemon net_mapper> ?cap> [
|
|
$cap { dataspace: $machine }
|
|
]
|
|
]
|
|
]
|
|
```
|
|
|
|
## preserve_process_environment
|
|
|
|
This utility serializes it's process environment to Preserves and prints it to stdout.
|
|
It can be used to feed the environment variables of a nested child of the Syndicate server back to the server. For example, to retreive the environmental variables that a desktop manager passed on to its children.
|
|
|
|
|
|
## syndump
|
|
|
|
Utility for printing assertions and messages. Parses the command-line arguments as a pattern, connects a dataspace via `$SYNDICATE_ROUTE`, and writes observations to standard-output. Published assertions are prefixed by the `+` character, retractions by `-`, and messages by `!`.
|
|
|
|
Example
|
|
```sh
|
|
# Print patterns in use, filter down with AWK to only the published patterns.
|
|
$ FS=':' syndump '<Observe ? _>' | awk -F : '/^+/ { print $2 }'
|
|
```
|